Skip to content

Commit 474a74c

Browse files
committed
Issue #76 - Add two override version of documented to ensure correct type erase
1 parent d2b8cfa commit 474a74c

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

src/main/java/ch/powerunit/extensions/exceptions/BinaryOperatorWithException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ default BinaryOperator<T> ignore() {
8181
return (t, u) -> ObjectReturnExceptionHandlerSupport.unchecked(() -> apply(t, u), e -> null);
8282
}
8383

84+
@Override
85+
default BinaryOperatorWithException<T, E> documented(Supplier<String> toString) {
86+
return (BinaryOperatorWithException<T, E>) BiFunctionWithException.super.documented(toString);
87+
}
88+
8489
/**
8590
* Returns a binary operator that always throw exception.
8691
*

src/main/java/ch/powerunit/extensions/exceptions/UnaryOperatorWithException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ default UnaryOperator<T> ignore() {
7777
return t -> ObjectReturnExceptionHandlerSupport.unchecked(() -> apply(t), e -> null);
7878
}
7979

80+
@Override
81+
default UnaryOperatorWithException<T, E> documented(Supplier<String> toString) {
82+
return (UnaryOperatorWithException<T, E>) FunctionWithException.super.documented(toString);
83+
}
84+
8085
/**
8186
* Returns a unary operator that always returns its input argument.
8287
*

src/test/java/ch/powerunit/extensions/exceptions/BinaryOperatorWithExceptionTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,12 @@ public void testLiftedException() {
7373
throw new Exception();
7474
}).apply("x", "x")).is(optionalIsNotPresent());
7575
}
76+
77+
@Test
78+
public void testDocumented() {
79+
BinaryOperatorWithException<String, Exception> fct1 = (x, y) -> x + y;
80+
fct1 = fct1.documented(() -> "test");
81+
assertThat(fct1.toString()).is("test");
82+
}
7683

7784
}

src/test/java/ch/powerunit/extensions/exceptions/UnaryOperatorWithExceptionTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,11 @@ public void testLiftedException() {
9292
throw new Exception();
9393
}).apply("x")).is(optionalIsNotPresent());
9494
}
95+
96+
@Test
97+
public void testDocumented() {
98+
UnaryOperatorWithException<String, Exception> fct1 = x -> x;
99+
fct1 = fct1.documented(() -> "test");
100+
assertThat(fct1.toString()).is("test");
101+
}
95102
}

0 commit comments

Comments
 (0)