From 614bd19ad5298bdf1504b8c2d190b1d6cad4e34d Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 5 Apr 2019 04:25:09 +0200 Subject: add shortcuts for mapping adapters --- .../org/pacien/lemonad/attempt/AttemptTest.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/pacien/lemonad/attempt/AttemptTest.java b/src/test/java/org/pacien/lemonad/attempt/AttemptTest.java index 706a81d..1cb79c9 100644 --- a/src/test/java/org/pacien/lemonad/attempt/AttemptTest.java +++ b/src/test/java/org/pacien/lemonad/attempt/AttemptTest.java @@ -81,15 +81,15 @@ class AttemptTest { @Test void testTransformationFlow() { var result0 = 0; var result1 = "res"; - var result2 = "result"; - var result3 = 0L; + var result2 = 0L; + var result3 = "0"; var error0 = 0; var error1 = 0L; var error2 = "fail"; var error3 = false; - Attempt.success(result0) - .mapError((Integer err) -> { + Attempt.success(result0) + .mapError((Long err) -> { fail(); return Attempt.failure(err); }) @@ -97,29 +97,35 @@ class AttemptTest { .mapResult((String res) -> { assertEquals(result1, res); return Attempt.failure(error0); + }, (Integer err) -> { + assertEquals(error0, err); + return (long) err; }) .ifSuccess((String __) -> fail()) .mapResult((String res) -> { fail(); return Attempt.success(res); }) - .mapError((Integer err) -> { + .mapError((Long err) -> { assertEquals(error0, err); return Attempt.failure(error1); }) .mapError((Long err) -> { assertEquals(error1, err); - return Attempt.success(result2); + return Attempt.success(result2); + }, (Long res) -> { + assertEquals(result2, res); + return res.toString(); }) .ifFailure((Long err) -> fail()) .flatMap((Attempt attempt) -> { - assertEquals(result2, attempt.getResult()); + assertEquals(Long.toString(result2), attempt.getResult()); return Attempt.failure(error2); }) .ifSuccess(__ -> fail()) .ifFailure(f -> assertEquals(error2, f)) .map((String __) -> Attempt.failure(error3), (String __) -> Attempt.success(result3)) - .ifSuccess((Long result) -> assertEquals(result3, result)) + .ifSuccess((String result) -> assertEquals(result3, result)) .ifFailure((Boolean __) -> fail()); } } -- cgit v1.2.3