protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message, final Supplier<?>... paramSuppliers) { final Message msg = messageFactory.newMessage(message, LambdaUtil.getAll(paramSuppliers)); logMessageSafely(fqcn, level, marker, msg, msg.getThrowable()); }
@Test(expected = RuntimeException.class) public void testGetAllThrowsExceptionIfAnyOfTheSuppliersThrowsException() { final Supplier<String> function1 = new Supplier<String>() { @Override public String get() { return "abc"; } }; final Supplier<String> function2 = new Supplier<String>() { @Override public String get() { throw new RuntimeException(); } }; final Supplier<?>[] functions = { function1, function2 }; LambdaUtil.getAll(functions); } }
@Test public void testGetAllReturnsNullArrayIfSupplierArrayNull() { final Object[] actual = LambdaUtil.getAll((Supplier<?>[]) null); assertNull(actual); }
@Test public void testGetAllReturnsNullElementsIfSupplierArrayContainsNulls() { final Supplier<?>[] functions = new Supplier<?>[3]; final Object[] actual = LambdaUtil.getAll(functions); assertEquals(actual.length, functions.length); for (final Object object : actual) { assertNull(object); } }
@Test public void testGetAllReturnsResultOfSuppliers() { final String expected1 = "result1"; final Supplier<String> function1 = new Supplier<String>() { @Override public String get() { return expected1; } }; final String expected2 = "result2"; final Supplier<String> function2 = new Supplier<String>() { @Override public String get() { return expected2; } }; final Supplier<?>[] functions = { function1, function2 }; final Object[] actual = LambdaUtil.getAll(functions); assertEquals(actual.length, functions.length); assertSame(expected1, actual[0]); assertSame(expected2, actual[1]); }
protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message, final Supplier<?>... paramSuppliers) { final Message msg = messageFactory.newMessage(message, LambdaUtil.getAll(paramSuppliers)); logMessageSafely(fqcn, level, marker, msg, msg.getThrowable()); }