Merge pull request #8 from kemitix/release/0.3.0

Release 0.3.0
This commit is contained in:
Paul Campbell 2017-08-26 23:24:58 +01:00 committed by GitHub
commit bab96c5621
20 changed files with 931 additions and 323 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule ".travis-support"]
path = .travis-support
url = https://github.com/kemitix/kemitix-travis-support.git

BIN
.mvn/wrapper/maven-wrapper.jar vendored Normal file

Binary file not shown.

1
.mvn/wrapper/maven-wrapper.properties vendored Normal file
View file

@ -0,0 +1 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip

1
.travis-support Submodule

@ -0,0 +1 @@
Subproject commit b8593e541ba9a11447fa9559a83e5f99097ca4d2

View file

@ -1,5 +1,18 @@
language: java language: java
jdk: jdk:
- oraclejdk8 - oraclejdk8
cache:
directories:
- "$HOME/.m2"
install: true
script: "./mvnw clean install"
after_success: after_success:
- mvn clean test jacoco:report coveralls:report - sh .travis-support/coveralls.sh
- bash <(curl -s https://codecov.io/bash)
deploy:
provider: script
script: sh .travis-support/deploy.sh
on:
branch: master
env:
global:

28
CHANGELOG Normal file
View file

@ -0,0 +1,28 @@
CHANGELOG
=========
0.3.0
-----
* Add `<T> Value.where(boolean, Supplier<T>, Supplier<T>)`
* Add `Optional<T> Value.where(boolean, Supplier<T>)`
* Add `.travis-support`
* Avoid danger of JVM-level deadlock during `Value` initialisation
* Avoid danger of JVM-level deadlock during `Condition` initialisation
* Upgrade `kemitix-parent` to 3.2.0
* Upgrade `kemitix-checkstyle-parent` to 3.2.0
* Upgrade `assertj` to 3.8.0
* Set `jacoco` to 100% line and instruction coverage required
* Set `pitest` to 100% mutation and coverage required
* Use `lombok.val` in `ValueTest`
* Move `assertThat` calls to individual test methods in `ValueTest`
0.2.0
-----
* Added `Value`
0.1.0
-----
* Initial release

View file

@ -1,11 +1,12 @@
# Conditional # Conditional
image:https://img.shields.io/github/release/kemitix/conditional.svg["Releases", link="https://github.com/kemitix/conditional/releases"]
image:https://api.codacy.com/project/badge/Grade/1188742d676e457da91415d2b3a5faf1["Codacy code quality", link="https://www.codacy.com/app/kemitix/conditional"]
image:https://travis-ci.org/kemitix/conditional.svg?branch=master["Build Status", link="https://travis-ci.org/kemitix/conditional"] image:https://travis-ci.org/kemitix/conditional.svg?branch=master["Build Status", link="https://travis-ci.org/kemitix/conditional"]
image:https://coveralls.io/repos/github/kemitix/conditional/badge.svg?branch=master["Coverage Status", link="https://coveralls.io/github/kemitix/conditional?branch=master"]
image::https://coveralls.io/repos/github/kemitix/conditional/badge.svg?branch=master["Coverage Status", link="https://coveralls.io/github/kemitix/conditional?branch=master"] * link:#condition[Condition]
* link:#value[Value]
* link:#_condition[Condition]
* link:#_value[Value]
## Condition ## Condition
@ -200,6 +201,16 @@ if (isTrue()) {
String result = isTrue() ? TRUE : FALSE; String result = isTrue() ? TRUE : FALSE;
---- ----
[[source,java]]
----
final String result = Value.where(isTrue(), () -> TRUE, () -> FALSE);
----
[[source,java]]
----
final Optional<String> result = Value.where(isTrue(), () -> TRUE);
----
[[source,java]] [[source,java]]
---- ----
final String result = Value.<String>where(isTrue()).then(() -> TRUE) final String result = Value.<String>where(isTrue()).then(() -> TRUE)

3
circle.yml Normal file
View file

@ -0,0 +1,3 @@
test:
override:
- ./mvnw clean install

236
mvnw vendored Executable file
View file

@ -0,0 +1,236 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
#
# Look for the Apple JDKs first to preserve the existing behaviour, and then look
# for the new JDKs provided by Oracle.
#
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then
#
# Apple JDKs
#
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then
#
# Oracle JDKs
#
export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home
fi
if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then
#
# Apple JDKs
#
export JAVA_HOME=`/usr/libexec/java_home`
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Migwn, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
local basedir=$(pwd)
local wdir=$(pwd)
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
wdir=$(cd "$wdir/.."; pwd)
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)}
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
# avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in $@
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

