parent
e968ad5a3f
commit
8f7eb6ce20
|
@ -40,8 +40,7 @@ import org.apache.commons.lang3.Streams.FailableStream;
|
|||
* constructs like:
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* @code
|
||||
* {@code
|
||||
* Consumer<java.lang.reflect.Method> consumer = (m) -> {
|
||||
* try {
|
||||
* m.invoke(o, args);
|
||||
|
@ -504,8 +503,7 @@ public class Functions {
|
|||
* {@link Throwable} is rethrown. Example use:
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* @code
|
||||
* {@code
|
||||
* final FileInputStream fis = new FileInputStream("my.file");
|
||||
* Functions.tryWithResources(useInputStream(fis), null, () -> fis.close());
|
||||
* }</pre>
|
||||
|
@ -566,8 +564,7 @@ public class Functions {
|
|||
* {@link Throwable} is rethrown. Example use:
|
||||
*
|
||||
* <pre>
|
||||
* {
|
||||
* @code
|
||||
* {@code
|
||||
* final FileInputStream fis = new FileInputStream("my.file");
|
||||
* Functions.tryWithResources(useInputStream(fis), () -> fis.close());
|
||||
* }</pre>
|
||||
|
|
|
@ -178,7 +178,7 @@ class FunctionsTest {
|
|||
@Test
|
||||
void testAsCallable() {
|
||||
FailureOnOddInvocations.invocation = 0;
|
||||
final FailableCallable<FailureOnOddInvocations, SomeException> failableCallable = () -> new FailureOnOddInvocations();
|
||||
final FailableCallable<FailureOnOddInvocations, SomeException> failableCallable = FailureOnOddInvocations::new;
|
||||
final Callable<FailureOnOddInvocations> callable = Functions.asCallable(failableCallable);
|
||||
final UndeclaredThrowableException e = assertThrows(UndeclaredThrowableException.class, () -> callable.call());
|
||||
final Throwable cause = e.getCause();
|
||||
|
@ -221,7 +221,7 @@ class FunctionsTest {
|
|||
void testAsConsumer() {
|
||||
final IllegalStateException ise = new IllegalStateException();
|
||||
final Testable testable = new Testable(ise);
|
||||
final Consumer<Testable> consumer = Functions.asConsumer(t -> t.test());
|
||||
final Consumer<Testable> consumer = Functions.asConsumer(Testable::test);
|
||||
Throwable e = assertThrows(IllegalStateException.class, () -> consumer.accept(testable));
|
||||
assertSame(ise, e);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class LocksTest {
|
|||
/** If our threads are running concurrently, then we expect to be faster
|
||||
* than running one after the other.
|
||||
*/
|
||||
runTest(DELAY, false, (l) -> assertTrue(l < NUMBER_OF_THREADS*DELAY));
|
||||
runTest(DELAY, false, l -> assertTrue(l < NUMBER_OF_THREADS*DELAY));
|
||||
}
|
||||
|
||||
void testWriteLock() throws Exception {
|
||||
|
@ -41,7 +41,7 @@ class LocksTest {
|
|||
/** If our threads are running concurrently, then we expect to be no faster
|
||||
* than running one after the other.
|
||||
*/
|
||||
runTest(DELAY, true, (l) -> assertTrue(l >= NUMBER_OF_THREADS*DELAY));
|
||||
runTest(DELAY, true, l -> assertTrue(l >= NUMBER_OF_THREADS*DELAY));
|
||||
}
|
||||
|
||||
private void runTest(long delay, boolean exclusiveLock, LongConsumer runTimeCheck) throws InterruptedException {
|
||||
|
@ -52,7 +52,7 @@ class LocksTest {
|
|||
final long startTime = System.currentTimeMillis();
|
||||
for (int i = 0; i < booleanValues.length; i++) {
|
||||
final int index = i;
|
||||
final FailableConsumer<boolean[], ?> consumer = (b) -> {
|
||||
final FailableConsumer<boolean[], ?> consumer = b -> {
|
||||
b[index] = false;
|
||||
Thread.sleep(delay);
|
||||
b[index] = true;
|
||||
|
|
|
@ -46,7 +46,7 @@ class StreamsTest {
|
|||
@Test
|
||||
void testSimpleStreamMap() {
|
||||
final List<String> input = Arrays.asList("1", "2", "3", "4", "5", "6");
|
||||
final List<Integer> output = Functions.stream(input).map((s) -> Integer.valueOf(s)).collect(Collectors.toList());
|
||||
final List<Integer> output = Functions.stream(input).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
|
||||
assertEquals(6, output.size());
|
||||
for (int i = 0; i < 6; i++) {
|
||||
assertEquals(i+1, output.get(i).intValue());
|
||||
|
@ -56,7 +56,7 @@ class StreamsTest {
|
|||
@Test
|
||||
void testSimpleStreamMapFailing() {
|
||||
final List<String> input = Arrays.asList("1", "2", "3", "4 ", "5", "6");
|
||||
final Executable testMethod = () -> Functions.stream(input).map((s) -> Integer.valueOf(s)).collect(Collectors.toList());
|
||||
final Executable testMethod = () -> Functions.stream(input).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
|
||||
final NumberFormatException thrown = assertThrows(NumberFormatException.class, testMethod);
|
||||
assertEquals("For input string: \"4 \"", thrown.getMessage());
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class StreamsTest {
|
|||
void testSimpleStreamForEach() {
|
||||
final List<String> input = Arrays.asList("1", "2", "3", "4", "5", "6");
|
||||
final List<Integer> output = new ArrayList<>();
|
||||
Functions.stream(input).forEach((s) -> output.add(Integer.valueOf(s)));
|
||||
Functions.stream(input).forEach(s -> output.add(Integer.valueOf(s)));
|
||||
assertEquals(6, output.size());
|
||||
for (int i = 0; i < 6; i++) {
|
||||
assertEquals(i+1, output.get(i).intValue());
|
||||
|
@ -83,7 +83,7 @@ class StreamsTest {
|
|||
}
|
||||
|
||||
protected <T extends Throwable> FailableConsumer<String, T> asIntConsumer(final T pThrowable) {
|
||||
return (s) -> {
|
||||
return s -> {
|
||||
final Integer i = Integer.valueOf(s);
|
||||
if (i.intValue() == 4) {
|
||||
throw pThrowable;
|
||||
|
@ -130,8 +130,8 @@ class StreamsTest {
|
|||
void testSimpleStreamFilter() {
|
||||
final List<String> input = Arrays.asList("1", "2", "3", "4", "5", "6");
|
||||
final List<Integer> output = Functions.stream(input)
|
||||
.map((s) -> Integer.valueOf(s))
|
||||
.filter((i) -> {
|
||||
.map(s -> Integer.valueOf(s))
|
||||
.filter(i -> {
|
||||
return i.intValue() %2 == 0;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
@ -146,7 +146,7 @@ class StreamsTest {
|
|||
}
|
||||
|
||||
protected <T extends Throwable> FailablePredicate<Integer, T> asIntPredicate(final T pThrowable) {
|
||||
return (i) -> {
|
||||
return i -> {
|
||||
if (i.intValue() == 5) {
|
||||
if (pThrowable != null) {
|
||||
throw pThrowable;
|
||||
|
@ -160,7 +160,7 @@ class StreamsTest {
|
|||
Stream<DynamicTest> simpleStreamFilterFailing() {
|
||||
final List<String> input = Arrays.asList("1", "2", "3", "4", "5", "6");
|
||||
final List<Integer> output = Functions.stream(input)
|
||||
.map((s) -> Integer.valueOf(s))
|
||||
.map(s -> Integer.valueOf(s))
|
||||
.filter(asIntPredicate(null))
|
||||
.collect(Collectors.toList());
|
||||
assertEvenNumbers(output);
|
||||
|
@ -170,7 +170,7 @@ class StreamsTest {
|
|||
dynamicTest("IllegalArgumentException", () -> {
|
||||
final IllegalArgumentException iae = new IllegalArgumentException("Invalid argument: " + 5);
|
||||
final Executable testMethod = () -> Functions.stream(input)
|
||||
.map((s) -> Integer.valueOf(s))
|
||||
.map(s -> Integer.valueOf(s))
|
||||
.filter(asIntPredicate(iae))
|
||||
.collect(Collectors.toList());
|
||||
final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, testMethod);
|
||||
|
@ -180,7 +180,7 @@ class StreamsTest {
|
|||
dynamicTest("OutOfMemoryError", () -> {
|
||||
final OutOfMemoryError oome = new OutOfMemoryError();
|
||||
final Executable testMethod = () -> Functions.stream(input)
|
||||
.map((s) -> Integer.valueOf(s))
|
||||
.map(s -> Integer.valueOf(s))
|
||||
.filter(asIntPredicate(oome))
|
||||
.collect(Collectors.toList());
|
||||
final OutOfMemoryError thrown = assertThrows(OutOfMemoryError.class, testMethod);
|
||||
|
@ -190,7 +190,7 @@ class StreamsTest {
|
|||
dynamicTest("SAXException", () -> {
|
||||
final SAXException se = new SAXException();
|
||||
final Executable testMethod = () -> Functions.stream(input)
|
||||
.map((s) -> Integer.valueOf(s))
|
||||
.map(s -> Integer.valueOf(s))
|
||||
.filter(asIntPredicate(se))
|
||||
.collect(Collectors.toList());
|
||||
final UndeclaredThrowableException thrown = assertThrows(UndeclaredThrowableException.class, testMethod);
|
||||
|
|
Loading…
Reference in New Issue