/** * Assert that the {@code Result} is a success and contains the specified value. * * @param value the value the {@code Result} is expected to contain * @return this, if the wrapped object is a success and has the specified value * @throws AssertionError if the wrapped object is a failure, or does not have the specified value */ public ResultAssert hasValue(Object value) { isSuccess(); if (!actual.getValue().equals(value)) { failWithMessage("Expected Success with value: <%s> but was: <%s>", value, actual.getValue()); } return this; }
public void assert_success() { Result<String> test = Result.success("success"); assertThat(test) .isSuccess() .hasValue("success"); }
public void assert_success_map() { Result<String> success = Result.success("success"); Result<Integer> test = success.map(MAP_STRLEN); assertThat(test).isSuccess().hasValue(7); }
public void assert_success_flatMap() { Result<String> success = Result.success("success"); Result<Integer> test = success.flatMap(FUNCTION_STRLEN); assertThat(test).isSuccess().hasValue(7); }
public void combine_iterableWithSuccesses() { Result<Integer> success1 = Result.success(1); Result<Integer> success2 = Result.success(2); Result<Integer> success3 = Result.success(3); Result<Integer> success4 = Result.success(4); Set<Result<Integer>> results = ImmutableSet.of(success1, success2, success3, success4); Result<String> combined = Result.combine( results, s -> "res" + s.reduce(1, (i1, i2) -> i1 * i2)); assertThat(combined) .isSuccess() .hasValue("res24"); }
public void flatCombine_iterableWithSuccesses_combineSucceeds() { Result<Integer> success1 = Result.success(1); Result<Integer> success2 = Result.success(2); Result<Integer> success3 = Result.success(3); Result<Integer> success4 = Result.success(4); Set<Result<Integer>> results = ImmutableSet.of(success1, success2, success3, success4); Result<String> combined = Result.flatCombine( results, s -> Result.success("res" + s.reduce(1, (i1, i2) -> i1 * i2))); assertThat(combined) .isSuccess() .hasValue("res24"); }
public void assert_success_combineWith_success() { Result<String> success1 = Result.success("Hello"); Result<String> success2 = Result.success("World"); Result<String> test = success1.combineWith(success2, FUNCTION_MERGE); assertThat(test).isSuccess().hasValue("Hello World"); }
assertThat(result1.getResult()).isSuccess(); CurrencyParameterSensitivities result1Value = (CurrencyParameterSensitivities) result1.getResult().getValue(); assertThat(result1Value.getSensitivities()).containsAll(expected1.getSensitivities()); assertThat(result2.getResult()).isSuccess(); CurrencyParameterSensitivities result2Value = (CurrencyParameterSensitivities) result2.getResult().getValue(); assertThat(result2Value.getSensitivities()).containsAll(expected2.getSensitivities());