146
mvnw.cmd vendored Normal file
View file

@ -0,0 +1,146 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
set MAVEN_CMD_LINE_ARGS=%MAVEN_CONFIG% %*
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR=""%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar""
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
# avoid using MAVEN_CMD_LINE_ARGS below since that would loose parameter escaping in %*
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%

26
pom.xml
View file

@ -4,21 +4,26 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<properties> <properties>
<kemitix-checkstyle-ruleset.version>2.3.0</kemitix-checkstyle-ruleset.version> <kemitix-checkstyle-ruleset.version>3.2.0</kemitix-checkstyle-ruleset.version>
<kemitix-checkstyle-ruleset.level>5-complexity</kemitix-checkstyle-ruleset.level> <kemitix-checkstyle-ruleset.level>5-complexity</kemitix-checkstyle-ruleset.level>
<jacoco-class-line-covered-ratio>1</jacoco-class-line-covered-ratio>
<jacoco-class-instruction-covered-ratio>1</jacoco-class-instruction-covered-ratio>
<jacoco-class-missed-count-maximum>0</jacoco-class-missed-count-maximum>
<pitest.coverage>100</pitest.coverage>
<pitest.mutation>100</pitest.mutation>
<junit.version>4.12</junit.version> <junit.version>4.12</junit.version>
<assertj.version>3.6.2</assertj.version> <assertj.version>3.8.0</assertj.version>
<coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version> <coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
</properties> </properties>
<parent> <parent>
<groupId>net.kemitix</groupId> <groupId>net.kemitix</groupId>
<artifactId>kemitix-parent</artifactId> <artifactId>kemitix-parent</artifactId>
<version>2.7.0</version> <version>3.2.0</version>
<relativePath/> <relativePath/>
</parent> </parent>
<artifactId>conditional</artifactId> <artifactId>conditional</artifactId>
<version>0.2.0</version> <version>0.3.0</version>
<dependencies> <dependencies>
<dependency> <dependency>
@ -41,11 +46,14 @@
<groupId>net.kemitix</groupId> <groupId>net.kemitix</groupId>
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId> <artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
<version>${kemitix-checkstyle-ruleset.version}</version> <version>${kemitix-checkstyle-ruleset.version}</version>
<configuration>
<level>${kemitix-checkstyle-ruleset.level}</level>
</configuration>
<executions> <executions>
<execution> <execution>
<phase>validate</phase> <phase>validate</phase>
<goals> <goals>
<goal>${kemitix-checkstyle-ruleset.level}</goal> <goal>check</goal>
</goals> </goals>
</execution> </execution>
</executions> </executions>
@ -57,12 +65,4 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<pluginRepositories>
<pluginRepository>
<id>sevntu-maven</id>
<name>sevntu-maven</name>
<url>http://sevntu-checkstyle.github.io/sevntu.checkstyle/maven2</url>
</pluginRepository>
</pluginRepositories>
</project> </project>

View file

