diff --git a/common-testing/src/test/java/io/carbynestack/common/CsFailureReasonTest.java b/common-testing/src/test/java/io/carbynestack/common/CsFailureReasonTest.java index b203f8b..81c7f42 100644 --- a/common-testing/src/test/java/io/carbynestack/common/CsFailureReasonTest.java +++ b/common-testing/src/test/java/io/carbynestack/common/CsFailureReasonTest.java @@ -12,7 +12,7 @@ class CsFailureReasonTest { @Test - void toFailure() { + void whenCallingToFailureOnCsFailureReasonThenReturnReasonWrappedInFailureInstance() { assertThat(new TestReason().toFailure()).isFailure(); } diff --git a/common-testing/src/test/java/io/carbynestack/common/result/FailureTest.java b/common-testing/src/test/java/io/carbynestack/common/result/FailureTest.java index 9a14c6f..384e194 100644 --- a/common-testing/src/test/java/io/carbynestack/common/result/FailureTest.java +++ b/common-testing/src/test/java/io/carbynestack/common/result/FailureTest.java @@ -29,7 +29,7 @@ class FailureTest { private final Result result = new Failure<>(reason); @Test - void isFailure() { + void givenFailureResultWhenCallingIsFailureOnResultThenReturnTrue() { assertThat(result).isInstanceOf(Result.class); assertThat(result.isFailure()).isTrue(); assertThat(result).isFailure(); @@ -37,177 +37,178 @@ void isFailure() { } @Test - void reason() { + void givenFailureResultWhenCallingReasonOnResultThenReturnExpectedReason() { assertThat(result).hasReason(reason); } @Test - void map() { + void givenFailureResultWhenCallingMapOnResultThenReturnMappedResult() { assertThat(result.map(v -> v * 2)).hasReason(reason); } @Test - void mapNullPointerException() { + void givenMappingFunctionIsNullWhenCallingMapOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.map(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void mapAndTransformType() { + void givenFailureResultWhenCallingMapOnResultThenReturnMappedResultWithTransformedType() { assertThat(result.map(v -> String.format("%s * 2 -> %s", v, v * 2))) .hasReason(reason); } @Test - void mapFailure() { + void givenFailureResultWhenCallingMapFailureOnResultThenReturnResultWithMappedFailureReason() { assertThat(result.mapFailure(r -> r * 2)).hasReason(reason * 2); } @Test - void mapFailureNullPointerException() { + void givenMappingFunctionIsNullWhenCallingMapFailureOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.mapFailure(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void tryMap() { + void givenFailureResultWhenCallingTryMapOnResultThenReturnMappedResult() { assertThat(result.tryMap(v -> v * 2, reason * 2)).hasReason(reason); } @Test - void tryMapNullPointerException() { + void givenMappingFunctionsIsNullWhenCallingTryMapOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.tryMap(null, reason * 2)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void mapFailureAndTransformType() { + void givenFailureResultWhenCallingMapFailureOnResultThenReturnResultWithMappedFailureReasonAndTransformedType() { assertThat(result.mapFailure(r -> String.format("%s * 2 -> %s", r, r * 2))) .hasReason("21 * 2 -> 42"); } @Test - void tryMapAndTransformType() { + void givenFailureResultWhenCallingTryMapOnResultThenReturnMappedResultAndTransformedType() { assertThat(result.tryMap(v -> String.format("%s * 2 -> %s", v, v * 2), reason * 2)).hasReason(reason); } @Test - void tryMapWithException() { + void givenThrowingMappingFunctionWhenCallingTryMapOnResultThenReturnFailureResult() { assertThat(result.tryMap(v -> { throw new IOException("-11"); }, reason * 2)).hasReason(reason); } @Test - void peek() { + void givenFailureResultWhenCallingPeekOnResultThenKeepSuccessValueOutput() { AtomicInteger output = new AtomicInteger(-1); result.peek(output::set); assertThat(output).hasValue(-1); } @Test - void peekNullPointerException() { + void givenOutputFunctionIsNullWhenCallingPeekOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.peek(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void tryPeek() { + void givenFailureResultWhenCallingTryPeekOnResultThenKeepSuccessValueOutput() { AtomicInteger output = new AtomicInteger(-1); result.tryPeek(output::set, reason * 2); assertThat(output).hasValue(-1); } @Test - void tryPeekWithException() { + void givenThrowingOutputFunctionWhenCallingTryPeekOnResultThenReturnFailureResult() { assertThat(result.tryPeek(v -> { throw new IOException("-11"); }, reason * 2)).hasReason(reason); } @Test - void tryPeekNullPointerException() { + void givenOutputFunctionIsNullWhenCallingTryPeekOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.tryPeek(null, reason * 2)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void recover() { + void givenFailureResultWhenCallingRecoverOnResultThenReturnSuccessResult() { assertThat(result.recover(r -> r * 2)).hasValue(42); } @Test - void recoverNullPointerException() { + void givenRecoveryFunctionIsNullWhenCallingRecoverOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.recover(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void flatMap() { + void givenFailureResultWhenCallingFlatMapOnResultThenReturnCurrentFailureResult() { assertThat(result.flatMap(v -> new Success<>(v * 2))).hasReason(reason); assertThat(result.flatMap(v -> new Failure<>(v * 2))).hasReason(reason); } @Test - void flatMapNullPointerException() { + void givenMappingFunctionWhenCallingFlatMapOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.flatMap(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void unsafeFlattenNestedFailure() { + void givenOutermostNestedFailureResultWhenCallingUnsafeFlattenOnResultThenReturnFlattenedResult() { int reason = 21; Result> res = new Failure<>(new Failure<>(reason)); assertThat(res.unsafeFlatten()).hasReason(reason); } @Test - void unsafeFlattenSuccessNestedInFailure() { + void givenOutermostFailureResultWithNestedSuccessResultWhenCallingUnsafeFlattenOnResultThenReturnFlattenedResult() { int value = 12; Result> res = new Failure<>(new Success<>(value)); assertThat(res.unsafeFlatten()).hasValue(value); } @Test - void unsafeFlattenNonNestedFailure() { + void givenNonNestedFailureResultWhenCallingUnsafeFlattenOnResultThenReturnNonNestedFailureResult() { int reason = 21; Result res = new Failure<>(reason); assertThat(res.unsafeFlatten()).hasReason(reason); } @Test - void fold() { + void givenFailureResultWhenCallingFoldOnResultThenReturnExpectedValue() { assertThat(result.fold(v -> v * 2, r -> r + 9)).isEqualTo(30); } @ParameterizedTest @NullableParamSource("FOLD") - void foldNullPointerException(Function successFunction, - Function failureFunction) { + void givenFoldingFunctionsAreNullWhenCallingFoldOnResultThenThrowNullPointerException( + Function successFunction, + Function failureFunction) { assertThatThrownBy(() -> result.fold(successFunction, failureFunction)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void filter() { + void givenFailureResultWhenCallingFilterOnResultThenReturnCurrentFailureResult() { assertThat(result.filter(Predicate.isEqual(12), 22)).hasReason(reason); } @Test - void filterNullPointerException() { + void givenPredicateIsNullWhenCallingFilterOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.filter(null, null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void or() { + void givenFailureResultWhenCallingOrOnResultThenReturnSuccessResult() { int value = 12; assertThat(result.or(() -> new Success<>(value))).hasValue(value); } @Test - void orNullPointerException() { + void givenResultSupplierIsNullWhenCallingOrOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.or(null)) .isExactlyInstanceOf(NullPointerException.class); assertThatThrownBy(() -> result.or(() -> null)) @@ -215,17 +216,17 @@ void orNullPointerException() { } @Test - void swap() { + void givenFailureResultWhenCallingSwapOnResultThenReturnSuccessResult() { assertThat(result.swap()).hasValue(reason); } @Test - void toOptional() { + void givenFailureResultWhenCallingToOptionalOnResultThenReturnEmptyOptional() { assertThat(result.toOptional()).isEmpty(); } @Test - void stream() { + void givenFailureResultWhenCallingStreamOnResultThenReturnEmptyStream() { assertThat(result.stream()).isEmpty(); } } diff --git a/common-testing/src/test/java/io/carbynestack/common/result/ResultTest.java b/common-testing/src/test/java/io/carbynestack/common/result/ResultTest.java index 076adeb..cfce15b 100644 --- a/common-testing/src/test/java/io/carbynestack/common/result/ResultTest.java +++ b/common-testing/src/test/java/io/carbynestack/common/result/ResultTest.java @@ -29,14 +29,14 @@ class ResultTest { () -> 12, Collections.emptyMap()); @Test - void of() { + void givenSuccessValueWhenCallingOfOnResultThenReturnSuccessResult() { int value = 12; Result result = Result.of(() -> value, "some"); assertThat(result).hasValue(value); } @Test - void ofThrowsToFailure() { + void givenThrowingValueSupplierWhenCallingOfOnResultThenReturnFailureResult() { String reason = "some"; Result result = Result.of(() -> { throw new IOException(); @@ -46,20 +46,21 @@ void ofThrowsToFailure() { @ParameterizedTest @NullableParamSource("OF") - void ofNullPointerException(AnyThrowingSupplier supplier, String reason) { + void givenValueSuppliersAndReasonsAreNullWhenCallingOfOnResultThenThrowNullPointerException( + AnyThrowingSupplier supplier, String reason) { assertThatThrownBy(() -> Result.of(supplier, reason)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void ofWithCsFailureReason() { + void givenFailureReasonTypeWhenCallingOfOnResultThenReturnSuccessResult() { int value = 12; Result result = Result.of(() -> value); assertThat(result).hasValue(value); } @Test - void ofWithCsFailureReasonToFailure() { + void givenThrowingValueSupplierWithFailureReasonTypeWhenCallingOfOnResultThenReturnFailureResult() { FailureException reason = new FailureException(); Result result = Result.of(() -> { throw reason; @@ -68,13 +69,13 @@ void ofWithCsFailureReasonToFailure() { } @Test - void ofWithCsFailureReasonNullPointerException() { + void givenValueSupplierIsNullWhenCallingOfOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> Result.of(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void ofWithMappedExceptions() { + void givenEmptyExceptionMappingWhenCallingOfOnResultThenReturnSuccessResult() { int value = 12; Result result = Result.of(() -> value, Collections.emptyMap(), new FailureException()); @@ -82,7 +83,7 @@ void ofWithMappedExceptions() { } @Test - void ofWithNoMappedExceptions() { + void givenThrowingValueSupplierAndEmptyExceptionMappingWhenCallingOfOnResultThenReturnFailureResult() { FailureException exception = new FailureException(); Result result = Result.of(() -> { throw new IOException(); @@ -91,7 +92,7 @@ void ofWithNoMappedExceptions() { } @Test - void ofWithMappedExactExceptionToFailure() { + void givenThrowingValueSupplierAndExactExceptionMappingWhenCallingOfOnResultThenReturnMappedFailureResult() { FailureException reason = new FailureException("IO", "IOException"); Map, FailureException> reasons = new HashMap<>(); reasons.put(IOException.class, reason); @@ -102,7 +103,7 @@ void ofWithMappedExactExceptionToFailure() { } @Test - void ofWithMappedCauseExceptionToFailure() { + void givenThrowingValueSupplierAndCauseExceptionMappingWhenCallingOfOnResultThenReturnMappedFailureResult() { FailureException reason = new FailureException("IO", "IOException"); Map, FailureException> reasons = new HashMap<>(); reasons.put(IllegalArgumentException.class, reason); @@ -113,7 +114,7 @@ void ofWithMappedCauseExceptionToFailure() { } @Test - void ofWithMappedAssignableExceptionToFailure() { + void givenThrowingValueSupplierAndAssignableExceptionMappingWhenCallingOfOnResultThenReturnMappedFailureResult() { FailureException reason = new FailureException("IO", "IOException"); Map, FailureException> reasons = new HashMap<>(); reasons.put(Throwable.class, reason); @@ -124,7 +125,7 @@ void ofWithMappedAssignableExceptionToFailure() { } @Test - void ofWithMappedExceptionsMissingEntry() { + void givenThrowingValueSupplierAndMissingExceptionMappingEntryWhenCallingOfOnResultThenReturnMappedFailureResult() { FailureException exception = new FailureException(); Map, FailureException> reasons = new HashMap<>(); reasons.put(NumberFormatException.class, new FailureException("IO", "IOException")); @@ -136,7 +137,8 @@ void ofWithMappedExceptionsMissingEntry() { @ParameterizedTest @NullableParamSource("OF_WITH_MAPPED_EXCEPTIONS") - void ofWithMappedExceptionsNullPointerException(AnyThrowingSupplier supplier, Map, FailureException> reasons) { + void givenValueSuppliersAndExceptionMappingsAreNullWhenCallingOfOnResultThenThrowNullPointerException( + AnyThrowingSupplier supplier, Map, FailureException> reasons) { assertThatThrownBy(() -> Result.of(supplier, reasons, new FailureException())); } diff --git a/common-testing/src/test/java/io/carbynestack/common/result/SuccessTest.java b/common-testing/src/test/java/io/carbynestack/common/result/SuccessTest.java index b2cb25f..7bbdc7a 100644 --- a/common-testing/src/test/java/io/carbynestack/common/result/SuccessTest.java +++ b/common-testing/src/test/java/io/carbynestack/common/result/SuccessTest.java @@ -30,7 +30,7 @@ class SuccessTest { private final Result result = new Success<>(value); @Test - void isSuccess() { + void givenSuccessResultWhenCallingIsSuccessOnResultThenReturnTrue() { assertThat(result).isInstanceOf(Result.class); assertThat(result.isSuccess()).isTrue(); assertThat(result).isSuccess(); @@ -38,63 +38,63 @@ void isSuccess() { } @Test - void value() { + void givenSuccessResultWhenCallingValueOnResultThenReturnExpectedValue() { assertThat(result).hasValue(value); } @Test - void map() { + void givenSuccessResultWhenCallingMapOnResultThenReturnMappedResult() { assertThat(result.map(v -> v * 2)).hasValue(24); } @Test - void mapNullPointerException() { + void givenMappingFunctionIsNullWhenCallingMapOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.map(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void mapAndTransformType() { + void givenSuccessResultWhenCallingMapOnResultThenReturnMappedResultWithTransformedType() { assertThat(result.map(v -> String.format("%s * 2 -> %s", v, v * 2))) .hasValue("12 * 2 -> 24"); } @Test - void mapFailure() { + void givenSuccessResultWhenCallingMapFailureOnResultThenReturnResultWithMappedFailureReason() { assertThat(result.mapFailure(r -> r * 2)).hasValue(value); } @Test - void mapFailureNullPointerException() { + void givenMappingFunctionIsNullWhenCallingMapFailureOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.mapFailure(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void tryMap() { + void givenSuccessResultWhenCallingTryMapOnResultThenReturnMappedResult() { assertThat(result.tryMap(v -> v * 2, -11)).hasValue(24); } @Test - void tryMapNullPointerException() { + void givenMappingFunctionsIsNullWhenCallingTryMapOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.tryMap(null, -11)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void mapFailureAndTransformType() { + void givenSuccessResultWhenCallingMapFailureOnResultThenReturnResultWithMappedFailureReasonAndTransformedType() { assertThat(result.mapFailure(r -> String.format("%s * 2 -> %s", r, r * 2))) .hasValue(value); } @Test - void tryMapAndTransformType() { + void givenSuccessResultWhenCallingTryMapOnResultThenReturnMappedResultAndTransformedType() { assertThat(result.tryMap(v -> String.format("%s * 2 -> %s", v, v * 2), -11)).hasValue("12 * 2 -> 24"); } @Test - void tryMapWithException() { + void givenThrowingMappingFunctionWhenCallingTryMapOnResultThenReturnFailureResult() { int reason = -11; assertThat(result.tryMap(v -> { throw new IOException("-11"); @@ -102,27 +102,27 @@ void tryMapWithException() { } @Test - void peek() { + void givenSuccessResultWhenCallingPeekOnResultThenOutputSuccessValue() { AtomicInteger output = new AtomicInteger(-1); result.peek(output::set); assertThat(output).hasValue(value); } @Test - void peekNullPointerException() { + void givenOutputFunctionIsNullWhenCallingPeekOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.peek(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void tryPeek() { + void givenSuccessResultWhenCallingTryPeekOnResultThenOutputSuccessValue() { AtomicInteger output = new AtomicInteger(-1); result.tryPeek(output::set, -11); assertThat(output).hasValue(value); } @Test - void tryPeekWithException() { + void givenThrowingOutputFunctionWhenCallingTryPeekOnResultThenReturnFailureResult() { int reason = -11; assertThat(result.tryPeek(v -> { throw new IOException("-11"); @@ -130,30 +130,30 @@ void tryPeekWithException() { } @Test - void tryPeekNullPointerException() { + void givenOutputFunctionIsNullWhenCallingTryPeekOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.tryPeek(null, -11)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void recover() { + void givenSuccessResultWhenCallingRecoverOnResultThenReturnCurrentResult() { assertThat(result.recover(identity())).hasValue(value); } @Test - void recoverNullPointerException() { + void givenRecoveryFunctionIsNullWhenCallingRecoverOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.recover(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void flatMap() { + void givenSuccessResultWhenCallingFlatMapOnResultThenReturnMappedResult() { assertThat(result.flatMap(v -> new Success<>(v * 2))).hasValue(24); assertThat(result.flatMap(v -> new Failure<>(v + 9))).hasReason(21); } @Test - void flatMapNullPointerException() { + void givenMappingFunctionWhenCallingFlatMapOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.flatMap(null)) .isExactlyInstanceOf(NullPointerException.class); assertThatThrownBy(() -> result.flatMap(v -> null)) @@ -161,74 +161,75 @@ void flatMapNullPointerException() { } @Test - void unsafeFlattenNestedSuccess() { + void givenOutermostNestedSuccessResultWhenCallingUnsafeFlattenOnResultThenReturnFlattenedResult() { int value = 12; Result, Integer> res = new Success<>(new Success<>(value)); assertThat(res.unsafeFlatten()).hasValue(value); } @Test - void unsafeFlattenFailureNestedInSuccess() { + void givenOutermostSuccessResultWithNestedFailureResultWhenCallingUnsafeFlattenOnResultThenReturnFlattenedResult() { int reason = 21; Result, Integer> res = new Success<>(new Failure<>(reason)); assertThat(res.unsafeFlatten()).hasReason(reason); } @Test - void unsafeFlattenNonNestedSuccess() { + void givenNonNestedSuccessResultWhenCallingUnsafeFlattenOnResultThenReturnNonNestedSuccessResult() { int value = 12; Result res = new Success<>(value); assertThat(res.unsafeFlatten()).hasValue(value); } @Test - void fold() { + void givenSuccessResultWhenCallingFoldOnResultThenReturnExpectedValue() { assertThat(result.fold(v -> v * 2, r -> r + 9)).isEqualTo(24); } @ParameterizedTest @NullableParamSource("FOLD") - void foldNullPointerException(Function successFunction, - Function failureFunction) { + void givenFoldingFunctionsAreNullWhenCallingFoldOnResultThenThrowNullPointerException( + Function successFunction, + Function failureFunction) { assertThatThrownBy(() -> result.fold(successFunction, failureFunction)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void filter() { + void givenSuccessResultWhenCallingFilterOnResultThenReturnFilteredResult() { assertThat(result.filter(Predicate.isEqual(value), 21)).hasValue(value); assertThat(result.filter(v -> !Objects.equals(v, value), 21)).hasReason(21); } @Test - void filterNullPointerException() { + void givenPredicateIsNullWhenCallingFilterOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.filter(null, null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void or() { + void givenSuccessResultWhenCallingOrOnResultThenReturnCurrentSuccessResult() { assertThat(result.or(() -> new Success<>(24))).hasValue(value); } @Test - void orNullPointerException() { + void givenResultSupplierIsNullWhenCallingOrOnResultThenThrowNullPointerException() { assertThatThrownBy(() -> result.or(null)) .isExactlyInstanceOf(NullPointerException.class); } @Test - void swap() { + void givenSuccessResultWhenCallingSwapOnResultThenReturnFailureResult() { assertThat(result.swap()).hasReason(value); } @Test - void toOptional() { + void givenSuccessResultWhenCallingToOptionalOnResultThenReturnOptionalWithSuccessValue() { assertThat(result.toOptional()).hasValue(value); } @Test - void stream() { + void givenSuccessResultWhenCallingStreamOnResultThenReturnStreamContainingSuccessValue() { assertThat(result.stream()).containsExactly(value); } } diff --git a/common-testing/src/test/java/io/carbynestack/testing/blankstring/BlankStringTest.java b/common-testing/src/test/java/io/carbynestack/testing/blankstring/BlankStringTest.java index 3633a34..7241cd7 100644 --- a/common-testing/src/test/java/io/carbynestack/testing/blankstring/BlankStringTest.java +++ b/common-testing/src/test/java/io/carbynestack/testing/blankstring/BlankStringTest.java @@ -13,7 +13,7 @@ class BlankStringTest { @ParameterizedTest @EmptyOrBlankStringSource - void verify(String blank) { + void givenEmptyOrBlankStringWhenCallingIsBlankOnStringArgumentThenVerifyStringProperty(String blank) { assertThat(blank).isBlank(); } } diff --git a/common-testing/src/test/java/io/carbynestack/testing/result/ResultAssertTest.java b/common-testing/src/test/java/io/carbynestack/testing/result/ResultAssertTest.java index 99bfb6b..1e84ad9 100644 --- a/common-testing/src/test/java/io/carbynestack/testing/result/ResultAssertTest.java +++ b/common-testing/src/test/java/io/carbynestack/testing/result/ResultAssertTest.java @@ -24,7 +24,7 @@ class ResultAssertTest { private final Result failure = new Failure<>(reason); @Test - void isSuccess() { + void givenSuccessAndFailureResultsWhenCallingIsSuccessOnResultAssertThenVerifyAssertion() { assertThat(success).isSuccess(); assertThatThrownBy(() -> assertThat(failure).isSuccess()) .isExactlyInstanceOf(AssertionError.class) @@ -32,7 +32,7 @@ void isSuccess() { } @Test - void isFailure() { + void givenSuccessAndFailureResultsWhenCallingIsFailureOnResultAssertThenVerifyAssertion() { assertThat(failure).isFailure(); assertThatThrownBy(() -> assertThat(success).isFailure()) .isExactlyInstanceOf(AssertionError.class) @@ -40,7 +40,7 @@ void isFailure() { } @Test - void hasValue() { + void givenSuccessAndFailureResultsWhenCallingHasValueOnResultAssertThenVerifyAssertion() { assertThat(success).hasValue(value); assertThatThrownBy(() -> assertThat(failure).hasValue(value)) .isExactlyInstanceOf(AssertionError.class) @@ -51,28 +51,28 @@ void hasValue() { } @Test - void hasStringValue() { + void givenSuccessAndFailureResultsWhenCallingHasStringValueOnResultAssertThenVerifyAssertion() { assertThatThrownBy(() -> assertThat(new Success<>(some)).hasValue(none)) .isExactlyInstanceOf(AssertionFailedError.class) .hasMessage("Expecting result success value to equal '%s' but was: '%s'", none, some); } @Test - void hasStringValueWithSingleQuotes() { + void givenSuccessAndFailureResultsWhenCallingHasStringValueWithSingleQuotesOnResultAssertThenVerifyAssertion() { assertThatThrownBy(() -> assertThat(new Success<>("'first'")).hasValue("second")) .isExactlyInstanceOf(AssertionFailedError.class) .hasMessage("Expecting result success value to equal 'second' but was: '%s'", "'first'"); } @Test - void hasStringValueWithLineBreaks() { + void givenSuccessAndFailureResultsWhenCallingHasStringValueWithLineBreaksOnResultAssertThenVerifyAssertion() { assertThatThrownBy(() -> assertThat(new Success<>("first\nsecond")).hasValue("third")) .isExactlyInstanceOf(AssertionFailedError.class) .hasMessage("Expecting result success value to equal 'third' but was: '%s'", "first\\nsecond"); } @Test - void hasReason() { + void givenSuccessAndFailureResultsWhenCallingHasReasonOnResultAssertThenVerifyAssertion() { assertThat(failure).hasReason(reason); assertThatThrownBy(() -> assertThat(success).hasReason(reason)) .isExactlyInstanceOf(AssertionError.class) @@ -83,21 +83,21 @@ void hasReason() { } @Test - void hasStringReason() { + void givenSuccessAndFailureResultsWhenCallingHasStringReasonOnResultAssertThenVerifyAssertion() { assertThatThrownBy(() -> assertThat(new Failure<>(some)).hasReason(none)) .isExactlyInstanceOf(AssertionFailedError.class) .hasMessage("Expecting result failure reason to equal '%s' but was: '%s'", none, some); } @Test - void hasStringReasonWithSingleQuotes() { + void givenSuccessAndFailureResultsWhenCallingHasStringReasonWithSingleQuotesOnResultAssertThenVerifyAssertion() { assertThatThrownBy(() -> assertThat(new Failure<>("'first'")).hasReason("second")) .isExactlyInstanceOf(AssertionFailedError.class) .hasMessage("Expecting result failure reason to equal 'second' but was: '%s'", "'first'"); } @Test - void hasStringReasonWithLineBreaks() { + void givenSuccessAndFailureResultsWhenCallingHasStringReasonWithLineBreaksOnResultAssertThenVerifyAssertion() { assertThatThrownBy(() -> assertThat(new Failure<>("first\nsecond")).hasReason("third")) .isExactlyInstanceOf(AssertionFailedError.class) .hasMessage("Expecting result failure reason to equal 'third' but was: '%s'", "first\\nsecond"); diff --git a/common-types/src/test/java/io/carbynestack/common/CsFailureReasonTest.java b/common-types/src/test/java/io/carbynestack/common/CsFailureReasonTest.java index 1ff2f64..e337bdb 100644 --- a/common-types/src/test/java/io/carbynestack/common/CsFailureReasonTest.java +++ b/common-types/src/test/java/io/carbynestack/common/CsFailureReasonTest.java @@ -16,22 +16,22 @@ class CsFailureReasonTest { private final CsFailureReason reason = new TestReason(SYNOPSIS); @Test - void description() { + void whenCallingDescriptionOnCsFailureReasonThenReturnExpectedDescription() { assertThat(reason.description()).isEqualTo(SYNOPSIS); } @Test - void stackTrace() { + void whenCallingStackTraceOnCsFailureReasonThenReturnExpectedStackTrace() { assertThat(reason.stackTrace()).isEmpty(); } @Test - void reportIssue() { + void whenCallingReportIssueOnCsFailureReasonThenReturnExpectedReportIssue() { assertThat(reason.reportIssue()).isFalse(); } @Test - void toFailure() { + void whenCallingToFailureOnCsFailureReasonThenReturnReasonWrappedInFailureInstance() { assertThat(new TestReason("synopsis").toFailure()).isExactlyInstanceOf(Failure.class); } diff --git a/common-types/src/test/java/io/carbynestack/common/CsFailureThrowableTest.java b/common-types/src/test/java/io/carbynestack/common/CsFailureThrowableTest.java index fce0294..9f19bd8 100644 --- a/common-types/src/test/java/io/carbynestack/common/CsFailureThrowableTest.java +++ b/common-types/src/test/java/io/carbynestack/common/CsFailureThrowableTest.java @@ -12,17 +12,17 @@ class CsFailureThrowableTest { @Test - void throwableSynopsis() { + void whenCallingSynopsisOnCsFailureThrowableThenReturnExpectedSynopsis() { assertThat(new SomeThrowable().synopsis()).isEqualTo("Some message."); } @Test - void nonThrowableSynopsis() { + void givenNonThrowableWhenCallingSynopsisOnCsFailureThrowableThenReturnExpectedSynopsis() { assertThat(new NonThrowable().synopsis()).isEqualTo("Throwable NonThrowable[] has been caught."); } @Test - void throwableStackTrace() { + void whenCallingStackTraceOnCsFailureThrowableThenReturnThrowableStackTrace() { try { throw new SomeThrowable(); } catch (SomeThrowable throwable) { @@ -31,7 +31,7 @@ void throwableStackTrace() { } @Test - void nonThrowableStackTrace() { + void givenNonThrowableWhenCallingStackTraceOnCsFailureThrowableThenReturnEmptyStackTraceOptional() { assertThat(new NonThrowable().stackTrace()).isEmpty(); } diff --git a/common-types/src/test/java/io/carbynestack/common/UnexpectedTest.java b/common-types/src/test/java/io/carbynestack/common/UnexpectedTest.java index 2b45e82..5670df3 100644 --- a/common-types/src/test/java/io/carbynestack/common/UnexpectedTest.java +++ b/common-types/src/test/java/io/carbynestack/common/UnexpectedTest.java @@ -22,22 +22,22 @@ void constructor() { } @Test - void synopsis() { + void givenUnexpectedWithThrowableWhenCallingSynopsisOnUnexpectedThenReturnExpectedSynopsis() { assertThat(unknown.synopsis()).isEqualTo("An unknown exception has occurred."); } @Test - void description() { + void givenUnexpectedWithThrowableWhenCallingDescriptionOnUnexpectedThenReturnExpectedDescription() { assertThat(unknown.description()).isEqualTo("test"); } @Test - void stackTrace() { + void givenUnexpectedWithThrowableWhenCallingStackTraceOnUnexpectedThenReturnExpectedStackTrace() { assertThat(unknown.stackTrace()).isNotEmpty(); } @Test - void reportIssue() { + void givenUnexpectedWithThrowableWhenCallingReportIssueOnUnexpectedThenReturnExpectedReportIssue() { assertThat(unknown.reportIssue()).isTrue(); } } diff --git a/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingConsumerTest.java b/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingConsumerTest.java index 9fb5c68..870c4c0 100644 --- a/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingConsumerTest.java +++ b/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingConsumerTest.java @@ -16,7 +16,7 @@ class AnyThrowingConsumerTest { @Test - void accept() throws Throwable { + void givenNonThrowingComputationWhenCallingAcceptOnAnyThrowingConsumerThenSuccessfullyExecuteComputation() throws Throwable { var value = 12; var output = new AtomicInteger(-1); AnyThrowingConsumer consumer = output::set; @@ -25,7 +25,7 @@ void accept() throws Throwable { } @Test - void acceptThrowsException() { + void givenIOExceptionThrowingComputationWhenCallingAcceptOnAnyThrowingConsumerThenThrowIOException() { AnyThrowingConsumer consumer = v -> { throw new IOException(); }; diff --git a/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingFunctionTest.java b/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingFunctionTest.java index 6a4ea97..961f5a3 100644 --- a/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingFunctionTest.java +++ b/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingFunctionTest.java @@ -15,14 +15,14 @@ class AnyThrowingFunctionTest { @Test - void apply() throws Throwable { + void givenNonThrowingIdentityFunctionWhenCallingApplyOnAnyThrowingFunctionThenReturnExpectedComputationResult() throws Throwable { var value = 12; AnyThrowingFunction function = v -> v; assertThat(function.apply(value)).isEqualTo(value); } @Test - void applyThrowsException() { + void givenIOExceptionThrowingComputationWhenCallingApplyOnAnyThrowingFunctionThenThrowIOException() { AnyThrowingFunction function = v -> { throw new IOException(); }; diff --git a/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingSupplierTest.java b/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingSupplierTest.java index 08a07e9..e6883bf 100644 --- a/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingSupplierTest.java +++ b/common-types/src/test/java/io/carbynestack/common/function/AnyThrowingSupplierTest.java @@ -15,14 +15,14 @@ class AnyThrowingSupplierTest { @Test - void get() throws Throwable { + void givenNonThrowingComputationWhenCallingGetOnAnyThrowingSupplierThenSuccessfullyExecuteComputation() throws Throwable { var value = 12; AnyThrowingSupplier supplier = () -> value; assertThat(supplier.get()).isEqualTo(value); } @Test - void getThrowsException() { + void givenIOExceptionThrowingComputationWhenCallingGetOnAnyThrowingSupplierThenThrowIOException() { AnyThrowingSupplier supplier = () -> { throw new IOException(); }; diff --git a/common-types/src/test/java/io/carbynestack/common/function/ThrowingConsumerTest.java b/common-types/src/test/java/io/carbynestack/common/function/ThrowingConsumerTest.java index 529f89f..19f5b4d 100644 --- a/common-types/src/test/java/io/carbynestack/common/function/ThrowingConsumerTest.java +++ b/common-types/src/test/java/io/carbynestack/common/function/ThrowingConsumerTest.java @@ -16,7 +16,7 @@ class ThrowingConsumerTest { @Test - void accept() { + void givenNonThrowingComputationWhenCallingAcceptOnThrowingConsumerThenSuccessfullyExecuteComputation() { var value = 12; var output = new AtomicInteger(-1); ThrowingConsumer consumer = output::set; @@ -25,7 +25,7 @@ void accept() { } @Test - void acceptCheckedException() throws IOException { + void givenNonThrowingComputationWithCheckedExceptionWhenCallingAcceptOnThrowingConsumerThenSuccessfullyExecuteComputation() throws IOException { var value = 12; var output = new AtomicInteger(-1); ThrowingConsumer consumer = output::set; @@ -34,7 +34,7 @@ void acceptCheckedException() throws IOException { } @Test - void acceptThrowsException() { + void givenIOExceptionThrowingComputationWhenCallingAcceptOnThrowingConsumerThenThrowIOException() { ThrowingConsumer consumer = v -> { throw new IOException(); }; diff --git a/common-types/src/test/java/io/carbynestack/common/function/ThrowingFunctionTest.java b/common-types/src/test/java/io/carbynestack/common/function/ThrowingFunctionTest.java index 4eec290..a208598 100644 --- a/common-types/src/test/java/io/carbynestack/common/function/ThrowingFunctionTest.java +++ b/common-types/src/test/java/io/carbynestack/common/function/ThrowingFunctionTest.java @@ -15,21 +15,21 @@ class ThrowingFunctionTest { @Test - void apply() { + void givenNonThrowingIdentityFunctionWhenCallingApplyOnThrowingFunctionThenReturnExpectedComputationResult() { var value = 12; ThrowingFunction function = v -> v; assertThat(function.apply(value)).isEqualTo(value); } @Test - void applyCheckedException() throws IOException { + void givenNonThrowingIdentityFunctionWithCheckedExceptionWhenCallingApplyOnThrowingFunctionThenReturnExpectedComputationResult() throws IOException { var value = 12; ThrowingFunction function = v -> v; assertThat(function.apply(value)).isEqualTo(value); } @Test - void applyThrowsException() { + void givenIOExceptionThrowingComputationWhenCallingApplyOnThrowingFunctionThenThrowIOException() { ThrowingFunction function = v -> { throw new IOException(); }; diff --git a/common-types/src/test/java/io/carbynestack/common/function/ThrowingSupplierTest.java b/common-types/src/test/java/io/carbynestack/common/function/ThrowingSupplierTest.java index e48b499..cd33663 100644 --- a/common-types/src/test/java/io/carbynestack/common/function/ThrowingSupplierTest.java +++ b/common-types/src/test/java/io/carbynestack/common/function/ThrowingSupplierTest.java @@ -15,21 +15,21 @@ class ThrowingSupplierTest { @Test - void get() { + void givenNonThrowingComputationWhenCallingGetOnThrowingSupplierThenSuccessfullyExecuteComputation() { var value = 12; ThrowingSupplier supplier = () -> value; assertThat(supplier.get()).isEqualTo(value); } @Test - void getCheckedException() throws IOException { + void givenNonThrowingComputationWithCheckedExceptionWhenCallingGetOnThrowingSupplierThenSuccessfullyExecuteComputation() throws IOException { var value = 12; ThrowingSupplier supplier = () -> value; assertThat(supplier.get()).isEqualTo(value); } @Test - void getThrowsException() { + void givenIOExceptionThrowingComputationWhenCallingGetOnThrowingSupplierThenThrowIOException() { ThrowingSupplier supplier = () -> { throw new IOException(); }; diff --git a/common-types/src/test/java/io/carbynestack/common/result/ResultTest.java b/common-types/src/test/java/io/carbynestack/common/result/ResultTest.java index f916bd3..e7d1c91 100644 --- a/common-types/src/test/java/io/carbynestack/common/result/ResultTest.java +++ b/common-types/src/test/java/io/carbynestack/common/result/ResultTest.java @@ -18,7 +18,7 @@ class ResultTest { @Test - void success() { + void givenFailureResultWhenApplyingTransformationsInSequenceUsingMapAndRecoverAndFlatMapAndFilterAndOrThenExpectSuccessResult() { var value = 12; var other = new Success(value); @@ -45,7 +45,7 @@ void success() { } @Test - void failure() { + void givenSuccessResultWhenApplyingTransformationsInSequenceUsingMapAndRecoverAndFlatMapAndFilterAndOrThenExpectFailureResult() { var res = Result.of(() -> 21, 21) .map(v -> v * 2) .peek(System.out::println) @@ -64,7 +64,7 @@ void failure() { } @Test - void result() { + void givenFailureResultWhenApplyingTransformationsInSequenceUsingFlatMapAndRecoverAndFilterThenExpectFailureResult() { var res = new Failure(21) .flatMap(Success::new) .recover(r -> r) @@ -78,7 +78,7 @@ void result() { } @Test - void mapFailure() { + void givenSuccessResultWhenApplyingTransformationsInSequenceUsingMapFailureAndFlatMapThenExpectFailureResult() { assertThat(new Success<>(12) .mapFailure(Long.TYPE::cast) .flatMap(v -> new Failure((long) v * 2)) @@ -87,7 +87,7 @@ void mapFailure() { } @Test - void tryPeek() { + void givenSuccessResultWhenApplyingTransformationsInSequenceUsingTryPeekThenExpectFailureResult() { assertThat(new Success<>(12) .tryPeek(System.out::println, -1) .tryPeek(v -> { @@ -98,7 +98,7 @@ void tryPeek() { } @Test - void tryMap() { + void givenSuccessResultWhenApplyingTransformationsInSequenceUsingTryMapThenExpectFailureResult() { assertThat(new Success<>(12) .tryMap(v -> v * 2, -11) .tryMap(v -> { @@ -109,7 +109,7 @@ void tryMap() { } @Test - void of() { + void givenSuccessValuesAndFailureReasonsWhenCallingOfOnResultThenReturnExpectedResult() { var value = 12; FailureException reason = new FailureException(); assertThat(Result.of(() -> value).isSuccess()).isTrue(); @@ -132,7 +132,7 @@ void of() { } @Test - void unsafeFlatten() { + void givenOutermostNestedResultInstanceWhenCallingUnsafeFlattenOnResultThenReturnFlattenedResult() { var value = 12; var reason = 21; @@ -152,7 +152,7 @@ void unsafeFlatten() { } @Test - void swap() { + void whenCallingSwapOnResultThenReturnOppositeResultInstance() { var value = 12; var res = new Success(value);