Bump junit from 4.12 to 5.3.1 (#56)
* Bump junit from 4.12 to 5.3.1 * [changelog] update * [jenkins] stop publishing to codacy and test build with java 11
This commit is contained in:
parent
f92c9cfa65
commit
73e59b0050
18 changed files with 246 additions and 223 deletions
|
@ -4,7 +4,8 @@ CHANGELOG
|
||||||
1.2.1
|
1.2.1
|
||||||
-----
|
-----
|
||||||
|
|
||||||
* Bump kemitix-parent from 5.1.1 to 5.2.0
|
* Bump kemitix-parent from 5.1.1 to 5.2.0 (#55)
|
||||||
|
* Bump junit from 4.12 to 5.3.1 [#56)
|
||||||
|
|
||||||
1.2.0
|
1.2.0
|
||||||
-----
|
-----
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
final String publicRepo = 'https://github.com/kemitix/'
|
final String publicRepo = 'https://github.com/kemitix/'
|
||||||
final String mvn = "mvn --batch-mode --update-snapshots --errors"
|
final String mvn = "mvn --batch-mode --update-snapshots --errors"
|
||||||
final dependenciesSupportJDK = 10
|
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
@ -9,12 +8,6 @@ pipeline {
|
||||||
steps {
|
steps {
|
||||||
withMaven(maven: 'maven', jdk: 'JDK 1.8') {
|
withMaven(maven: 'maven', jdk: 'JDK 1.8') {
|
||||||
sh "${mvn} clean compile checkstyle:checkstyle pmd:pmd test"
|
sh "${mvn} clean compile checkstyle:checkstyle pmd:pmd test"
|
||||||
// Code Coverage to Codacy
|
|
||||||
sh "${mvn} jacoco:report com.gavinmogan:codacy-maven-plugin:coverage " +
|
|
||||||
"-DcoverageReportFile=target/site/jacoco/jacoco.xml " +
|
|
||||||
"-DprojectToken=`$JENKINS_HOME/codacy/token` " +
|
|
||||||
"-DapiToken=`$JENKINS_HOME/codacy/apitoken` " +
|
|
||||||
"-Dcommit=`git rev-parse HEAD`"
|
|
||||||
// Code Coverage to Jenkins
|
// Code Coverage to Jenkins
|
||||||
jacoco exclusionPattern: '**/*{Test|IT|Main|Application|Immutable}.class'
|
jacoco exclusionPattern: '**/*{Test|IT|Main|Application|Immutable}.class'
|
||||||
// PMD to Jenkins
|
// PMD to Jenkins
|
||||||
|
@ -58,19 +51,10 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Build Java 9') {
|
stage('Build Java 11') {
|
||||||
when { expression { dependenciesSupportJDK >= 9 } }
|
|
||||||
steps {
|
steps {
|
||||||
withMaven(maven: 'maven', jdk: 'JDK 9') {
|
withMaven(maven: 'maven', jdk: 'JDK 11') {
|
||||||
sh "${mvn} clean verify -Djava.version=9"
|
sh "${mvn} clean verify -Djava.version=11"
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('Build Java 10') {
|
|
||||||
when { expression { dependenciesSupportJDK >= 10 } }
|
|
||||||
steps {
|
|
||||||
withMaven(maven: 'maven', jdk: 'JDK 10') {
|
|
||||||
sh "${mvn} clean verify -Djava.version=10"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
47
pom.xml
47
pom.xml
|
@ -33,13 +33,16 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<junit.version>4.12</junit.version>
|
<junit.version>5.3.1</junit.version>
|
||||||
|
<mockito.version>2.23.0</mockito.version>
|
||||||
<assertj.version>3.11.1</assertj.version>
|
<assertj.version>3.11.1</assertj.version>
|
||||||
<lombok.version>1.18.2</lombok.version>
|
<lombok.version>1.18.2</lombok.version>
|
||||||
<tiles-maven-plugin.version>2.12</tiles-maven-plugin.version>
|
<tiles-maven-plugin.version>2.12</tiles-maven-plugin.version>
|
||||||
<kemitix-maven-tiles.version>1.2.0</kemitix-maven-tiles.version>
|
<kemitix-maven-tiles.version>1.2.0</kemitix-maven-tiles.version>
|
||||||
<digraph-dependency.basePackage>net.kemitix.mon</digraph-dependency.basePackage>
|
<digraph-dependency.basePackage>net.kemitix.mon</digraph-dependency.basePackage>
|
||||||
<kemitix-checkstyle.version>5.0.0</kemitix-checkstyle.version>
|
<kemitix-checkstyle.version>5.0.0</kemitix-checkstyle.version>
|
||||||
|
<pitest-maven-plugin.version>1.4.3</pitest-maven-plugin.version>
|
||||||
|
<pitest-junit5-plugin.version>0.7</pitest-junit5-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -49,10 +52,21 @@
|
||||||
<version>${lombok.version}</version>
|
<version>${lombok.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>${junit.version}</version>
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<version>${mockito.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -63,6 +77,18 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit</groupId>
|
||||||
|
<artifactId>junit-bom</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -77,6 +103,19 @@
|
||||||
</tiles>
|
</tiles>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin><!-- tiles-maven-plugin -->
|
</plugin><!-- tiles-maven-plugin -->
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.pitest</groupId>
|
||||||
|
<artifactId>pitest-maven</artifactId>
|
||||||
|
<version>${pitest-maven-plugin.version}</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.pitest</groupId>
|
||||||
|
<artifactId>pitest-junit5-plugin</artifactId>
|
||||||
|
<version>${pitest-junit5-plugin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
|
@ -5,15 +5,15 @@ import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import net.kemitix.mon.experimental.BeanBuilder;
|
import net.kemitix.mon.experimental.BeanBuilder;
|
||||||
import org.assertj.core.api.WithAssertions;
|
import org.assertj.core.api.WithAssertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class BeanBuilderTest implements WithAssertions {
|
class BeanBuilderTest implements WithAssertions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canCreateAndSetupObject() {
|
void canCreateAndSetupObject() {
|
||||||
//given
|
//given
|
||||||
final Supplier<DataObject> template = () -> new DataObject("name");
|
final Supplier<DataObject> template = () -> new DataObject("name");
|
||||||
final Consumer<DataObject> value = data -> data.setValue("value");
|
final Consumer<DataObject> value = data -> data.setValue("value");
|
||||||
|
|
|
@ -2,12 +2,12 @@ package net.kemitix.mon;
|
||||||
|
|
||||||
import net.kemitix.mon.experimental.either.Either;
|
import net.kemitix.mon.experimental.either.Either;
|
||||||
import org.assertj.core.api.WithAssertions;
|
import org.assertj.core.api.WithAssertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class EitherTest implements WithAssertions {
|
class EitherTest implements WithAssertions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenLeft_isLeft() {
|
void whenLeft_isLeft() {
|
||||||
//when
|
//when
|
||||||
final Either<Integer, String> either = Either.left(1);
|
final Either<Integer, String> either = Either.left(1);
|
||||||
//then
|
//then
|
||||||
|
@ -15,7 +15,7 @@ public class EitherTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenLeft_isNotRight() {
|
void whenLeft_isNotRight() {
|
||||||
//when
|
//when
|
||||||
final Either<Integer, String> either = Either.left(1);
|
final Either<Integer, String> either = Either.left(1);
|
||||||
//then
|
//then
|
||||||
|
@ -23,7 +23,7 @@ public class EitherTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRight_isNotLeft() {
|
void whenRight_isNotLeft() {
|
||||||
//when
|
//when
|
||||||
final Either<Integer, String> either = Either.right("1");
|
final Either<Integer, String> either = Either.right("1");
|
||||||
//then
|
//then
|
||||||
|
@ -31,7 +31,7 @@ public class EitherTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRight_isRight() {
|
void whenRight_isRight() {
|
||||||
//when
|
//when
|
||||||
final Either<Integer, String> either = Either.right("1");
|
final Either<Integer, String> either = Either.right("1");
|
||||||
//then
|
//then
|
||||||
|
@ -39,7 +39,7 @@ public class EitherTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenLeft_matchLeft() {
|
void whenLeft_matchLeft() {
|
||||||
//given
|
//given
|
||||||
final Either<Integer, String> either = Either.left(1);
|
final Either<Integer, String> either = Either.left(1);
|
||||||
//then
|
//then
|
||||||
|
@ -50,7 +50,7 @@ public class EitherTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRight_matchRight() {
|
void whenRight_matchRight() {
|
||||||
//given
|
//given
|
||||||
final Either<Integer, String> either = Either.right("1");
|
final Either<Integer, String> either = Either.right("1");
|
||||||
//then
|
//then
|
||||||
|
@ -61,7 +61,7 @@ public class EitherTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenLeft_whenMapLeft_thenMap() {
|
void givenLeft_whenMapLeft_thenMap() {
|
||||||
//given
|
//given
|
||||||
final Either<Integer, String> either = Either.left(2);
|
final Either<Integer, String> either = Either.left(2);
|
||||||
//when
|
//when
|
||||||
|
@ -74,7 +74,7 @@ public class EitherTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenRight_whenMapRight_thenMap() {
|
void givenRight_whenMapRight_thenMap() {
|
||||||
//given
|
//given
|
||||||
final Either<Integer, String> either = Either.right("2");
|
final Either<Integer, String> either = Either.right("2");
|
||||||
//when
|
//when
|
||||||
|
@ -87,7 +87,7 @@ public class EitherTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenLeft_whenMapRight_thenDoNothing() {
|
void givenLeft_whenMapRight_thenDoNothing() {
|
||||||
//given
|
//given
|
||||||
final Either<Integer, String> either = Either.left(2);
|
final Either<Integer, String> either = Either.left(2);
|
||||||
//when
|
//when
|
||||||
|
@ -100,7 +100,7 @@ public class EitherTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenRight_whenMapLeft_thenDoNothing() {
|
void givenRight_whenMapLeft_thenDoNothing() {
|
||||||
//given
|
//given
|
||||||
final Either<Integer, String> either = Either.right("2");
|
final Either<Integer, String> either = Either.right("2");
|
||||||
//when
|
//when
|
||||||
|
|
|
@ -2,11 +2,11 @@ package net.kemitix.mon;
|
||||||
|
|
||||||
import net.kemitix.mon.maybe.Maybe;
|
import net.kemitix.mon.maybe.Maybe;
|
||||||
import org.assertj.core.api.WithAssertions;
|
import org.assertj.core.api.WithAssertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class MaybeMonadTest implements WithAssertions {
|
class MaybeMonadTest implements WithAssertions {
|
||||||
|
|
||||||
private final int v = 1;
|
private final int v = 1;
|
||||||
private final Function<Integer, Maybe<Integer>> f = i -> m(i * 2);
|
private final Function<Integer, Maybe<Integer>> f = i -> m(i * 2);
|
||||||
|
@ -17,7 +17,7 @@ public class MaybeMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void leftIdentity() {
|
void leftIdentity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
m(v).flatMap(f)
|
m(v).flatMap(f)
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
@ -26,7 +26,7 @@ public class MaybeMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rightIdentity() {
|
void rightIdentity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
m(v).flatMap(x -> m(x))
|
m(v).flatMap(x -> m(x))
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
@ -35,7 +35,7 @@ public class MaybeMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void associativity() {
|
void associativity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
m(v).flatMap(f).flatMap(g)
|
m(v).flatMap(f).flatMap(g)
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
|
|
@ -2,7 +2,7 @@ package net.kemitix.mon;
|
||||||
|
|
||||||
import net.kemitix.mon.maybe.Maybe;
|
import net.kemitix.mon.maybe.Maybe;
|
||||||
import org.assertj.core.api.WithAssertions;
|
import org.assertj.core.api.WithAssertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -13,25 +13,25 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import static net.kemitix.mon.maybe.Maybe.*;
|
import static net.kemitix.mon.maybe.Maybe.*;
|
||||||
|
|
||||||
public class MaybeTest implements WithAssertions {
|
class MaybeTest implements WithAssertions {
|
||||||
|
|
||||||
private static <T> Predicate<T> eq(final T value) {
|
private static <T> Predicate<T> eq(final T value) {
|
||||||
return v -> Objects.equals(value, v);
|
return v -> Objects.equals(value, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void justMustBeNonNull() {
|
void justMustBeNonNull() {
|
||||||
assertThatNullPointerException().isThrownBy(() -> just(null))
|
assertThatNullPointerException().isThrownBy(() -> just(null))
|
||||||
.withMessageContaining("value");
|
.withMessageContaining("value");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothingReusesTheSameInstance() {
|
void nothingReusesTheSameInstance() {
|
||||||
assertThat(nothing()).isSameAs(nothing());
|
assertThat(nothing()).isSameAs(nothing());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equality() {
|
void equality() {
|
||||||
assertThat(just(1)).isEqualTo(just(1));
|
assertThat(just(1)).isEqualTo(just(1));
|
||||||
assertThat(just(1)).isNotEqualTo(just(2));
|
assertThat(just(1)).isNotEqualTo(just(2));
|
||||||
assertThat(just(1)).isNotEqualTo(nothing());
|
assertThat(just(1)).isNotEqualTo(nothing());
|
||||||
|
@ -40,19 +40,19 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void maybeAllowsNull() {
|
void maybeAllowsNull() {
|
||||||
assertThat(just(1)).isEqualTo(maybe(1));
|
assertThat(just(1)).isEqualTo(maybe(1));
|
||||||
assertThat(nothing()).isEqualTo(maybe(null));
|
assertThat(nothing()).isEqualTo(maybe(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void map() {
|
void map() {
|
||||||
assertThat(just(1).map(v -> v + 1)).isEqualTo(just(2));
|
assertThat(just(1).map(v -> v + 1)).isEqualTo(just(2));
|
||||||
assertThat(nothing().map(v -> v)).isEqualTo(nothing());
|
assertThat(nothing().map(v -> v)).isEqualTo(nothing());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mapToNull_thenJustNull() {
|
void mapToNull_thenJustNull() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> maybe = just(1);
|
final Maybe<Integer> maybe = just(1);
|
||||||
//when
|
//when
|
||||||
|
@ -65,7 +65,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void optional_mapToNull_thenJustNull() {
|
void optional_mapToNull_thenJustNull() {
|
||||||
//given
|
//given
|
||||||
final Optional<Integer> optional = Optional.ofNullable(1);
|
final Optional<Integer> optional = Optional.ofNullable(1);
|
||||||
//when
|
//when
|
||||||
|
@ -75,49 +75,49 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void justHashCode() {
|
void justHashCode() {
|
||||||
assertThat(just(1).hashCode()).isNotEqualTo(just(2).hashCode());
|
assertThat(just(1).hashCode()).isNotEqualTo(just(2).hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothingHashCode() {
|
void nothingHashCode() {
|
||||||
assertThat(nothing().hashCode()).isEqualTo(maybe(null).hashCode());
|
assertThat(nothing().hashCode()).isEqualTo(maybe(null).hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void orElseGet() {
|
void orElseGet() {
|
||||||
assertThat(just(1).orElseGet(() -> -1)).isEqualTo(1);
|
assertThat(just(1).orElseGet(() -> -1)).isEqualTo(1);
|
||||||
assertThat(nothing().orElseGet(() -> -1)).isEqualTo(-1);
|
assertThat(nothing().orElseGet(() -> -1)).isEqualTo(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void orElse() {
|
void orElse() {
|
||||||
assertThat(just(1).orElse(-1)).isEqualTo(1);
|
assertThat(just(1).orElse(-1)).isEqualTo(1);
|
||||||
assertThat(nothing().orElse(-1)).isEqualTo(-1);
|
assertThat(nothing().orElse(-1)).isEqualTo(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void filter() {
|
void filter() {
|
||||||
assertThat(just(1).filter(eq(1))).isEqualTo(just(1));
|
assertThat(just(1).filter(eq(1))).isEqualTo(just(1));
|
||||||
assertThat(just(1).filter(eq(0))).isEqualTo(nothing());
|
assertThat(just(1).filter(eq(0))).isEqualTo(nothing());
|
||||||
assertThat(nothing().filter(eq(1))).isEqualTo(nothing());
|
assertThat(nothing().filter(eq(1))).isEqualTo(nothing());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toOptional() {
|
void toOptional() {
|
||||||
assertThat(just(1).toOptional()).isEqualTo(Optional.of(1));
|
assertThat(just(1).toOptional()).isEqualTo(Optional.of(1));
|
||||||
assertThat(nothing()
|
assertThat(nothing()
|
||||||
.toOptional()).isEqualTo(Optional.empty());
|
.toOptional()).isEqualTo(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void fromOptional() {
|
void fromOptional() {
|
||||||
assertThat(Optional.of(1).map(Maybe::just).orElseGet(Maybe::nothing)).isEqualTo(just(1));
|
assertThat(Optional.of(1).map(Maybe::just).orElseGet(Maybe::nothing)).isEqualTo(just(1));
|
||||||
assertThat(Optional.empty().map(Maybe::just).orElseGet(Maybe::nothing)).isEqualTo(nothing());
|
assertThat(Optional.empty().map(Maybe::just).orElseGet(Maybe::nothing)).isEqualTo(nothing());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void peek() {
|
void peek() {
|
||||||
final AtomicInteger ref = new AtomicInteger(0);
|
final AtomicInteger ref = new AtomicInteger(0);
|
||||||
assertThat(just(1).peek(x -> ref.incrementAndGet())).isEqualTo(just(1));
|
assertThat(just(1).peek(x -> ref.incrementAndGet())).isEqualTo(just(1));
|
||||||
assertThat(ref.get()).isEqualTo(1);
|
assertThat(ref.get()).isEqualTo(1);
|
||||||
|
@ -127,12 +127,12 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void justOrThrowDoesNotThrow() {
|
void justOrThrowDoesNotThrow() {
|
||||||
assertThatCode(() -> just(1).orElseThrow(IllegalStateException::new)).doesNotThrowAnyException();
|
assertThatCode(() -> just(1).orElseThrow(IllegalStateException::new)).doesNotThrowAnyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void justOrThrowReturnsValue() {
|
void justOrThrowReturnsValue() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> maybe = just(1);
|
final Maybe<Integer> maybe = just(1);
|
||||||
//when
|
//when
|
||||||
|
@ -142,13 +142,13 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothingOrThrow() {
|
void nothingOrThrow() {
|
||||||
assertThatThrownBy(() -> nothing().orElseThrow(IllegalStateException::new)).isInstanceOf(
|
assertThatThrownBy(() -> nothing().orElseThrow(IllegalStateException::new)).isInstanceOf(
|
||||||
IllegalStateException.class);
|
IllegalStateException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void justToStream() {
|
void justToStream() {
|
||||||
//when
|
//when
|
||||||
final Stream<Integer> stream = just(1).stream();
|
final Stream<Integer> stream = just(1).stream();
|
||||||
//then
|
//then
|
||||||
|
@ -156,7 +156,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothingToStream() {
|
void nothingToStream() {
|
||||||
//when
|
//when
|
||||||
final Stream<Object> stream = nothing().stream();
|
final Stream<Object> stream = nothing().stream();
|
||||||
//then
|
//then
|
||||||
|
@ -164,7 +164,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void justFlatMap() {
|
void justFlatMap() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> just1 = just(1);
|
final Maybe<Integer> just1 = just(1);
|
||||||
final Maybe<Integer> just2 = just(2);
|
final Maybe<Integer> just2 = just(2);
|
||||||
|
@ -178,7 +178,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothingFlatMap() {
|
void nothingFlatMap() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> nothing1 = nothing();
|
final Maybe<Integer> nothing1 = nothing();
|
||||||
final Maybe<Integer> nothing2 = nothing();
|
final Maybe<Integer> nothing2 = nothing();
|
||||||
|
@ -192,7 +192,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void justNothingFlatMap() {
|
void justNothingFlatMap() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> just1 = just(1);
|
final Maybe<Integer> just1 = just(1);
|
||||||
final Maybe<Integer> nothing2 = nothing();
|
final Maybe<Integer> nothing2 = nothing();
|
||||||
|
@ -206,7 +206,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void just_ifNothing_isIgnored() {
|
void just_ifNothing_isIgnored() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> just = just(1);
|
final Maybe<Integer> just = just(1);
|
||||||
final AtomicBoolean capture = new AtomicBoolean(false);
|
final AtomicBoolean capture = new AtomicBoolean(false);
|
||||||
|
@ -217,7 +217,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothing_ifNothing_isCalled() {
|
void nothing_ifNothing_isCalled() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> nothing = nothing();
|
final Maybe<Integer> nothing = nothing();
|
||||||
final AtomicBoolean capture = new AtomicBoolean(false);
|
final AtomicBoolean capture = new AtomicBoolean(false);
|
||||||
|
@ -228,7 +228,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void just_whenMatch_thenJustTriggers() {
|
void just_whenMatch_thenJustTriggers() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> maybe = just(1);
|
final Maybe<Integer> maybe = just(1);
|
||||||
//then
|
//then
|
||||||
|
@ -239,7 +239,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothing_whenMatch_thenNothingTriggers() {
|
void nothing_whenMatch_thenNothingTriggers() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> maybe = nothing();
|
final Maybe<Integer> maybe = nothing();
|
||||||
final AtomicBoolean flag = new AtomicBoolean(false);
|
final AtomicBoolean flag = new AtomicBoolean(false);
|
||||||
|
@ -253,7 +253,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void just_isJust_isTrue() {
|
void just_isJust_isTrue() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> maybe = just(1);
|
final Maybe<Integer> maybe = just(1);
|
||||||
//when
|
//when
|
||||||
|
@ -263,7 +263,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void just_isNothing_isFalse() {
|
void just_isNothing_isFalse() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> maybe = just(1);
|
final Maybe<Integer> maybe = just(1);
|
||||||
//when
|
//when
|
||||||
|
@ -273,7 +273,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothing_isJust_isFalse() {
|
void nothing_isJust_isFalse() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Object> maybe = nothing();
|
final Maybe<Object> maybe = nothing();
|
||||||
//when
|
//when
|
||||||
|
@ -283,7 +283,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothing_isNothing_isTrue() {
|
void nothing_isNothing_isTrue() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Object> maybe = nothing();
|
final Maybe<Object> maybe = nothing();
|
||||||
//when
|
//when
|
||||||
|
@ -293,7 +293,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void just_or_ignoreTheAlternative() {
|
void just_or_ignoreTheAlternative() {
|
||||||
//given
|
//given
|
||||||
final Maybe<String> one = Maybe.just("one");
|
final Maybe<String> one = Maybe.just("one");
|
||||||
//when
|
//when
|
||||||
|
@ -303,7 +303,7 @@ public class MaybeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothing_or_isTheAlternative() {
|
void nothing_or_isTheAlternative() {
|
||||||
//given
|
//given
|
||||||
final Maybe<String> one = Maybe.nothing();
|
final Maybe<String> one = Maybe.nothing();
|
||||||
//when
|
//when
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.kemitix.mon;
|
package net.kemitix.mon;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -8,10 +8,10 @@ import java.util.function.Function;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
|
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
|
||||||
|
|
||||||
public class MonTest {
|
class MonTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canCreateAndMapCanGetValue() {
|
void canCreateAndMapCanGetValue() {
|
||||||
//when
|
//when
|
||||||
final Mon<String> wrap = Mon.of("test");
|
final Mon<String> wrap = Mon.of("test");
|
||||||
//then
|
//then
|
||||||
|
@ -26,7 +26,7 @@ public class MonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canMap() {
|
void canMap() {
|
||||||
//given
|
//given
|
||||||
final Mon<String> wrap = Mon.of("test");
|
final Mon<String> wrap = Mon.of("test");
|
||||||
//when
|
//when
|
||||||
|
@ -36,7 +36,7 @@ public class MonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canMapInstance() {
|
void canMapInstance() {
|
||||||
//given
|
//given
|
||||||
final Mon<String> wrap = Mon.of("test");
|
final Mon<String> wrap = Mon.of("test");
|
||||||
//when
|
//when
|
||||||
|
@ -46,7 +46,7 @@ public class MonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWithValidatorAndContinuations() {
|
void createWithValidatorAndContinuations() {
|
||||||
//given
|
//given
|
||||||
final Function<String, Optional<Mon<String>>> factory =
|
final Function<String, Optional<Mon<String>>> factory =
|
||||||
Mon.factory(
|
Mon.factory(
|
||||||
|
@ -65,7 +65,7 @@ public class MonTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
||||||
public void canCompare() {
|
void canCompare() {
|
||||||
//given
|
//given
|
||||||
final Mon<String> one = Mon.of("test");
|
final Mon<String> one = Mon.of("test");
|
||||||
final Mon<String> same = Mon.of("test");
|
final Mon<String> same = Mon.of("test");
|
||||||
|
@ -76,7 +76,7 @@ public class MonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canFlatMap() {
|
void canFlatMap() {
|
||||||
//given
|
//given
|
||||||
final Mon<String> wrap = Mon.of("test");
|
final Mon<String> wrap = Mon.of("test");
|
||||||
//when
|
//when
|
||||||
|
@ -88,13 +88,13 @@ public class MonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ofRequiresNonNull() {
|
void ofRequiresNonNull() {
|
||||||
assertThatNullPointerException().isThrownBy(() -> Mon.of(null));
|
assertThatNullPointerException().isThrownBy(() -> Mon.of(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public void factoryRequiresValidator() {
|
void factoryRequiresValidator() {
|
||||||
assertThatNullPointerException().isThrownBy(
|
assertThatNullPointerException().isThrownBy(
|
||||||
() -> Mon.factory(null, Optional::of, Optional::empty))
|
() -> Mon.factory(null, Optional::of, Optional::empty))
|
||||||
.withMessageContaining("validator");
|
.withMessageContaining("validator");
|
||||||
|
@ -102,7 +102,7 @@ public class MonTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public void factoryRequiresOnValid() {
|
void factoryRequiresOnValid() {
|
||||||
assertThatNullPointerException().isThrownBy(
|
assertThatNullPointerException().isThrownBy(
|
||||||
() -> Mon.factory(v -> true, null, Optional::empty))
|
() -> Mon.factory(v -> true, null, Optional::empty))
|
||||||
.withMessageContaining("onValid");
|
.withMessageContaining("onValid");
|
||||||
|
@ -110,14 +110,14 @@ public class MonTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public void factoryRequiresOnInvalid() {
|
void factoryRequiresOnInvalid() {
|
||||||
assertThatNullPointerException().isThrownBy(
|
assertThatNullPointerException().isThrownBy(
|
||||||
() -> Mon.factory(v -> true, Optional::of, null))
|
() -> Mon.factory(v -> true, Optional::of, null))
|
||||||
.withMessageContaining("onInvalid");
|
.withMessageContaining("onInvalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void factory() {
|
void factory() {
|
||||||
//given
|
//given
|
||||||
final Function<Integer, Optional<?>> evenMonFactory =
|
final Function<Integer, Optional<?>> evenMonFactory =
|
||||||
Mon.factory((Integer v) -> v % 2 == 0, Optional::of, Optional::empty);
|
Mon.factory((Integer v) -> v % 2 == 0, Optional::of, Optional::empty);
|
||||||
|
@ -131,7 +131,7 @@ public class MonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldGetInvalidResultWhenFactoryApplyWithNull() {
|
void shouldGetInvalidResultWhenFactoryApplyWithNull() {
|
||||||
//given
|
//given
|
||||||
final Function<Object, Optional<?>> factory = Mon.factory(v -> true, Optional::of, Optional::empty);
|
final Function<Object, Optional<?>> factory = Mon.factory(v -> true, Optional::of, Optional::empty);
|
||||||
//when
|
//when
|
||||||
|
@ -141,7 +141,7 @@ public class MonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveHashCodeBasedOnContent() {
|
void shouldHaveHashCodeBasedOnContent() {
|
||||||
//given
|
//given
|
||||||
final int hashOfOne = Mon.of("one")
|
final int hashOfOne = Mon.of("one")
|
||||||
.hashCode();
|
.hashCode();
|
||||||
|
@ -155,7 +155,7 @@ public class MonTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveEquals() {
|
void shouldHaveEquals() {
|
||||||
//given
|
//given
|
||||||
final Mon<String> one = Mon.of("one");
|
final Mon<String> one = Mon.of("one");
|
||||||
final Mon<String> two = Mon.of("two");
|
final Mon<String> two = Mon.of("two");
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package net.kemitix.mon;
|
package net.kemitix.mon;
|
||||||
|
|
||||||
import org.assertj.core.api.WithAssertions;
|
import org.assertj.core.api.WithAssertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class OptionalMonadTest implements WithAssertions {
|
class OptionalMonadTest implements WithAssertions {
|
||||||
|
|
||||||
private final int v = 1;
|
private final int v = 1;
|
||||||
private final Function<Integer, Optional<Integer>> f = i -> o(i * 2);
|
private final Function<Integer, Optional<Integer>> f = i -> o(i * 2);
|
||||||
|
@ -17,7 +17,7 @@ public class OptionalMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void leftIdentity() {
|
void leftIdentity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
o(v).flatMap(f)
|
o(v).flatMap(f)
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
@ -26,7 +26,7 @@ public class OptionalMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rightIdentity() {
|
void rightIdentity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
o(v).flatMap(x -> o(x))
|
o(v).flatMap(x -> o(x))
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
@ -35,7 +35,7 @@ public class OptionalMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void associativity() {
|
void associativity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
o(v).flatMap(f).flatMap(g)
|
o(v).flatMap(f).flatMap(g)
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
|
|
@ -2,11 +2,11 @@ package net.kemitix.mon;
|
||||||
|
|
||||||
import net.kemitix.mon.result.Result;
|
import net.kemitix.mon.result.Result;
|
||||||
import org.assertj.core.api.WithAssertions;
|
import org.assertj.core.api.WithAssertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class ResultMonadTest implements WithAssertions {
|
class ResultMonadTest implements WithAssertions {
|
||||||
|
|
||||||
private final int v = 1;
|
private final int v = 1;
|
||||||
private final Function<Integer, Result<Integer>> f = i -> r(i * 2);
|
private final Function<Integer, Result<Integer>> f = i -> r(i * 2);
|
||||||
|
@ -17,7 +17,7 @@ public class ResultMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void leftIdentity() {
|
void leftIdentity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
r(v).flatMap(f)
|
r(v).flatMap(f)
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
@ -26,7 +26,7 @@ public class ResultMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rightIdentity() {
|
void rightIdentity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
r(v).flatMap(x -> r(x))
|
r(v).flatMap(x -> r(x))
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
@ -35,7 +35,7 @@ public class ResultMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void associativity() {
|
void associativity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
r(v).flatMap(f).flatMap(g)
|
r(v).flatMap(f).flatMap(g)
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
|
|
@ -7,7 +7,7 @@ import net.kemitix.mon.result.ErrorResultException;
|
||||||
import net.kemitix.mon.result.UnexpectedErrorResultException;
|
import net.kemitix.mon.result.UnexpectedErrorResultException;
|
||||||
import net.kemitix.mon.result.Result;
|
import net.kemitix.mon.result.Result;
|
||||||
import org.assertj.core.api.WithAssertions;
|
import org.assertj.core.api.WithAssertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
@ -15,10 +15,10 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assumptions.assumeThat;
|
import static org.assertj.core.api.Assumptions.assumeThat;
|
||||||
|
|
||||||
public class ResultTest implements WithAssertions {
|
class ResultTest implements WithAssertions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equality() {
|
void equality() {
|
||||||
assertThat(Result.ok(1)).isEqualTo(Result.ok(1));
|
assertThat(Result.ok(1)).isEqualTo(Result.ok(1));
|
||||||
assertThat(Result.ok(1)).isNotEqualTo(Result.ok(2));
|
assertThat(Result.ok(1)).isNotEqualTo(Result.ok(2));
|
||||||
final RuntimeException runtimeException = new RuntimeException();
|
final RuntimeException runtimeException = new RuntimeException();
|
||||||
|
@ -30,12 +30,12 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void successHashCodesAreUnique() {
|
void successHashCodesAreUnique() {
|
||||||
assertThat(Result.ok(1).hashCode()).isNotEqualTo(Result.ok(2).hashCode());
|
assertThat(Result.ok(1).hashCode()).isNotEqualTo(Result.ok(2).hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void errorHashCodesAreUnique() {
|
void errorHashCodesAreUnique() {
|
||||||
// despite having 'equivalent' exceptions, the exceptions are distinct instances, so should be considered unique
|
// despite having 'equivalent' exceptions, the exceptions are distinct instances, so should be considered unique
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception1 = new RuntimeException("message");
|
final RuntimeException exception1 = new RuntimeException("message");
|
||||||
|
@ -46,7 +46,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOk_isOkay() {
|
void whenOk_isOkay() {
|
||||||
//when
|
//when
|
||||||
final Result<String> result = Result.ok("good");
|
final Result<String> result = Result.ok("good");
|
||||||
//then
|
//then
|
||||||
|
@ -54,7 +54,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOkay_isNotError() {
|
void whenOkay_isNotError() {
|
||||||
//when
|
//when
|
||||||
final Result<String> result = Result.ok("good");
|
final Result<String> result = Result.ok("good");
|
||||||
//then
|
//then
|
||||||
|
@ -62,7 +62,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenOkay_matchSuccess() {
|
void whenOkay_matchSuccess() {
|
||||||
//given
|
//given
|
||||||
final Result<String> result = Result.ok("good");
|
final Result<String> result = Result.ok("good");
|
||||||
//then
|
//then
|
||||||
|
@ -73,7 +73,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenError_isError() {
|
void whenError_isError() {
|
||||||
//when
|
//when
|
||||||
final Result<String> result = Result.error(new Exception());
|
final Result<String> result = Result.error(new Exception());
|
||||||
//then
|
//then
|
||||||
|
@ -81,7 +81,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenError_isNotSuccess() {
|
void whenError_isNotSuccess() {
|
||||||
//when
|
//when
|
||||||
final Result<String> result = Result.error(new Exception());
|
final Result<String> result = Result.error(new Exception());
|
||||||
//then
|
//then
|
||||||
|
@ -89,7 +89,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenError_matchError() {
|
void whenError_matchError() {
|
||||||
//given
|
//given
|
||||||
final Result<Object> result = Result.error(new Exception("bad"));
|
final Result<Object> result = Result.error(new Exception("bad"));
|
||||||
//then
|
//then
|
||||||
|
@ -100,7 +100,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenFlatMapToOkay_isOkay() {
|
void okay_whenFlatMapToOkay_isOkay() {
|
||||||
//given
|
//given
|
||||||
final Result<String> result = Result.ok("good");
|
final Result<String> result = Result.ok("good");
|
||||||
//when
|
//when
|
||||||
|
@ -114,7 +114,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenFlatMapToError_isError() {
|
void okay_whenFlatMapToError_isError() {
|
||||||
//given
|
//given
|
||||||
final Result<String> result = Result.ok("good");
|
final Result<String> result = Result.ok("good");
|
||||||
//when
|
//when
|
||||||
|
@ -124,7 +124,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenFlatMapToOkay_isError() {
|
void error_whenFlatMapToOkay_isError() {
|
||||||
//given
|
//given
|
||||||
final Result<String> result = Result.error(new Exception("bad"));
|
final Result<String> result = Result.error(new Exception("bad"));
|
||||||
//when
|
//when
|
||||||
|
@ -134,7 +134,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenFlatMapToError_isError() {
|
void error_whenFlatMapToError_isError() {
|
||||||
//given
|
//given
|
||||||
final Result<String> result = Result.error(new Exception("bad"));
|
final Result<String> result = Result.error(new Exception("bad"));
|
||||||
//when
|
//when
|
||||||
|
@ -144,7 +144,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenMap_isOkay() {
|
void okay_whenMap_isOkay() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> okResult = Result.ok(1);
|
final Result<Integer> okResult = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -158,7 +158,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenMap_isError() {
|
void error_whenMap_isError() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Integer> errorResult = Result.error(exception);
|
final Result<Integer> errorResult = Result.error(exception);
|
||||||
|
@ -173,7 +173,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenMaybe_wherePasses_isOkayJust() {
|
void okay_whenMaybe_wherePasses_isOkayJust() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> okResult = Result.ok(1);
|
final Result<Integer> okResult = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -187,7 +187,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenMaybe_whereFails_isOkayNothing() {
|
void okay_whenMaybe_whereFails_isOkayNothing() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> okResult = Result.ok(1);
|
final Result<Integer> okResult = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -201,7 +201,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenMaybe_wherePasses_isError() {
|
void error_whenMaybe_wherePasses_isError() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Integer> errorResult = Result.error(exception);
|
final Result<Integer> errorResult = Result.error(exception);
|
||||||
|
@ -216,7 +216,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenMaybe_whereFails_isError() {
|
void error_whenMaybe_whereFails_isError() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Integer> errorResult = Result.error(exception);
|
final Result<Integer> errorResult = Result.error(exception);
|
||||||
|
@ -231,7 +231,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void just_whenFromMaybe_isOkay() {
|
void just_whenFromMaybe_isOkay() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Integer> just = Maybe.just(1);
|
final Maybe<Integer> just = Maybe.just(1);
|
||||||
//when
|
//when
|
||||||
|
@ -245,7 +245,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothing_whenFromMaybe_isError() {
|
void nothing_whenFromMaybe_isError() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Object> nothing = Maybe.nothing();
|
final Maybe<Object> nothing = Maybe.nothing();
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
|
@ -260,7 +260,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenToMaybe_isJust() {
|
void okay_whenToMaybe_isJust() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -270,7 +270,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenToMaybe_isNothing() {
|
void error_whenToMaybe_isNothing() {
|
||||||
//given
|
//given
|
||||||
final Result<Object> error = Result.error(new RuntimeException());
|
final Result<Object> error = Result.error(new RuntimeException());
|
||||||
//when
|
//when
|
||||||
|
@ -280,7 +280,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenOrElseThrow_isValue() throws Throwable {
|
void okay_whenOrElseThrow_isValue() throws Throwable {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -290,7 +290,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenOrElseThrow_throws() {
|
void error_whenOrElseThrow_throws() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Integer> error = Result.error(exception);
|
final Result<Integer> error = Result.error(exception);
|
||||||
|
@ -300,7 +300,8 @@ public class ResultTest implements WithAssertions {
|
||||||
.hasCause(exception);
|
.hasCause(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void okay_whenOrElseThrowT_isValue() throws Exception {
|
@Test
|
||||||
|
void okay_whenOrElseThrowT_isValue() throws Exception {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -309,7 +310,7 @@ public class ResultTest implements WithAssertions {
|
||||||
assumeThat(value).isEqualTo(1);
|
assumeThat(value).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void errorT_whenOrElseThrowT_throwsT() {
|
@Test void errorT_whenOrElseThrowT_throwsT() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Object> error = Result.error(exception);
|
final Result<Object> error = Result.error(exception);
|
||||||
|
@ -317,7 +318,8 @@ public class ResultTest implements WithAssertions {
|
||||||
assertThatThrownBy(() -> error.orElseThrow(RuntimeException.class)).isSameAs(exception);
|
assertThatThrownBy(() -> error.orElseThrow(RuntimeException.class)).isSameAs(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void errorR_whenOrElseThrowT_throwsWrappedR() {
|
@Test
|
||||||
|
void errorR_whenOrElseThrowT_throwsWrappedR() {
|
||||||
//given
|
//given
|
||||||
final IOException exception = new IOException();
|
final IOException exception = new IOException();
|
||||||
final Result<Object> error = Result.error(exception);
|
final Result<Object> error = Result.error(exception);
|
||||||
|
@ -327,7 +329,8 @@ public class ResultTest implements WithAssertions {
|
||||||
.hasCause(exception);
|
.hasCause(exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void okay_whenOrElseThrowUnchecked_isValue() {
|
@Test
|
||||||
|
void okay_whenOrElseThrowUnchecked_isValue() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -336,7 +339,8 @@ public class ResultTest implements WithAssertions {
|
||||||
assumeThat(value).isEqualTo(1);
|
assumeThat(value).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void error_whenOrElseThrowUnchecked_throwsWrapped() {
|
@Test
|
||||||
|
void error_whenOrElseThrowUnchecked_throwsWrapped() {
|
||||||
//given
|
//given
|
||||||
final IOException exception = new IOException();
|
final IOException exception = new IOException();
|
||||||
final Result<Object> error = Result.error(exception);
|
final Result<Object> error = Result.error(exception);
|
||||||
|
@ -347,7 +351,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void justOkay_whenInvert_thenOkayJust() {
|
void justOkay_whenInvert_thenOkayJust() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Result<Integer>> justSuccess = Maybe.just(Result.ok(1));
|
final Maybe<Result<Integer>> justSuccess = Maybe.just(Result.ok(1));
|
||||||
//when
|
//when
|
||||||
|
@ -360,7 +364,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void JustError_whenInvert_isError() {
|
void JustError_whenInvert_isError() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Maybe<Result<Object>> justError = Maybe.just(Result.error(exception));
|
final Maybe<Result<Object>> justError = Maybe.just(Result.error(exception));
|
||||||
|
@ -374,7 +378,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nothing_whenInvert_thenOkayNothing() {
|
void nothing_whenInvert_thenOkayNothing() {
|
||||||
//given
|
//given
|
||||||
final Maybe<Result<Integer>> nothing = Maybe.nothing();
|
final Maybe<Result<Integer>> nothing = Maybe.nothing();
|
||||||
//when
|
//when
|
||||||
|
@ -387,7 +391,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void useCase_whenOkay_thenReturnSuccess() {
|
void useCase_whenOkay_thenReturnSuccess() {
|
||||||
//given
|
//given
|
||||||
final UseCase useCase = UseCase.isOkay();
|
final UseCase useCase = UseCase.isOkay();
|
||||||
//when
|
//when
|
||||||
|
@ -400,7 +404,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void useCase_whenFirstReadIsError_thenReturnError() {
|
void useCase_whenFirstReadIsError_thenReturnError() {
|
||||||
//given
|
//given
|
||||||
final UseCase useCase = UseCase.firstReadInvalid();
|
final UseCase useCase = UseCase.firstReadInvalid();
|
||||||
//when
|
//when
|
||||||
|
@ -415,7 +419,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void useCase_whenSecondReadIsError_thenReturnError() {
|
void useCase_whenSecondReadIsError_thenReturnError() {
|
||||||
//given
|
//given
|
||||||
final UseCase useCase = UseCase.secondReadInvalid();
|
final UseCase useCase = UseCase.secondReadInvalid();
|
||||||
//when
|
//when
|
||||||
|
@ -431,7 +435,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_toString() {
|
void okay_toString() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -441,7 +445,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_toString() {
|
void error_toString() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> error = Result.error(new RuntimeException("failed"));
|
final Result<Integer> error = Result.error(new RuntimeException("failed"));
|
||||||
//when
|
//when
|
||||||
|
@ -451,7 +455,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void value_whenResultOf_isOkay() {
|
void value_whenResultOf_isOkay() {
|
||||||
//given
|
//given
|
||||||
final Callable<String> c = () -> "okay";
|
final Callable<String> c = () -> "okay";
|
||||||
//when
|
//when
|
||||||
|
@ -464,7 +468,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void exception_whenResultOf_isError() {
|
void exception_whenResultOf_isError() {
|
||||||
//given
|
//given
|
||||||
final Callable<String> c = () -> {
|
final Callable<String> c = () -> {
|
||||||
throw new IOException();
|
throw new IOException();
|
||||||
|
@ -479,7 +483,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenPeek_isConsumed() {
|
void okay_whenPeek_isConsumed() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> result = Result.ok(1);
|
final Result<Integer> result = Result.ok(1);
|
||||||
final AtomicReference<Integer> consumed = new AtomicReference<>(0);
|
final AtomicReference<Integer> consumed = new AtomicReference<>(0);
|
||||||
|
@ -491,7 +495,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenPeek_isNotConsumed() {
|
void error_whenPeek_isNotConsumed() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> result = Result.error(new RuntimeException());
|
final Result<Integer> result = Result.error(new RuntimeException());
|
||||||
final AtomicReference<Integer> consumed = new AtomicReference<>(0);
|
final AtomicReference<Integer> consumed = new AtomicReference<>(0);
|
||||||
|
@ -503,7 +507,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenOnError_isIgnored() {
|
void okay_whenOnError_isIgnored() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -511,7 +515,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenOnError_isConsumed() {
|
void error_whenOnError_isConsumed() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Integer> error = Result.error(exception);
|
final Result<Integer> error = Result.error(exception);
|
||||||
|
@ -523,7 +527,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenRecover_thenNoChange() {
|
void okay_whenRecover_thenNoChange() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -533,7 +537,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenRecover_isSuccess() {
|
void error_whenRecover_isSuccess() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> error = Result.error(new RuntimeException());
|
final Result<Integer> error = Result.error(new RuntimeException());
|
||||||
//when
|
//when
|
||||||
|
@ -543,7 +547,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenRecover_whereError_isUpdatedError() {
|
void error_whenRecover_whereError_isUpdatedError() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> error = Result.error(new RuntimeException("original"));
|
final Result<Integer> error = Result.error(new RuntimeException("original"));
|
||||||
//when
|
//when
|
||||||
|
@ -553,7 +557,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenAndThen_whereSuccess_isUpdatedSuccess() {
|
void okay_whenAndThen_whereSuccess_isUpdatedSuccess() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -564,7 +568,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenAndThen_whereError_isError() {
|
void okay_whenAndThen_whereError_isError() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
|
@ -578,7 +582,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whereAndThen_whereSuccess_isError() {
|
void error_whereAndThen_whereSuccess_isError() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Object> error = Result.error(exception);
|
final Result<Object> error = Result.error(exception);
|
||||||
|
@ -590,7 +594,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenAndThen_whereError_isOriginalError() {
|
void error_whenAndThen_whereError_isOriginalError() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception1 = new RuntimeException();
|
final RuntimeException exception1 = new RuntimeException();
|
||||||
final Result<Object> error = Result.error(exception1);
|
final Result<Object> error = Result.error(exception1);
|
||||||
|
@ -604,7 +608,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenThenWith_whereOkay_isOriginalSuccess() {
|
void okay_whenThenWith_whereOkay_isOriginalSuccess() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
//when
|
//when
|
||||||
|
@ -616,7 +620,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okay_whenThenWith_whereError_thenError() {
|
void okay_whenThenWith_whereError_thenError() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> ok = Result.ok(1);
|
final Result<Integer> ok = Result.ok(1);
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
|
@ -630,7 +634,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenThenWith_whereOkay_thenOriginalError() {
|
void error_whenThenWith_whereOkay_thenOriginalError() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Integer> error = Result.error(exception);
|
final Result<Integer> error = Result.error(exception);
|
||||||
|
@ -643,7 +647,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenThenWith_whenError_thenOriginalError() {
|
void error_whenThenWith_whenError_thenOriginalError() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Integer> error = Result.error(exception);
|
final Result<Integer> error = Result.error(exception);
|
||||||
|
@ -656,7 +660,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okayJust_whenFlatMapMaybe_whereOkayJust_thenIsOkayJust() {
|
void okayJust_whenFlatMapMaybe_whereOkayJust_thenIsOkayJust() {
|
||||||
//given
|
//given
|
||||||
final Result<Maybe<Integer>> okJust = Result.ok(Maybe.just(1));
|
final Result<Maybe<Integer>> okJust = Result.ok(Maybe.just(1));
|
||||||
//when
|
//when
|
||||||
|
@ -669,7 +673,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okayJust_whenFlatMapMaybe_whereOkayNothing_thenIsOkayNothing() {
|
void okayJust_whenFlatMapMaybe_whereOkayNothing_thenIsOkayNothing() {
|
||||||
//given
|
//given
|
||||||
final Result<Maybe<Integer>> okJust = Result.ok(Maybe.just(1));
|
final Result<Maybe<Integer>> okJust = Result.ok(Maybe.just(1));
|
||||||
//when
|
//when
|
||||||
|
@ -682,7 +686,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okayJust_whenFlatMapMaybe_whereError_thenIsError() {
|
void okayJust_whenFlatMapMaybe_whereError_thenIsError() {
|
||||||
//given
|
//given
|
||||||
final Result<Maybe<Integer>> okJust = Result.ok(Maybe.just(1));
|
final Result<Maybe<Integer>> okJust = Result.ok(Maybe.just(1));
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
|
@ -696,7 +700,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okayNothing_whenFlatMapMaybe_thenDoNotApply() {
|
void okayNothing_whenFlatMapMaybe_thenDoNotApply() {
|
||||||
//given
|
//given
|
||||||
final Result<Maybe<Integer>> okNothing = Result.ok(Maybe.nothing());
|
final Result<Maybe<Integer>> okNothing = Result.ok(Maybe.nothing());
|
||||||
//when
|
//when
|
||||||
|
@ -709,7 +713,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void error_whenFlatMapMaybe_thenDoNotApply() {
|
void error_whenFlatMapMaybe_thenDoNotApply() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Maybe<Integer>> maybeResult = Result.error(exception);
|
final Result<Maybe<Integer>> maybeResult = Result.error(exception);
|
||||||
|
@ -723,7 +727,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okayOkay_whenReduce_thenCombine() {
|
void okayOkay_whenReduce_thenCombine() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> result1 = Result.ok(1);
|
final Result<Integer> result1 = Result.ok(1);
|
||||||
final Result<Integer> result10 = Result.ok(10);
|
final Result<Integer> result10 = Result.ok(10);
|
||||||
|
@ -737,7 +741,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void okayError_whenReduce_thenError() {
|
void okayError_whenReduce_thenError() {
|
||||||
//given
|
//given
|
||||||
final Result<Integer> result1 = Result.ok(1);
|
final Result<Integer> result1 = Result.ok(1);
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
|
@ -752,7 +756,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void errorOkay_whenReduce_thenError() {
|
void errorOkay_whenReduce_thenError() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception = new RuntimeException();
|
final RuntimeException exception = new RuntimeException();
|
||||||
final Result<Integer> result1 = Result.error(exception);
|
final Result<Integer> result1 = Result.error(exception);
|
||||||
|
@ -767,7 +771,7 @@ public class ResultTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void errorError_whenReduce_thenError() {
|
void errorError_whenReduce_thenError() {
|
||||||
//given
|
//given
|
||||||
final RuntimeException exception1 = new RuntimeException();
|
final RuntimeException exception1 = new RuntimeException();
|
||||||
final Result<Integer> result1 = Result.error(exception1);
|
final Result<Integer> result1 = Result.error(exception1);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package net.kemitix.mon;
|
package net.kemitix.mon;
|
||||||
|
|
||||||
import org.assertj.core.api.WithAssertions;
|
import org.assertj.core.api.WithAssertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class TypeAliasMonadTest implements WithAssertions {
|
class TypeAliasMonadTest implements WithAssertions {
|
||||||
|
|
||||||
private final int v = 1;
|
private final int v = 1;
|
||||||
private final Function<Integer, AnAlias<Integer>> f = i -> a(i * 2);
|
private final Function<Integer, AnAlias<Integer>> f = i -> a(i * 2);
|
||||||
|
@ -16,7 +16,7 @@ public class TypeAliasMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void leftIdentity() {
|
void leftIdentity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
a(v).flatMap(f)
|
a(v).flatMap(f)
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
@ -25,7 +25,7 @@ public class TypeAliasMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rightIdentity() {
|
void rightIdentity() {
|
||||||
final AnAlias<Integer> integerAnAlias = a(v).flatMap(x -> a(x));
|
final AnAlias<Integer> integerAnAlias = a(v).flatMap(x -> a(x));
|
||||||
assertThat(
|
assertThat(
|
||||||
integerAnAlias
|
integerAnAlias
|
||||||
|
@ -35,7 +35,7 @@ public class TypeAliasMonadTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void associativity() {
|
void associativity() {
|
||||||
assertThat(
|
assertThat(
|
||||||
a(v).flatMap(f).flatMap(g)
|
a(v).flatMap(f).flatMap(g)
|
||||||
).isEqualTo(
|
).isEqualTo(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package net.kemitix.mon;
|
package net.kemitix.mon;
|
||||||
|
|
||||||
import org.assertj.core.util.Strings;
|
import org.assertj.core.util.Strings;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -9,10 +9,10 @@ import java.util.List;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class TypeAliasTest {
|
class TypeAliasTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateATypeAliasAndGetTheValue() {
|
void shouldCreateATypeAliasAndGetTheValue() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
//when
|
//when
|
||||||
|
@ -27,7 +27,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateATypeAliasWithNestedGenericTypes() {
|
void shouldCreateATypeAliasWithNestedGenericTypes() {
|
||||||
//given
|
//given
|
||||||
final Iterable<String> iterable = Collections.emptyList();
|
final Iterable<String> iterable = Collections.emptyList();
|
||||||
//when
|
//when
|
||||||
|
@ -39,7 +39,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateATypeAliasSubclassAndGetTheValue() {
|
void shouldCreateATypeAliasSubclassAndGetTheValue() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
//when
|
//when
|
||||||
|
@ -49,7 +49,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotBeEqualWhenValueTypesAreDifferent() {
|
void shouldNotBeEqualWhenValueTypesAreDifferent() {
|
||||||
//given
|
//given
|
||||||
final TypeAlias<String> stringTypeAlias = givenTypeAlias("1");
|
final TypeAlias<String> stringTypeAlias = givenTypeAlias("1");
|
||||||
final TypeAlias<Integer> integerTypeAlias = new TypeAlias<Integer>(1) {
|
final TypeAlias<Integer> integerTypeAlias = new TypeAlias<Integer>(1) {
|
||||||
|
@ -59,7 +59,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldBeEqualWhenValuesAreTheSame() {
|
void shouldBeEqualWhenValuesAreTheSame() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
final AnAlias anAlias1 = AnAlias.of(value);
|
final AnAlias anAlias1 = AnAlias.of(value);
|
||||||
|
@ -69,7 +69,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotBeEqualWhenValuesAreNotTheSame() {
|
void shouldNotBeEqualWhenValuesAreNotTheSame() {
|
||||||
//given
|
//given
|
||||||
final AnAlias valueA = AnAlias.of("value a");
|
final AnAlias valueA = AnAlias.of("value a");
|
||||||
final AnAlias valueB = AnAlias.of("value b");
|
final AnAlias valueB = AnAlias.of("value b");
|
||||||
|
@ -78,7 +78,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldBeEqualToRawValue() {
|
void shouldBeEqualToRawValue() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
final AnAlias anAlias = AnAlias.of(value);
|
final AnAlias anAlias = AnAlias.of(value);
|
||||||
|
@ -87,7 +87,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveHashCodeOfValue() {
|
void shouldHaveHashCodeOfValue() {
|
||||||
//given
|
//given
|
||||||
final String value = "value";
|
final String value = "value";
|
||||||
final AnAlias anAlias = AnAlias.of(value);
|
final AnAlias anAlias = AnAlias.of(value);
|
||||||
|
@ -96,7 +96,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveSameToStringAsAliasedType() {
|
void shouldHaveSameToStringAsAliasedType() {
|
||||||
//given
|
//given
|
||||||
final List<Integer> value = Arrays.asList(1, 2, 3);
|
final List<Integer> value = Arrays.asList(1, 2, 3);
|
||||||
//when
|
//when
|
||||||
|
@ -107,7 +107,7 @@ public class TypeAliasTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldMapTypeAlias() {
|
void shouldMapTypeAlias() {
|
||||||
//given
|
//given
|
||||||
final AnAlias anAlias = AnAlias.of("text");
|
final AnAlias anAlias = AnAlias.of("text");
|
||||||
//when
|
//when
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.kemitix.mon.combinator;
|
package net.kemitix.mon.combinator;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -8,10 +8,10 @@ import java.util.function.Function;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class AfterTest {
|
class AfterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canCreateAfterCombinator() {
|
void canCreateAfterCombinator() {
|
||||||
//given
|
//given
|
||||||
final List<String> events = new ArrayList<>();
|
final List<String> events = new ArrayList<>();
|
||||||
final Function<Integer, Integer> squareDecorated =
|
final Function<Integer, Integer> squareDecorated =
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.kemitix.mon.combinator;
|
package net.kemitix.mon.combinator;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -8,10 +8,10 @@ import java.util.function.Function;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class AroundTest {
|
class AroundTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canCreateAnAroundCombinator() {
|
void canCreateAnAroundCombinator() {
|
||||||
//given
|
//given
|
||||||
final List<String> events = new ArrayList<>();
|
final List<String> events = new ArrayList<>();
|
||||||
final Function<Integer, Integer> squareDecorated =
|
final Function<Integer, Integer> squareDecorated =
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.kemitix.mon.combinator;
|
package net.kemitix.mon.combinator;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -8,10 +8,10 @@ import java.util.function.Function;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class BeforeTest {
|
class BeforeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canCreateBeforeCombinator() {
|
void canCreateBeforeCombinator() {
|
||||||
//given
|
//given
|
||||||
final List<String> events = new ArrayList<>();
|
final List<String> events = new ArrayList<>();
|
||||||
final Function<Integer, Integer> squareDecorated =
|
final Function<Integer, Integer> squareDecorated =
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package net.kemitix.mon.lazy;
|
package net.kemitix.mon.lazy;
|
||||||
|
|
||||||
import org.assertj.core.api.WithAssertions;
|
import org.assertj.core.api.WithAssertions;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.rules.Timeout;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
@ -11,13 +9,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class LazySupplierTest implements WithAssertions {
|
class LazySupplierTest implements WithAssertions {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final Timeout timeout = Timeout.seconds(1);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCreateLazyThenSupplierIsNotCalled() {
|
void whenCreateLazyThenSupplierIsNotCalled() {
|
||||||
//given
|
//given
|
||||||
final AtomicBoolean supplierCalled = new AtomicBoolean(false);
|
final AtomicBoolean supplierCalled = new AtomicBoolean(false);
|
||||||
final Supplier<UUID> supplier = () -> {
|
final Supplier<UUID> supplier = () -> {
|
||||||
|
@ -31,7 +26,7 @@ public class LazySupplierTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCreateLazyThenIsEvaluatedIsFalse() {
|
void whenCreateLazyThenIsEvaluatedIsFalse() {
|
||||||
//given
|
//given
|
||||||
final Supplier<UUID> supplier = UUID::randomUUID;
|
final Supplier<UUID> supplier = UUID::randomUUID;
|
||||||
//when
|
//when
|
||||||
|
@ -41,7 +36,7 @@ public class LazySupplierTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenValueThenSupplierIsCalled() {
|
void whenValueThenSupplierIsCalled() {
|
||||||
//given
|
//given
|
||||||
final AtomicBoolean supplierCalled = new AtomicBoolean(false);
|
final AtomicBoolean supplierCalled = new AtomicBoolean(false);
|
||||||
final Supplier<UUID> supplier = () -> {
|
final Supplier<UUID> supplier = () -> {
|
||||||
|
@ -56,7 +51,7 @@ public class LazySupplierTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenValueThenValueIsSameAsSupplier() {
|
void whenValueThenValueIsSameAsSupplier() {
|
||||||
//given
|
//given
|
||||||
final UUID uuid = UUID.randomUUID();
|
final UUID uuid = UUID.randomUUID();
|
||||||
final Supplier<UUID> supplier = () -> uuid;
|
final Supplier<UUID> supplier = () -> uuid;
|
||||||
|
@ -68,7 +63,7 @@ public class LazySupplierTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenValueThenIsEvaluatedIsTrue() {
|
void whenValueThenIsEvaluatedIsTrue() {
|
||||||
//given
|
//given
|
||||||
final Supplier<UUID> supplier = () -> UUID.randomUUID();
|
final Supplier<UUID> supplier = () -> UUID.randomUUID();
|
||||||
final Lazy<UUID> lazy = Lazy.of(supplier);
|
final Lazy<UUID> lazy = Lazy.of(supplier);
|
||||||
|
@ -79,7 +74,7 @@ public class LazySupplierTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenValueCalledTwiceThenSupplierIsNotCalledAgain() {
|
void whenValueCalledTwiceThenSupplierIsNotCalledAgain() {
|
||||||
//given
|
//given
|
||||||
final AtomicInteger supplierCalledCounter = new AtomicInteger(0);
|
final AtomicInteger supplierCalledCounter = new AtomicInteger(0);
|
||||||
final Supplier<UUID> supplier = () -> {
|
final Supplier<UUID> supplier = () -> {
|
||||||
|
@ -95,7 +90,7 @@ public class LazySupplierTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenMapLazyThenSupplierNotCalled() {
|
void whenMapLazyThenSupplierNotCalled() {
|
||||||
//given
|
//given
|
||||||
final UUID uuid = UUID.randomUUID();
|
final UUID uuid = UUID.randomUUID();
|
||||||
final AtomicBoolean supplierCalled = new AtomicBoolean(false);
|
final AtomicBoolean supplierCalled = new AtomicBoolean(false);
|
||||||
|
@ -111,7 +106,7 @@ public class LazySupplierTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenMapLazyValueThenSupplierIsCalled() {
|
void whenMapLazyValueThenSupplierIsCalled() {
|
||||||
//given
|
//given
|
||||||
final UUID uuid = UUID.randomUUID();
|
final UUID uuid = UUID.randomUUID();
|
||||||
final AtomicBoolean supplierCalled = new AtomicBoolean(false);
|
final AtomicBoolean supplierCalled = new AtomicBoolean(false);
|
||||||
|
@ -128,7 +123,7 @@ public class LazySupplierTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenMapLazyValueThenValueIsCorrect() {
|
void whenMapLazyValueThenValueIsCorrect() {
|
||||||
//given
|
//given
|
||||||
final UUID uuid = UUID.randomUUID();
|
final UUID uuid = UUID.randomUUID();
|
||||||
final AtomicBoolean supplierCalled = new AtomicBoolean(false);
|
final AtomicBoolean supplierCalled = new AtomicBoolean(false);
|
||||||
|
@ -145,7 +140,7 @@ public class LazySupplierTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenLazyValueCalledOnTwoThreadsThenSupplierIsOnlyCalledOnce() throws ExecutionException, InterruptedException {
|
void whenLazyValueCalledOnTwoThreadsThenSupplierIsOnlyCalledOnce() throws ExecutionException, InterruptedException {
|
||||||
//given
|
//given
|
||||||
final AtomicInteger supplierCalledCounter = new AtomicInteger(0);
|
final AtomicInteger supplierCalledCounter = new AtomicInteger(0);
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package net.kemitix.mon.tree;
|
package net.kemitix.mon.tree;
|
||||||
|
|
||||||
import org.assertj.core.api.WithAssertions;
|
import org.assertj.core.api.WithAssertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
|
||||||
public class GeneralisedTreeTest implements WithAssertions {
|
class GeneralisedTreeTest implements WithAssertions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canCreateAnEmptyLeaf() {
|
void canCreateAnEmptyLeaf() {
|
||||||
//when
|
//when
|
||||||
final Tree<String> leaf = Tree.leaf(null);
|
final Tree<String> leaf = Tree.leaf(null);
|
||||||
//then
|
//then
|
||||||
|
@ -19,7 +19,7 @@ public class GeneralisedTreeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canCreateANonEmptyLeaf() {
|
void canCreateANonEmptyLeaf() {
|
||||||
//given
|
//given
|
||||||
final String item = "item";
|
final String item = "item";
|
||||||
//when
|
//when
|
||||||
|
@ -29,7 +29,7 @@ public class GeneralisedTreeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyLeafHasCountZero() {
|
void emptyLeafHasCountZero() {
|
||||||
//given
|
//given
|
||||||
final Tree<Object> tree = Tree.leaf(null);
|
final Tree<Object> tree = Tree.leaf(null);
|
||||||
//when
|
//when
|
||||||
|
@ -39,7 +39,7 @@ public class GeneralisedTreeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonEmptyLeafHasCountOne() {
|
void nonEmptyLeafHasCountOne() {
|
||||||
//given
|
//given
|
||||||
final Tree<String> tree = Tree.leaf("value");
|
final Tree<String> tree = Tree.leaf("value");
|
||||||
//when
|
//when
|
||||||
|
@ -49,7 +49,7 @@ public class GeneralisedTreeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canCreateTreeWithSubTrees() {
|
void canCreateTreeWithSubTrees() {
|
||||||
//given
|
//given
|
||||||
final String treeItem = "tree";
|
final String treeItem = "tree";
|
||||||
final String leafItem = "leaf";
|
final String leafItem = "leaf";
|
||||||
|
@ -60,7 +60,7 @@ public class GeneralisedTreeTest implements WithAssertions {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canMapNestedTrees() {
|
void canMapNestedTrees() {
|
||||||
//given
|
//given
|
||||||
final UUID uid1 = UUID.randomUUID();
|
final UUID uid1 = UUID.randomUUID();
|
||||||
final UUID uid2 = UUID.randomUUID();
|
final UUID uid2 = UUID.randomUUID();
|
||||||
|
|
Loading…
Reference in a new issue