diff --git a/core-java/functional-programming/functional-interfaces/src/test/java/io/reflectoring/function/custom/ArithmeticOperationTest.java b/core-java/functional-programming/functional-interfaces/src/test/java/io/reflectoring/function/custom/ArithmeticOperationTest.java index ee0a84f0..5e1afbeb 100644 --- a/core-java/functional-programming/functional-interfaces/src/test/java/io/reflectoring/function/custom/ArithmeticOperationTest.java +++ b/core-java/functional-programming/functional-interfaces/src/test/java/io/reflectoring/function/custom/ArithmeticOperationTest.java @@ -14,16 +14,10 @@ void operate() { ArithmeticOperation multiply = (a, b) -> a * b; ArithmeticOperation divide = (a, b) -> a / b; - // Use the operations - int addition = add.operate(10, 5); // Returns 15 - int subtraction = subtract.operate(10, 5); // Returns 5 - int multiplication = multiply.operate(10, 5); // Returns 50 - int division = divide.operate(10, 5); // Returns 2 - // Verify results - assertEquals(15, addition, "Result of addition is not correct."); - assertEquals(5, subtraction, "Result of subtraction is not correct."); - assertEquals(50, multiplication, "Result of multiplication is not correct."); - assertEquals(2, division, "Result of division is not correct."); + assertEquals(15, add.operate(10, 5)); + assertEquals(5, subtract.operate(10, 5)); + assertEquals(50, multiply.operate(10, 5)); + assertEquals(2, divide.operate(10, 5)); } } diff --git a/core-java/functional-programming/functional-interfaces/src/test/java/io/reflectoring/function/custom/MethodReferenceTest.java b/core-java/functional-programming/functional-interfaces/src/test/java/io/reflectoring/function/custom/MethodReferenceTest.java index 1e8ae840..96ab8c8b 100644 --- a/core-java/functional-programming/functional-interfaces/src/test/java/io/reflectoring/function/custom/MethodReferenceTest.java +++ b/core-java/functional-programming/functional-interfaces/src/test/java/io/reflectoring/function/custom/MethodReferenceTest.java @@ -10,19 +10,18 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -/** The Method reference test. */ +/** Method reference test. */ public class MethodReferenceTest { /** Static method reference. */ -@Test + @Test void staticMethodReference() { List numbers = List.of(1, -2, 3, -4, 5); List positiveNumbers = numbers.stream().map(Math::abs).toList(); - positiveNumbers.forEach( - number -> Assertions.assertTrue(number > 0, "Number should be positive.")); + positiveNumbers.forEach(number -> Assertions.assertTrue(number > 0)); } /** The String number comparator. */ -static class StringNumberComparator implements Comparator { + static class StringNumberComparator implements Comparator { @Override public int compare(String o1, String o2) { if (o1 == null) { @@ -35,33 +34,33 @@ public int compare(String o1, String o2) { } /** Instance method reference. */ -@Test + @Test void containingClassInstanceMethodReference() { List numbers = List.of("One", "Two", "Three"); List numberChars = numbers.stream().map(String::length).toList(); - numberChars.forEach(length -> Assertions.assertTrue(length > 0, "Number text is not empty.")); + numberChars.forEach(length -> Assertions.assertTrue(length > 0)); } /** Instance method reference. */ -@Test + @Test void containingObjectInstanceMethodReference() { List numbers = List.of("One", "Two", "Three"); StringNumberComparator comparator = new StringNumberComparator(); final List sorted = numbers.stream().sorted(comparator::compare).toList(); final List expected = List.of("One", "Three", "Two"); - Assertions.assertEquals(expected, sorted, "Incorrect sorting."); + Assertions.assertEquals(expected, sorted); } /** Instance method arbitrary object particular type. */ -@Test + @Test void instanceMethodArbitraryObjectParticularType() { List numbers = List.of(1, 2L, 3.0f, 4.0d); List numberIntValues = numbers.stream().map(Number::intValue).toList(); - Assertions.assertEquals(List.of(1, 2, 3, 4), numberIntValues, "Int values are not same."); + Assertions.assertEquals(List.of(1, 2, 3, 4), numberIntValues); } /** Constructor reference. */ -@Test + @Test void constructorReference() { List numbers = List.of("1", "2", "3"); Map numberMapping = @@ -76,6 +75,6 @@ void constructorReference() { put("3", BigInteger.valueOf(3)); } }; - Assertions.assertEquals(expected, numberMapping, "Mapped numbers do not match."); + Assertions.assertEquals(expected, numberMapping); } }