commit
bab96c5621
20 changed files with 931 additions and 323 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal 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
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
1
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
1
.mvn/wrapper/maven-wrapper.properties
vendored
Normal 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
1
.travis-support
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit b8593e541ba9a11447fa9559a83e5f99097ca4d2
|
17
.travis.yml
17
.travis.yml
|
@ -1,5 +1,18 @@
|
|||
language: java
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
- oraclejdk8
|
||||
cache:
|
||||
directories:
|
||||
- "$HOME/.m2"
|
||||
install: true
|
||||
script: "./mvnw clean install"
|
||||
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
28
CHANGELOG
Normal 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
|
19
README.adoc
19
README.adoc
|
@ -1,11 +1,12 @@
|
|||
# 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://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
|
||||
|
||||
|
@ -200,6 +201,16 @@ if (isTrue()) {
|
|||
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]]
|
||||
----
|
||||
final String result = Value.<String>where(isTrue()).then(() -> TRUE)
|
||||
|
|
3
circle.yml
Normal file
3
circle.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
test:
|
||||
override:
|
||||
- ./mvnw clean install
|
236
mvnw
vendored
Executable file
236
mvnw
vendored
Executable 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
146
mvnw.cmd
vendored
Normal 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
26
pom.xml
|
@ -4,21 +4,26 @@
|
|||
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>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>net.kemitix</groupId>
|
||||
<artifactId>kemitix-parent</artifactId>
|
||||
<version>2.7.0</version>
|
||||
<version>3.2.0</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<artifactId>conditional</artifactId>
|
||||
<version>0.2.0</version>
|
||||
<version>0.3.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -41,11 +46,14 @@
|
|||
<groupId>net.kemitix</groupId>
|
||||
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
|
||||
<version>${kemitix-checkstyle-ruleset.version}</version>
|
||||
<configuration>
|
||||
<level>${kemitix-checkstyle-ruleset.level}</level>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>${kemitix-checkstyle-ruleset.level}</goal>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
@ -57,12 +65,4 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>sevntu-maven</id>
|
||||
<name>sevntu-maven</name>
|
||||
<url>http://sevntu-checkstyle.github.io/sevntu.checkstyle/maven2</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
</project>
|
||||
|
|
|
@ -21,12 +21,6 @@
|
|||
|
||||
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.
|
||||
*
|
||||
|
@ -34,14 +28,6 @@ import java.util.stream.Stream;
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -49,8 +35,9 @@ public interface Condition {
|
|||
*
|
||||
* @return the Condition
|
||||
*/
|
||||
@SuppressWarnings("avoidinlineconditionals")
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
53
src/main/java/net/kemitix/conditional/FalseCondition.java
Normal file
53
src/main/java/net/kemitix/conditional/FalseCondition.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
64
src/main/java/net/kemitix/conditional/FalseValueClause.java
Normal file
64
src/main/java/net/kemitix/conditional/FalseValueClause.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
54
src/main/java/net/kemitix/conditional/TrueCondition.java
Normal file
54
src/main/java/net/kemitix/conditional/TrueCondition.java
Normal 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
|
||||
}
|
||||
|
||||
}
|
69
src/main/java/net/kemitix/conditional/TrueValueClause.java
Normal file
69
src/main/java/net/kemitix/conditional/TrueValueClause.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
package net.kemitix.conditional;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
|
@ -30,6 +31,41 @@ import java.util.function.Supplier;
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -38,11 +74,9 @@ public interface Value {
|
|||
*
|
||||
* @return a true or false value clause
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "avoidinlineconditionals"})
|
||||
static <T> ValueClause<T> where(final boolean clause) {
|
||||
if (clause) {
|
||||
return new TrueValueClause<>();
|
||||
}
|
||||
return new FalseValueClause<>();
|
||||
return (ValueClause<T>) (clause ? TrueValueClause.TRUE : FalseValueClause.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class ConditionalTest {
|
|||
//when
|
||||
when(true);
|
||||
//then
|
||||
thenTheThenResponseRuns();
|
||||
assertThatTheThenResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -37,7 +37,7 @@ public class ConditionalTest {
|
|||
//when
|
||||
when(false);
|
||||
//then
|
||||
thenTheOtherwiseResponseRuns();
|
||||
assertThatTheOtherwiseResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -45,7 +45,7 @@ public class ConditionalTest {
|
|||
//when
|
||||
when(true, true);
|
||||
//then
|
||||
thenTheThenResponseRuns();
|
||||
assertThatTheThenResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -53,7 +53,7 @@ public class ConditionalTest {
|
|||
//when
|
||||
when(true, false);
|
||||
//then
|
||||
thenTheOtherwiseResponseRuns();
|
||||
assertThatTheOtherwiseResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -61,7 +61,7 @@ public class ConditionalTest {
|
|||
//when
|
||||
when(false, true);
|
||||
//then
|
||||
thenTheOtherwiseResponseRuns();
|
||||
assertThatTheOtherwiseResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -69,7 +69,7 @@ public class ConditionalTest {
|
|||
//when
|
||||
when(false, false);
|
||||
//then
|
||||
thenTheOtherwiseResponseRuns();
|
||||
assertThatTheOtherwiseResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -80,7 +80,7 @@ public class ConditionalTest {
|
|||
.and(true)
|
||||
.then(otherwiseResponse);
|
||||
//then
|
||||
thenBothResponsesRun();
|
||||
assertThatBothResponsesRun();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -88,7 +88,7 @@ public class ConditionalTest {
|
|||
//when
|
||||
whenOr(true, true);
|
||||
//then
|
||||
thenTheThenResponseRuns();
|
||||
assertThatTheThenResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -96,7 +96,7 @@ public class ConditionalTest {
|
|||
//when
|
||||
whenOr(true, false);
|
||||
//then
|
||||
thenTheThenResponseRuns();
|
||||
assertThatTheThenResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -104,7 +104,7 @@ public class ConditionalTest {
|
|||
//when
|
||||
whenOr(false, true);
|
||||
//then
|
||||
thenTheThenResponseRuns();
|
||||
assertThatTheThenResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -112,7 +112,7 @@ public class ConditionalTest {
|
|||
//when
|
||||
whenOr(false, false);
|
||||
//then
|
||||
thenTheOtherwiseResponseRuns();
|
||||
assertThatTheOtherwiseResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -121,7 +121,7 @@ public class ConditionalTest {
|
|||
Condition.whereNot(false)
|
||||
.then(thenResponse);
|
||||
//then
|
||||
thenTheThenResponseRuns();
|
||||
assertThatTheThenResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -131,7 +131,7 @@ public class ConditionalTest {
|
|||
.then(thenResponse)
|
||||
.otherwise(otherwiseResponse);
|
||||
//then
|
||||
thenTheOtherwiseResponseRuns();
|
||||
assertThatTheOtherwiseResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -141,7 +141,7 @@ public class ConditionalTest {
|
|||
.andNot(false)
|
||||
.then(thenResponse);
|
||||
//then
|
||||
thenTheThenResponseRuns();
|
||||
assertThatTheThenResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -152,7 +152,7 @@ public class ConditionalTest {
|
|||
.then(thenResponse)
|
||||
.otherwise(otherwiseResponse);
|
||||
//then
|
||||
thenTheOtherwiseResponseRuns();
|
||||
assertThatTheOtherwiseResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -162,7 +162,7 @@ public class ConditionalTest {
|
|||
.orNot(false)
|
||||
.then(thenResponse);
|
||||
//then
|
||||
thenTheThenResponseRuns();
|
||||
assertThatTheThenResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -173,7 +173,7 @@ public class ConditionalTest {
|
|||
.then(thenResponse)
|
||||
.otherwise(otherwiseResponse);
|
||||
//then
|
||||
thenTheOtherwiseResponseRuns();
|
||||
assertThatTheOtherwiseResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -184,7 +184,7 @@ public class ConditionalTest {
|
|||
.otherwise(true)
|
||||
.then(otherwiseResponse);
|
||||
//then
|
||||
thenTheOtherwiseResponseRuns();
|
||||
assertThatTheOtherwiseResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -195,7 +195,7 @@ public class ConditionalTest {
|
|||
.otherwise(false)
|
||||
.then(otherwiseResponse);
|
||||
//then
|
||||
thenNoResponseRuns();
|
||||
assertThatNoResponseRuns();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -205,7 +205,7 @@ public class ConditionalTest {
|
|||
.then(thenResponse)
|
||||
.then(otherwiseResponse);
|
||||
//then
|
||||
thenBothResponsesRun();
|
||||
assertThatBothResponsesRun();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -215,14 +215,47 @@ public class ConditionalTest {
|
|||
.then(thenResponse)
|
||||
.then(otherwiseResponse);
|
||||
//then
|
||||
thenNoResponseRuns();
|
||||
assertThatNoResponseRuns();
|
||||
}
|
||||
|
||||
private void whenOr(final boolean firstClause, final boolean secondClause) {
|
||||
Condition.where(firstClause)
|
||||
.or(secondClause)
|
||||
.then(thenResponse)
|
||||
.otherwise(otherwiseResponse);
|
||||
private void assertThatBothResponsesRun() {
|
||||
assertThatTheThenResponseRan();
|
||||
assertThatTheOtherwiseResponseRan();
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -231,51 +264,23 @@ public class ConditionalTest {
|
|||
.otherwise(otherwiseResponse);
|
||||
}
|
||||
|
||||
private void thenBothResponsesRun() {
|
||||
theThenResponseRan();
|
||||
theOtherwiseResponseRan();
|
||||
}
|
||||
|
||||
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) {
|
||||
private void when(
|
||||
final boolean firstClause,
|
||||
final boolean secondClause
|
||||
) {
|
||||
Condition.where(firstClause)
|
||||
.and(secondClause)
|
||||
.then(thenResponse)
|
||||
.otherwise(otherwiseResponse);
|
||||
}
|
||||
|
||||
private void whenOr(
|
||||
final boolean firstClause,
|
||||
final boolean secondClause
|
||||
) {
|
||||
Condition.where(firstClause)
|
||||
.or(secondClause)
|
||||
.then(thenResponse)
|
||||
.otherwise(otherwiseResponse);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package net.kemitix.conditional;
|
||||
|
||||
import lombok.val;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
|
@ -14,207 +17,230 @@ public class ValueTest {
|
|||
private static final String FALSE = "false";
|
||||
|
||||
@Test
|
||||
public void valueWhereTrueIsTrue() {
|
||||
public void valueWhereClauseIsTrueTypeSafe() {
|
||||
//when
|
||||
final String result = Value.<String>where(true).then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
final String result = Value.where(true, () -> TRUE, () -> FALSE);
|
||||
//then
|
||||
thenIsTrue(result);
|
||||
assertThat(result).isEqualTo(TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereFalseIsFalse() {
|
||||
public void valueWhereClauseIsFalseTypeSafe() {
|
||||
//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);
|
||||
//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
|
||||
public void valueWhereTrueAndTrueIsTrue() {
|
||||
//when
|
||||
final String result = Value.<String>where(true).and(true)
|
||||
val result = Value.<String>where(true).and(true)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsTrue(result);
|
||||
assertThat(result).isEqualTo(TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereTrueAndFalseIsFalse() {
|
||||
//when
|
||||
final String result = Value.<String>where(true).and(false)
|
||||
val result = Value.<String>where(true).and(false)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsFalse(result);
|
||||
assertThat(result).isEqualTo(FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereFalseAndTrueIsFalse() {
|
||||
//when
|
||||
final String result = Value.<String>where(false).and(true)
|
||||
val result = Value.<String>where(false).and(true)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsFalse(result);
|
||||
assertThat(result).isEqualTo(FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereFalseAndFalseIsFalse() {
|
||||
//when
|
||||
final String result = Value.<String>where(false).and(false)
|
||||
val result = Value.<String>where(false).and(false)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsFalse(result);
|
||||
assertThat(result).isEqualTo(FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereTrueOrTrueIsTrue() {
|
||||
//when
|
||||
final String result = Value.<String>where(true).or(true)
|
||||
val result = Value.<String>where(true).or(true)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsTrue(result);
|
||||
assertThat(result).isEqualTo(TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereTrueOrFalseIsTrue() {
|
||||
//when
|
||||
final String result = Value.<String>where(true).or(false)
|
||||
val result = Value.<String>where(true).or(false)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsTrue(result);
|
||||
assertThat(result).isEqualTo(TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereFalseOrTrueIsTrue() {
|
||||
//when
|
||||
final String result = Value.<String>where(false).or(true)
|
||||
val result = Value.<String>where(false).or(true)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsTrue(result);
|
||||
assertThat(result).isEqualTo(TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereFalseOrFalseIsFalse() {
|
||||
//when
|
||||
final String result = Value.<String>where(false).or(false)
|
||||
val result = Value.<String>where(false).or(false)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsFalse(result);
|
||||
assertThat(result).isEqualTo(FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereNotTrueIsFalse() {
|
||||
//when
|
||||
final String result = Value.<String>whereNot(true).then(() -> TRUE)
|
||||
val result = Value.<String>whereNot(true).then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsFalse(result);
|
||||
assertThat(result).isEqualTo(FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereNotFalseIsTrue() {
|
||||
//when
|
||||
final String result = Value.<String>whereNot(false).then(() -> TRUE)
|
||||
val result = Value.<String>whereNot(false).then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsTrue(result);
|
||||
assertThat(result).isEqualTo(TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereTrueAndNotTrueIsFalse() {
|
||||
//when
|
||||
final String result = Value.<String>where(true).andNot(true)
|
||||
val result = Value.<String>where(true).andNot(true)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsFalse(result);
|
||||
assertThat(result).isEqualTo(FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereTrueAndNotFalseIsTrue() {
|
||||
//when
|
||||
final String result = Value.<String>where(true).andNot(false)
|
||||
val result = Value.<String>where(true).andNot(false)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsTrue(result);
|
||||
assertThat(result).isEqualTo(TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereFalseAndNotTrueIsFalse() {
|
||||
//when
|
||||
final String result = Value.<String>where(false).andNot(true)
|
||||
val result = Value.<String>where(false).andNot(true)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsFalse(result);
|
||||
assertThat(result).isEqualTo(FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereFalseAndNotFalseIsFalse() {
|
||||
//when
|
||||
final String result = Value.<String>where(false).andNot(false)
|
||||
val result = Value.<String>where(false).andNot(false)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsFalse(result);
|
||||
assertThat(result).isEqualTo(FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereTrueOrNotTrueIsTrue() {
|
||||
//when
|
||||
final String result = Value.<String>where(true).orNot(true)
|
||||
val result = Value.<String>where(true).orNot(true)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsTrue(result);
|
||||
assertThat(result).isEqualTo(TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereTrueOrNotFalseIsTrue() {
|
||||
//when
|
||||
final String result = Value.<String>where(true).orNot(false)
|
||||
val result = Value.<String>where(true).orNot(false)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsTrue(result);
|
||||
assertThat(result).isEqualTo(TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereFalseOrNotTrueIsFalse() {
|
||||
//when
|
||||
final String result = Value.<String>where(false).orNot(true)
|
||||
val result = Value.<String>where(false).orNot(true)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsFalse(result);
|
||||
assertThat(result).isEqualTo(FALSE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void valueWhereFalseOrNotFalseIsTrue() {
|
||||
//when
|
||||
final String result = Value.<String>where(false).orNot(false)
|
||||
val result = Value.<String>where(false).orNot(false)
|
||||
.then(() -> TRUE)
|
||||
.otherwise(() -> FALSE);
|
||||
//then
|
||||
thenIsTrue(result);
|
||||
}
|
||||
|
||||
private void thenIsFalse(final String result) {
|
||||
assertThat(result).isEqualTo(FALSE);
|
||||
}
|
||||
|
||||
private void thenIsTrue(final String result) {
|
||||
assertThat(result).isEqualTo(TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
6
wercker.yml
Normal file
6
wercker.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
box: maven:3.5.0-jdk-8
|
||||
|
||||
build:
|
||||
steps:
|
||||
- xenoterracide/maven:
|
||||
goals: clean install
|
Loading…
Reference in a new issue