Skip to content

Commit

Permalink
Remove error-prone constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Oct 29, 2015
1 parent 0a633a9 commit 72c7483
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Expand Up @@ -11,7 +11,7 @@
package org.junit.gen5.engine.junit5;

import static java.util.Collections.*;
import static org.junit.gen5.commons.util.ObjectUtils.*;
import static org.junit.gen5.commons.util.ObjectUtils.nullSafeToString;

import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down Expand Up @@ -82,7 +82,7 @@ public static JavaMethodTestDescriptor from(final String uid) throws RuntimeExce

try {
Method method = clazz.getDeclaredMethod(methodName, parameterTypes);
return new JavaMethodTestDescriptor(engineId, method);
return new JavaMethodTestDescriptor(engineId, clazz, method);
}
catch (NoSuchMethodException e) {
throw new IllegalStateException("Failed to get method with name '" + methodName + "'.", e);
Expand All @@ -101,10 +101,6 @@ public static JavaMethodTestDescriptor from(final String uid) throws RuntimeExce
private final Method testMethod;


public JavaMethodTestDescriptor(String engineId, Method testMethod) {
this(engineId, testMethod.getDeclaringClass(), testMethod, null, null);
}

public JavaMethodTestDescriptor(String engineId, Class<?> testClass, Method testMethod) {
this(engineId, testClass, testMethod, null, null);
}
Expand Down
Expand Up @@ -39,40 +39,43 @@ public class JavaTestDescriptorTests {

@org.junit.Test
public void constructFromMethod() throws Exception {
Method testMethod = getClass().getDeclaredMethod("test");
JavaMethodTestDescriptor descriptor = new JavaMethodTestDescriptor(JUNIT_5_ENGINE_ID, testMethod);
Class<? extends JavaTestDescriptorTests> testClass = getClass();
Method testMethod = testClass.getDeclaredMethod("test");
JavaMethodTestDescriptor descriptor = new JavaMethodTestDescriptor(JUNIT_5_ENGINE_ID, testClass, testMethod);

System.out.println("DEBUG - " + descriptor);
assertEquals(JUNIT_5_ENGINE_ID, descriptor.getEngineId());
assertEquals(TEST_METHOD_ID, descriptor.getTestId());
assertEquals(TEST_METHOD_UID, descriptor.getUniqueId());
assertEquals(getClass(), descriptor.getTestClass());
assertEquals(testClass, descriptor.getTestClass());
assertEquals(testMethod, descriptor.getTestMethod());
assertEquals("test", descriptor.getDisplayName(), "display name:");
}

@org.junit.Test
public void constructFromMethodWithCustomDisplayName() throws Exception {
Method testMethod = getClass().getDeclaredMethod("foo");
JavaMethodTestDescriptor descriptor = new JavaMethodTestDescriptor(JUNIT_5_ENGINE_ID, testMethod);
Class<? extends JavaTestDescriptorTests> testClass = getClass();
Method testMethod = testClass.getDeclaredMethod("foo");
JavaMethodTestDescriptor descriptor = new JavaMethodTestDescriptor(JUNIT_5_ENGINE_ID, testClass, testMethod);

System.out.println("DEBUG - " + descriptor);
assertEquals(JUNIT_5_ENGINE_ID, descriptor.getEngineId());
assertEquals(getClass(), descriptor.getTestClass());
assertEquals(testClass, descriptor.getTestClass());
assertEquals(testMethod, descriptor.getTestMethod());
assertEquals("custom test name", descriptor.getDisplayName(), "display name:");
}

@org.junit.Test
public void constructFromMethodWithParameters() throws Exception {
Method testMethod = getClass().getDeclaredMethod("test", String.class, BigDecimal.class);
JavaMethodTestDescriptor descriptor = new JavaMethodTestDescriptor(JUNIT_5_ENGINE_ID, testMethod);
Class<? extends JavaTestDescriptorTests> testClass = getClass();
Method testMethod = testClass.getDeclaredMethod("test", String.class, BigDecimal.class);
JavaMethodTestDescriptor descriptor = new JavaMethodTestDescriptor(JUNIT_5_ENGINE_ID, testClass, testMethod);

System.out.println("DEBUG - " + descriptor);
assertEquals(JUNIT_5_ENGINE_ID, descriptor.getEngineId());
assertEquals(TEST_METHOD_STRING_BIGDECIMAL_ID, descriptor.getTestId());
assertEquals(TEST_METHOD_STRING_BIGDECIMAL_UID, descriptor.getUniqueId());
assertEquals(getClass(), descriptor.getTestClass());
assertEquals(testClass, descriptor.getTestClass());
assertEquals(testMethod, descriptor.getTestMethod());
assertEquals("test", descriptor.getDisplayName(), "display name:");
}
Expand Down

0 comments on commit 72c7483

Please sign in to comment.