From bdcb452120421239eebf5abafc3fe6d2622c49af Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 3 May 2017 15:15:49 +0200 Subject: [PATCH] Polish MethodSourceTests --- .../support/descriptor/MethodSourceTests.java | 54 +++++++++---------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/MethodSourceTests.java b/platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/MethodSourceTests.java index f34caed0972..69e1df8cdf6 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/MethodSourceTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/MethodSourceTests.java @@ -19,21 +19,29 @@ import org.junit.jupiter.api.Test; import org.junit.platform.commons.util.PreconditionViolationException; +/** + * Unit tests for {@link MethodSource}. + * + * @since 1.0 + */ class MethodSourceTests { @Test void instantiatingWithNullNamesShouldThrowPreconditionViolationException() { - assertThrows(PreconditionViolationException.class, () -> new MethodSource(null, null)); + assertThrows(PreconditionViolationException.class, () -> new MethodSource("foo", null)); + assertThrows(PreconditionViolationException.class, () -> new MethodSource(null, "foo")); } @Test void instantiatingWithEmptyNamesShouldThrowPreconditionViolationException() { - assertThrows(PreconditionViolationException.class, () -> new MethodSource("", "")); + assertThrows(PreconditionViolationException.class, () -> new MethodSource("foo", "")); + assertThrows(PreconditionViolationException.class, () -> new MethodSource("", "foo")); } @Test void instantiatingWithBlankNamesShouldThrowPreconditionViolationException() { - assertThrows(PreconditionViolationException.class, () -> new MethodSource(" ", " ")); + assertThrows(PreconditionViolationException.class, () -> new MethodSource("foo", " ")); + assertThrows(PreconditionViolationException.class, () -> new MethodSource(" ", "foo")); } @Test @@ -57,7 +65,7 @@ void twoUnequalMethodsInTheSameClassShouldHaveUnequalMethodSourceObjects() { } @Test - void twoEqualMethodSourceObjectsShouldHaveEqualHashCode() { + void twoEqualMethodSourceObjectsShouldHaveEqualHashCodes() { assertEquals(new MethodSource("TestClass1", "testMethod1").hashCode(), new MethodSource("TestClass1", "testMethod1").hashCode()); } @@ -94,69 +102,55 @@ void twoEqualMethodsWithUnequalParametersShouldHaveUnequalMethodSourceHashCodes( @Test void aReflectedMethodsClassNameShouldBeConsistent() throws Exception { - Class c = String.class; - Method m = c.getDeclaredMethod("valueOf", int.class); + Method m = String.class.getDeclaredMethod("valueOf", int.class); assertEquals("java.lang.String", new MethodSource(m).getClassName()); } @Test void aReflectedMethodsMethodNameShouldBeConsistent() throws Exception { - Class c = String.class; - Method m = c.getDeclaredMethod("valueOf", int.class); + Method m = String.class.getDeclaredMethod("valueOf", int.class); assertEquals("valueOf", new MethodSource(m).getMethodName()); } @Test void aReflectedMethodsParameterTypesShouldBeConsistent() throws Exception { - Class c = String.class; - Method m = c.getDeclaredMethod("valueOf", float.class); + Method m = String.class.getDeclaredMethod("valueOf", float.class); assertEquals("float", new MethodSource(m).getMethodParameterTypes()); } @Test void twoEqualReflectedMethodsShouldHaveEqualMethodSourceObjects() throws Exception { - Class c1 = String.class; - Method m1 = c1.getDeclaredMethod("valueOf", int.class); - - Class c2 = String.class; - Method m2 = c2.getDeclaredMethod("valueOf", int.class); + Method m1 = String.class.getDeclaredMethod("valueOf", int.class); + Method m2 = String.class.getDeclaredMethod("valueOf", int.class); assertEquals(new MethodSource(m1), new MethodSource(m2)); } @Test void twoEqualReflectedMethodsShouldHaveEqualMethodSourceHashCodes() throws Exception { - Class c1 = String.class; - Method m1 = c1.getDeclaredMethod("valueOf", int.class); - - Class c2 = String.class; - Method m2 = c2.getDeclaredMethod("valueOf", int.class); + Method m1 = String.class.getDeclaredMethod("valueOf", int.class); + Method m2 = String.class.getDeclaredMethod("valueOf", int.class); assertEquals(new MethodSource(m1).hashCode(), new MethodSource(m2).hashCode()); } @Test void twoUnequalReflectedMethodsShouldNotHaveEqualMethodSourceObjects() throws Exception { - Class c1 = String.class; - Method m1 = c1.getDeclaredMethod("valueOf", int.class); - - Class c2 = Byte.class; - Method m2 = c2.getDeclaredMethod("byteValue"); + Method m1 = String.class.getDeclaredMethod("valueOf", int.class); + Method m2 = Byte.class.getDeclaredMethod("byteValue"); assertNotEquals(new MethodSource(m1), new MethodSource(m2)); } @Test void twoUnequalReflectedMethodsShouldNotHaveEqualMethodSourceHashCodes() throws Exception { - Class c1 = String.class; - Method m1 = c1.getDeclaredMethod("valueOf", int.class); - - Class c2 = Byte.class; - Method m2 = c2.getDeclaredMethod("byteValue"); + Method m1 = String.class.getDeclaredMethod("valueOf", int.class); + Method m2 = Byte.class.getDeclaredMethod("byteValue"); assertNotEquals(new MethodSource(m1).hashCode(), new MethodSource(m2).hashCode()); } + }