@ -21,12 +21,6 @@
package net.kemitix.conditional; package net.kemitix.conditional;
import java.util.AbstractMap.SimpleEntry;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* If-then-else in a functional-style. * If-then-else in a functional-style.
* *
@ -34,14 +28,6 @@ import java.util.stream.Stream;
*/ */
public interface Condition { public interface Condition {
Condition TRUE = new TrueCondition();
Condition FALSE = new FalseCondition();
Map<Boolean, Condition> CONDITIONS = Collections.unmodifiableMap(
Stream.of(new SimpleEntry<>(true, TRUE), new SimpleEntry<>(false, FALSE))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
/** /**
* Create a new {@code Condition} for the clause. * Create a new {@code Condition} for the clause.
* *
@ -49,8 +35,9 @@ public interface Condition {
* *
* @return the Condition * @return the Condition
*/ */
@SuppressWarnings("avoidinlineconditionals")
static Condition where(final boolean clause) { static Condition where(final boolean clause) {
return CONDITIONS.get(clause); return clause ? TrueCondition.TRUE : FalseCondition.FALSE;
} }
/** /**
@ -131,58 +118,4 @@ public interface Condition {
return where(clause); return where(clause);
} }
/**
* A {@code Condition} that has evaluated to {@code true}.
*/
class TrueCondition implements Condition {
@Override
public Condition and(final boolean clause) {
return where(clause);
}
@Override
public Condition or(final boolean secondClause) {
return TRUE;
}
@Override
public Condition then(final Runnable response) {
response.run();
return TRUE;
}
@Override
public void otherwise(final Runnable response) {
}
}
/**
* A {@code Condition} that has evaluated to {@code false}.
*/
class FalseCondition implements Condition {
@Override
public Condition and(final boolean clause) {
return FALSE;
}
@Override
public Condition or(final boolean secondClause) {
return where(secondClause);
}
@Override
public Condition then(final Runnable response) {
return FALSE;
}
@Override
public void otherwise(final Runnable response) {
response.run();
}
}
} }

View file

@ -0,0 +1,53 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Paul Campbell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.kemitix.conditional;
/**
* A {@code Condition} that has evaluated to {@code false}.
*
* @author Paul Campbell (pcampbell@kemitix.net).
*/
final class FalseCondition implements Condition {
protected static final Condition FALSE = new net.kemitix.conditional.FalseCondition();
@Override
public Condition and(final boolean clause) {
return FALSE;
}
@Override
public Condition or(final boolean secondClause) {
return Condition.where(secondClause);
}
@Override
public Condition then(final Runnable response) {
return FALSE;
}
@Override
public void otherwise(final Runnable response) {
response.run();
}
}

View file

@ -0,0 +1,64 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Paul Campbell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.kemitix.conditional;
import java.util.function.Supplier;
/**
* An intermediate state where the clause has evaluated to false.
*
* @param <T> the type of the value
*
* @author Paul Campbell (pcampbell@kemitix.net).
*/
class FalseValueClause<T> implements Value.ValueClause<T> {
protected static final Value.ValueClause FALSE = new FalseValueClause();
@Override
public ValueSupplier<T> then(final Supplier<T> trueSupplier) {
return new FalseValueSupplier();
}
@Override
public Value.ValueClause<T> and(final boolean clause) {
return this;
}
@Override
public Value.ValueClause<T> or(final boolean clause) {
return Value.where(clause);
}
/**
* An intermediate result of the {@link Value} where the clause has evaluated to false.
*/
private class FalseValueSupplier implements ValueSupplier<T> {
@Override
public T otherwise(final Supplier<T> falseSupplier) {
return falseSupplier.get();
}
}
}

View file

@ -0,0 +1,54 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Paul Campbell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.kemitix.conditional;
/**
* A {@code Condition} that has evaluated to {@code true}.
*
* @author Paul Campbell (pcampbell@kemitix.net).
*/
final class TrueCondition implements Condition {
protected static final Condition TRUE = new net.kemitix.conditional.TrueCondition();
@Override
public Condition and(final boolean clause) {
return Condition.where(clause);
}
@Override
public Condition or(final boolean secondClause) {
return TRUE;
}
@Override
public Condition then(final Runnable response) {
response.run();
return TRUE;
}
@Override
public void otherwise(final Runnable response) {
// do nothing
}
}

View file

@ -0,0 +1,69 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Paul Campbell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.kemitix.conditional;
import lombok.RequiredArgsConstructor;
import java.util.function.Supplier;
/**
* An intermediate state where the clause has evaluated to true.
*
* @param <T> the type of the value
*
* @author Paul Campbell (pcampbell@kemitix.net).
*/
class TrueValueClause<T> implements Value.ValueClause<T> {
protected static final Value.ValueClause TRUE = new TrueValueClause();
@Override
public ValueSupplier<T> then(final Supplier<T> trueSupplier) {
return new TrueValueSupplier(trueSupplier);
}
@Override
public Value.ValueClause<T> and(final boolean clause) {
return Value.where(clause);
}
@Override
public Value.ValueClause<T> or(final boolean clause) {
return this;
}
/**
* An intermediate result of the {@link Value} where the clause has evaluated to true.
*/
@RequiredArgsConstructor
private class TrueValueSupplier implements ValueSupplier<T> {
private final Supplier<T> valueSupplier;
@Override
public T otherwise(final Supplier<T> falseSupplier) {
return valueSupplier.get();
}
}
}

View file

@ -21,6 +21,7 @@
package net.kemitix.conditional; package net.kemitix.conditional;
import java.util.Optional;
import java.util.function.Supplier; import java.util.function.Supplier;
/** /**
@ -30,6 +31,41 @@ import java.util.function.Supplier;
*/ */
public interface Value { public interface Value {
/**
* Return one of two values depending on the value of a clause.
*
* @param clause The deciding clause
* @param trueSupplier The supplier to provide the value when the clause is true
* @param falseSupplier The supplier to provide the value when the clause is false
* @param <T> The type of the value
*
* @return the value from either the trueSupplier or the falseSupplier
*/
static <T> T where(
boolean clause,
Supplier<T> trueSupplier,
Supplier<T> falseSupplier
) {
return Value.<T>where(clause).then(trueSupplier)
.otherwise(falseSupplier);
}
/**
* Return an Optional either containing a value, if the clause is true, or empty.
*
* @param clause The deciding clause
* @param trueSupplier The supplier to provide the value when the clause is true
* @param <T> The type of the value
*
* @return an Optional either containing the value from the trueSupplier or empty
*/
static <T> Optional<T> where(
boolean clause,
Supplier<T> trueSupplier
) {
return Optional.ofNullable(Value.where(clause, trueSupplier, () -> null));
}
/** /**
* Create a new {@link ValueClause} for the clause. * Create a new {@link ValueClause} for the clause.
* *
@ -38,11 +74,9 @@ public interface Value {
* *
* @return a true or false value clause * @return a true or false value clause
*/ */
@SuppressWarnings({"unchecked", "avoidinlineconditionals"})
static <T> ValueClause<T> where(final boolean clause) { static <T> ValueClause<T> where(final boolean clause) {
if (clause) { return (ValueClause<T>) (clause ? TrueValueClause.TRUE : FalseValueClause.FALSE);
return new TrueValueClause<>();
}
return new FalseValueClause<>();
} }
/** /**
@ -133,82 +167,4 @@ public interface Value {
} }
/**
* An intermediate state where the clause has evaluated to true.
*
* @param <T> the type of the value
*/
class TrueValueClause<T> implements ValueClause<T> {
@Override
public ValueSupplier<T> then(final Supplier<T> trueSupplier) {
return new TrueValueSupplier(trueSupplier);
}
@Override
public ValueClause<T> and(final boolean clause) {
return Value.where(clause);
}
@Override
public ValueClause<T> or(final boolean clause) {
return this;
}
/**
* An intermediate result of the {@link Value} where the clause has evaluated to true.
*/
private class TrueValueSupplier implements ValueSupplier<T> {
private final Supplier<T> valueSupplier;
TrueValueSupplier(final Supplier<T> valueSupplier) {
this.valueSupplier = valueSupplier;
}
@Override
public T otherwise(final Supplier<T> falseSupplier) {
return valueSupplier.get();
}
}
}
/**
* An intermediate state where the clause has evaluated to false.
*
* @param <T> the type of the value
*/
class FalseValueClause<T> implements ValueClause<T> {
@Override
public ValueSupplier<T> then(final Supplier<T> trueSupplier) {
return new FalseValueSupplier();
}
@Override
public ValueClause<T> and(final boolean clause) {
return this;
}
@Override
public ValueClause<T> or(final boolean clause) {
return Value.where(clause);
}
/**
* An intermediate result of the {@link Value} where the clause has evaluated to false.
*/
private class FalseValueSupplier implements ValueSupplier<T> {
@Override
public T otherwise(final Supplier<T> falseSupplier) {
return falseSupplier.get();
}
}
}
} }

View file

@ -29,7 +29,7 @@ public class ConditionalTest {
//when //when
when(true); when(true);
//then //then
thenTheThenResponseRuns(); assertThatTheThenResponseRuns();
} }
@Test @Test
@ -37,7 +37,7 @@ public class ConditionalTest {
//when //when
when(false); when(false);
//then //then
thenTheOtherwiseResponseRuns(); assertThatTheOtherwiseResponseRuns();
} }
@Test @Test
@ -45,7 +45,7 @@ public class ConditionalTest {
//when //when
when(true, true); when(true, true);
//then //then
thenTheThenResponseRuns(); assertThatTheThenResponseRuns();
} }
@Test @Test
@ -53,7 +53,7 @@ public class ConditionalTest {
//when //when
when(true, false); when(true, false);
//then //then
thenTheOtherwiseResponseRuns(); assertThatTheOtherwiseResponseRuns();
} }
@Test @Test
@ -61,7 +61,7 @@ public class ConditionalTest {
//when //when
when(false, true); when(false, true);
//then //then
thenTheOtherwiseResponseRuns(); assertThatTheOtherwiseResponseRuns();
} }
@Test @Test
@ -69,7 +69,7 @@ public class ConditionalTest {
//when //when
when(false, false); when(false, false);
//then //then
thenTheOtherwiseResponseRuns(); assertThatTheOtherwiseResponseRuns();
} }
@Test @Test
@ -80,7 +80,7 @@ public class ConditionalTest {
.and(true) .and(true)
.then(otherwiseResponse); .then(otherwiseResponse);
//then //then
thenBothResponsesRun(); assertThatBothResponsesRun();
} }
@Test @Test
@ -88,7 +88,7 @@ public class ConditionalTest {
//when //when
whenOr(true, true); whenOr(true, true);
//then //then
thenTheThenResponseRuns(); assertThatTheThenResponseRuns();
} }
@Test @Test
@ -96,7 +96,7 @@ public class ConditionalTest {
//when //when
whenOr(true, false); whenOr(true, false);
//then //then
thenTheThenResponseRuns(); assertThatTheThenResponseRuns();
} }
@Test @Test
@ -104,7 +104,7 @@ public class ConditionalTest {
//when //when
whenOr(false, true); whenOr(false, true);
//then //then
thenTheThenResponseRuns(); assertThatTheThenResponseRuns();
} }
@Test @Test
@ -112,7 +112,7 @@ public class ConditionalTest {
//when //when
whenOr(false, false); whenOr(false, false);
//then //then
thenTheOtherwiseResponseRuns(); assertThatTheOtherwiseResponseRuns();
} }
@Test @Test
@ -121,7 +121,7 @@ public class ConditionalTest {
Condition.whereNot(false) Condition.whereNot(false)
.then(thenResponse); .then(thenResponse);
//then //then
thenTheThenResponseRuns(); assertThatTheThenResponseRuns();
} }
@Test @Test
@ -131,7 +131,7 @@ public class ConditionalTest {
.then(thenResponse) .then(thenResponse)
.otherwise(otherwiseResponse); .otherwise(otherwiseResponse);
//then //then
thenTheOtherwiseResponseRuns(); assertThatTheOtherwiseResponseRuns();
} }
@Test @Test
@ -141,7 +141,7 @@ public class ConditionalTest {
.andNot(false) .andNot(false)
.then(thenResponse); .then(thenResponse);
//then //then
thenTheThenResponseRuns(); assertThatTheThenResponseRuns();
} }
@Test @Test
@ -152,7 +152,7 @@ public class ConditionalTest {
.then(thenResponse) .then(thenResponse)
.otherwise(otherwiseResponse); .otherwise(otherwiseResponse);
//then //then
thenTheOtherwiseResponseRuns(); assertThatTheOtherwiseResponseRuns();
} }
@Test @Test
@ -162,7 +162,7 @@ public class ConditionalTest {
.orNot(false) .orNot(false)
.then(thenResponse); .then(thenResponse);
//then //then
thenTheThenResponseRuns(); assertThatTheThenResponseRuns();
} }
@Test @Test
@ -173,7 +173,7 @@ public class ConditionalTest {
.then(thenResponse) .then(thenResponse)
.otherwise(otherwiseResponse); .otherwise(otherwiseResponse);
//then //then
thenTheOtherwiseResponseRuns(); assertThatTheOtherwiseResponseRuns();
} }
@Test @Test
@ -184,7 +184,7 @@ public class ConditionalTest {
.otherwise(true) .otherwise(true)
.then(otherwiseResponse); .then(otherwiseResponse);
//then //then
thenTheOtherwiseResponseRuns(); assertThatTheOtherwiseResponseRuns();
} }
@Test @Test
@ -195,7 +195,7 @@ public class ConditionalTest {
.otherwise(false) .otherwise(false)
.then(otherwiseResponse); .then(otherwiseResponse);
//then //then
thenNoResponseRuns(); assertThatNoResponseRuns();
} }
@Test @Test
@ -205,7 +205,7 @@ public class ConditionalTest {
.then(thenResponse) .then(thenResponse)
.then(otherwiseResponse); .then(otherwiseResponse);
//then //then
thenBothResponsesRun(); assertThatBothResponsesRun();
} }
@Test @Test
@ -215,14 +215,47 @@ public class ConditionalTest {
.then(thenResponse) .then(thenResponse)
.then(otherwiseResponse); .then(otherwiseResponse);
//then //then
thenNoResponseRuns(); assertThatNoResponseRuns();
} }
private void whenOr(final boolean firstClause, final boolean secondClause) { private void assertThatBothResponsesRun() {
Condition.where(firstClause) assertThatTheThenResponseRan();
.or(secondClause) assertThatTheOtherwiseResponseRan();
.then(thenResponse) }
.otherwise(otherwiseResponse);
private void assertThatTheThenResponseRuns() {
assertThatTheThenResponseRan();
assertThatTheOtherwiseResponseDidNotRun();
}
private void assertThatTheOtherwiseResponseRuns() {
assertThatTheThenResponseDidNotRun();
assertThatTheOtherwiseResponseRan();
}
private void assertThatTheOtherwiseResponseRan() {
assertThat(otherwiseFlag).as("otherwise response runs")
.isTrue();
}
private void assertThatTheThenResponseRan() {
assertThat(thenFlag).as("then response runs")
.isTrue();
}
private void assertThatTheOtherwiseResponseDidNotRun() {
assertThat(otherwiseFlag).as("otherwise response does not run")
.isFalse();
}
private void assertThatTheThenResponseDidNotRun() {
assertThat(thenFlag).as("then response does not run")
.isFalse();
}
private void assertThatNoResponseRuns() {
assertThatTheThenResponseDidNotRun();
assertThatTheOtherwiseResponseDidNotRun();
} }
private void when(final boolean clause) { private void when(final boolean clause) {
@ -231,51 +264,23 @@ public class ConditionalTest {
.otherwise(otherwiseResponse); .otherwise(otherwiseResponse);
} }
private void thenBothResponsesRun() { private void when(
theThenResponseRan(); final boolean firstClause,
theOtherwiseResponseRan(); final boolean secondClause
} ) {
private void thenTheThenResponseRuns() {
theThenResponseRan();
theOtherwiseResponseDidNotRun();
}
private void thenTheOtherwiseResponseRuns() {
theThenResponseDidNotRun();
theOtherwiseResponseRan();
}
private void theOtherwiseResponseRan() {
assertThat(otherwiseFlag).as("otherwise response runs")
.isTrue();
}
private void theThenResponseRan() {
assertThat(thenFlag).as("then response runs")
.isTrue();
}
private void theOtherwiseResponseDidNotRun() {
assertThat(otherwiseFlag).as("otherwise response does not run")
.isFalse();
}
private void theThenResponseDidNotRun() {
assertThat(thenFlag).as("then response does not run")
.isFalse();
}
private void thenNoResponseRuns() {
theThenResponseDidNotRun();
theOtherwiseResponseDidNotRun();
}
private void when(final boolean firstClause, final boolean secondClause) {
Condition.where(firstClause) Condition.where(firstClause)
.and(secondClause) .and(secondClause)
.then(thenResponse) .then(thenResponse)
.otherwise(otherwiseResponse); .otherwise(otherwiseResponse);
} }
private void whenOr(
final boolean firstClause,
final boolean secondClause
) {
Condition.where(firstClause)
.or(secondClause)
.then(thenResponse)
.otherwise(otherwiseResponse);
}
} }

