aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/pacien/lemonad/attempt
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/pacien/lemonad/attempt')
-rw-r--r--src/test/java/org/pacien/lemonad/attempt/AttemptTest.java22
1 files changed, 14 insertions, 8 deletions
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 {
81 @Test void testTransformationFlow() { 81 @Test void testTransformationFlow() {
82 var result0 = 0; 82 var result0 = 0;
83 var result1 = "res"; 83 var result1 = "res";
84 var result2 = "result"; 84 var result2 = 0L;
85 var result3 = 0L; 85 var result3 = "0";
86 var error0 = 0; 86 var error0 = 0;
87 var error1 = 0L; 87 var error1 = 0L;
88 var error2 = "fail"; 88 var error2 = "fail";
89 var error3 = false; 89 var error3 = false;
90 90
91 Attempt.<Integer, Integer>success(result0) 91 Attempt.<Integer, Long>success(result0)
92 .mapError((Integer err) -> { 92 .mapError((Long err) -> {
93 fail(); 93 fail();
94 return Attempt.failure(err); 94 return Attempt.failure(err);
95 }) 95 })
@@ -97,29 +97,35 @@ class AttemptTest {
97 .mapResult((String res) -> { 97 .mapResult((String res) -> {
98 assertEquals(result1, res); 98 assertEquals(result1, res);
99 return Attempt.<String, Integer>failure(error0); 99 return Attempt.<String, Integer>failure(error0);
100 }, (Integer err) -> {
101 assertEquals(error0, err);
102 return (long) err;
100 }) 103 })
101 .ifSuccess((String __) -> fail()) 104 .ifSuccess((String __) -> fail())
102 .mapResult((String res) -> { 105 .mapResult((String res) -> {
103 fail(); 106 fail();
104 return Attempt.success(res); 107 return Attempt.success(res);
105 }) 108 })
106 .mapError((Integer err) -> { 109 .mapError((Long err) -> {
107 assertEquals(error0, err); 110 assertEquals(error0, err);
108 return Attempt.failure(error1); 111 return Attempt.failure(error1);
109 }) 112 })
110 .mapError((Long err) -> { 113 .mapError((Long err) -> {
111 assertEquals(error1, err); 114 assertEquals(error1, err);
112 return Attempt.<String, Long>success(result2); 115 return Attempt.<Long, Long>success(result2);
116 }, (Long res) -> {
117 assertEquals(result2, res);
118 return res.toString();
113 }) 119 })
114 .ifFailure((Long err) -> fail()) 120 .ifFailure((Long err) -> fail())
115 .flatMap((Attempt<? super String, ? super Long> attempt) -> { 121 .flatMap((Attempt<? super String, ? super Long> attempt) -> {
116 assertEquals(result2, attempt.getResult()); 122 assertEquals(Long.toString(result2), attempt.getResult());
117 return Attempt.<String, String>failure(error2); 123 return Attempt.<String, String>failure(error2);
118 }) 124 })
119 .ifSuccess(__ -> fail()) 125 .ifSuccess(__ -> fail())
120 .ifFailure(f -> assertEquals(error2, f)) 126 .ifFailure(f -> assertEquals(error2, f))
121 .map((String __) -> Attempt.failure(error3), (String __) -> Attempt.success(result3)) 127 .map((String __) -> Attempt.failure(error3), (String __) -> Attempt.success(result3))
122 .ifSuccess((Long result) -> assertEquals(result3, result)) 128 .ifSuccess((String result) -> assertEquals(result3, result))
123 .ifFailure((Boolean __) -> fail()); 129 .ifFailure((Boolean __) -> fail());
124 } 130 }
125} 131}