View file

@ -1,7 +1,10 @@
package net.kemitix.conditional; package net.kemitix.conditional;
import lombok.val;
import org.junit.Test; import org.junit.Test;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
@ -14,207 +17,230 @@ public class ValueTest {
private static final String FALSE = "false"; private static final String FALSE = "false";
@Test @Test
public void valueWhereTrueIsTrue() { public void valueWhereClauseIsTrueTypeSafe() {
//when //when
final String result = Value.<String>where(true).then(() -> TRUE) final String result = Value.where(true, () -> TRUE, () -> FALSE);
.otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereFalseIsFalse() { public void valueWhereClauseIsFalseTypeSafe() {
//when //when
final String result = Value.<String>where(false).then(() -> TRUE) final String result = Value.where(false, () -> TRUE, () -> FALSE);
//then
assertThat(result).isEqualTo(FALSE);
}
@Test
public void valueWhereClauseIsTrueIsOptional() {
//when
final Optional<String> result = Value.where(true, () -> TRUE);
//then
assertThat(result).contains(TRUE);
}
@Test
public void valueWhereClauseIsFalseIsEmptyOptional() {
//when
final Optional<String> result = Value.where(false, () -> TRUE);
//then
assertThat(result).isEmpty();
}
@Test
public void valueWhereClauseIsTrue() {
//when
val result = Value.<String>where(true).then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(TRUE);
}
@Test
public void valueWhereClauseIsFalse() {
//when
val result = Value.<String>where(false).then(() -> TRUE)
.otherwise(() -> FALSE);
//then
assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereTrueAndTrueIsTrue() { public void valueWhereTrueAndTrueIsTrue() {
//when //when
final String result = Value.<String>where(true).and(true) val result = Value.<String>where(true).and(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereTrueAndFalseIsFalse() { public void valueWhereTrueAndFalseIsFalse() {
//when //when
final String result = Value.<String>where(true).and(false) val result = Value.<String>where(true).and(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereFalseAndTrueIsFalse() { public void valueWhereFalseAndTrueIsFalse() {
//when //when
final String result = Value.<String>where(false).and(true) val result = Value.<String>where(false).and(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereFalseAndFalseIsFalse() { public void valueWhereFalseAndFalseIsFalse() {
//when //when
final String result = Value.<String>where(false).and(false) val result = Value.<String>where(false).and(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereTrueOrTrueIsTrue() { public void valueWhereTrueOrTrueIsTrue() {
//when //when
final String result = Value.<String>where(true).or(true) val result = Value.<String>where(true).or(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereTrueOrFalseIsTrue() { public void valueWhereTrueOrFalseIsTrue() {
//when //when
final String result = Value.<String>where(true).or(false) val result = Value.<String>where(true).or(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereFalseOrTrueIsTrue() { public void valueWhereFalseOrTrueIsTrue() {
//when //when
final String result = Value.<String>where(false).or(true) val result = Value.<String>where(false).or(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereFalseOrFalseIsFalse() { public void valueWhereFalseOrFalseIsFalse() {
//when //when
final String result = Value.<String>where(false).or(false) val result = Value.<String>where(false).or(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereNotTrueIsFalse() { public void valueWhereNotTrueIsFalse() {
//when //when
final String result = Value.<String>whereNot(true).then(() -> TRUE) val result = Value.<String>whereNot(true).then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereNotFalseIsTrue() { public void valueWhereNotFalseIsTrue() {
//when //when
final String result = Value.<String>whereNot(false).then(() -> TRUE) val result = Value.<String>whereNot(false).then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereTrueAndNotTrueIsFalse() { public void valueWhereTrueAndNotTrueIsFalse() {
//when //when
final String result = Value.<String>where(true).andNot(true) val result = Value.<String>where(true).andNot(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereTrueAndNotFalseIsTrue() { public void valueWhereTrueAndNotFalseIsTrue() {
//when //when
final String result = Value.<String>where(true).andNot(false) val result = Value.<String>where(true).andNot(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereFalseAndNotTrueIsFalse() { public void valueWhereFalseAndNotTrueIsFalse() {
//when //when
final String result = Value.<String>where(false).andNot(true) val result = Value.<String>where(false).andNot(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereFalseAndNotFalseIsFalse() { public void valueWhereFalseAndNotFalseIsFalse() {
//when //when
final String result = Value.<String>where(false).andNot(false) val result = Value.<String>where(false).andNot(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereTrueOrNotTrueIsTrue() { public void valueWhereTrueOrNotTrueIsTrue() {
//when //when
final String result = Value.<String>where(true).orNot(true) val result = Value.<String>where(true).orNot(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereTrueOrNotFalseIsTrue() { public void valueWhereTrueOrNotFalseIsTrue() {
//when //when
final String result = Value.<String>where(true).orNot(false) val result = Value.<String>where(true).orNot(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result); assertThat(result).isEqualTo(TRUE);
} }
@Test @Test
public void valueWhereFalseOrNotTrueIsFalse() { public void valueWhereFalseOrNotTrueIsFalse() {
//when //when
final String result = Value.<String>where(false).orNot(true) val result = Value.<String>where(false).orNot(true)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsFalse(result); assertThat(result).isEqualTo(FALSE);
} }
@Test @Test
public void valueWhereFalseOrNotFalseIsTrue() { public void valueWhereFalseOrNotFalseIsTrue() {
//when //when
final String result = Value.<String>where(false).orNot(false) val result = Value.<String>where(false).orNot(false)
.then(() -> TRUE) .then(() -> TRUE)
.otherwise(() -> FALSE); .otherwise(() -> FALSE);
//then //then
thenIsTrue(result);
}
private void thenIsFalse(final String result) {
assertThat(result).isEqualTo(FALSE);
}
private void thenIsTrue(final String result) {
assertThat(result).isEqualTo(TRUE); assertThat(result).isEqualTo(TRUE);
} }
} }

6
wercker.yml Normal file
View file

@ -0,0 +1,6 @@
box: maven:3.5.0-jdk-8
build:
steps:
- xenoterracide/maven:
goals: clean install