Browse Source

Consistently supply test name to @Parameters

pull/786/head
Sam Brannen 10 years ago
parent
commit
572cbb0821
  1. 4
      spring-context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java
  2. 27
      spring-test/src/test/java/org/springframework/test/context/junit4/FailingBeforeAndAfterMethodsJUnitTests.java
  3. 36
      spring-test/src/test/java/org/springframework/test/context/junit4/FailingBeforeAndAfterMethodsTestNGTests.java
  4. 21
      spring-test/src/test/java/org/springframework/test/context/junit4/ParameterizedDependencyInjectionTests.java
  5. 37
      spring-test/src/test/java/org/springframework/test/context/junit4/RepeatedSpringRunnerTests.java
  6. 30
      spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java
  7. 14
      spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestHttpMethodsTests.java
  8. 8
      spring-websocket/src/test/java/org/springframework/web/socket/WebSocketIntegrationTests.java
  9. 4
      spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationTests.java
  10. 4
      spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java

4
spring-context/src/test/java/org/springframework/scheduling/support/CronTriggerTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -53,7 +53,7 @@ public class CronTriggerTests { @@ -53,7 +53,7 @@ public class CronTriggerTests {
this.timeZone = timeZone;
}
@Parameters
@Parameters(name = "date [{0}], time zone [{1}]")
public static List<Object[]> getParameters() {
List<Object[]> list = new ArrayList<Object[]>();
list.add(new Object[] { new Date(), TimeZone.getTimeZone("PST") });

27
spring-test/src/test/java/org/springframework/test/context/junit4/FailingBeforeAndAfterMethodsJUnitTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,6 +33,7 @@ import org.springframework.test.context.TestExecutionListeners; @@ -33,6 +33,7 @@ import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.util.ClassUtils;
import static org.junit.Assert.*;
@ -66,24 +67,24 @@ public class FailingBeforeAndAfterMethodsJUnitTests { @@ -66,24 +67,24 @@ public class FailingBeforeAndAfterMethodsJUnitTests {
protected final Class<?> clazz;
public FailingBeforeAndAfterMethodsJUnitTests(final Class<?> clazz) {
this.clazz = clazz;
}
@Parameters
@Parameters(name = "{0}")
public static Collection<Object[]> testData() {
return Arrays.asList(new Object[][] {//
//
{ AlwaysFailingBeforeTestClassTestCase.class },//
{ AlwaysFailingAfterTestClassTestCase.class },//
{ AlwaysFailingPrepareTestInstanceTestCase.class },//
{ AlwaysFailingBeforeTestMethodTestCase.class },//
{ AlwaysFailingAfterTestMethodTestCase.class },//
{ FailingBeforeTransactionTestCase.class },//
{ FailingAfterTransactionTestCase.class } //
{ AlwaysFailingBeforeTestClassTestCase.class.getSimpleName() },//
{ AlwaysFailingAfterTestClassTestCase.class.getSimpleName() },//
{ AlwaysFailingPrepareTestInstanceTestCase.class.getSimpleName() },//
{ AlwaysFailingBeforeTestMethodTestCase.class.getSimpleName() },//
{ AlwaysFailingAfterTestMethodTestCase.class.getSimpleName() },//
{ FailingBeforeTransactionTestCase.class.getSimpleName() },//
{ FailingAfterTransactionTestCase.class.getSimpleName() } //
});
}
public FailingBeforeAndAfterMethodsJUnitTests(String testClassName) throws Exception {
this.clazz = ClassUtils.forName(getClass().getName() + "." + testClassName, getClass().getClassLoader());
}
@Test
public void runTestAndAssertCounters() throws Exception {
final TrackingRunListener listener = new TrackingRunListener();

36
spring-test/src/test/java/org/springframework/test/context/junit4/FailingBeforeAndAfterMethodsTestNGTests.java

@ -34,6 +34,7 @@ import org.springframework.test.context.testng.AbstractTransactionalTestNGSpring @@ -34,6 +34,7 @@ import org.springframework.test.context.testng.AbstractTransactionalTestNGSpring
import org.springframework.test.context.testng.TrackingTestNGTestListener;
import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.util.ClassUtils;
import org.testng.TestNG;
@ -73,30 +74,29 @@ public class FailingBeforeAndAfterMethodsTestNGTests { @@ -73,30 +74,29 @@ public class FailingBeforeAndAfterMethodsTestNGTests {
protected final int expectedFailedConfigurationsCount;
public FailingBeforeAndAfterMethodsTestNGTests(final Class<?> clazz, final int expectedTestStartCount,
final int expectedTestSuccessCount, final int expectedFailureCount,
final int expectedFailedConfigurationsCount) {
this.clazz = clazz;
this.expectedTestStartCount = expectedTestStartCount;
this.expectedTestSuccessCount = expectedTestSuccessCount;
this.expectedFailureCount = expectedFailureCount;
this.expectedFailedConfigurationsCount = expectedFailedConfigurationsCount;
}
@Parameters
@Parameters(name = "{0}")
public static Collection<Object[]> testData() {
return Arrays.asList(new Object[][] {//
//
{ AlwaysFailingBeforeTestClassTestCase.class, 1, 0, 0, 1 },//
{ AlwaysFailingAfterTestClassTestCase.class, 1, 1, 0, 1 },//
{ AlwaysFailingPrepareTestInstanceTestCase.class, 1, 0, 0, 1 },//
{ AlwaysFailingBeforeTestMethodTestCase.class, 1, 0, 0, 1 },//
{ AlwaysFailingAfterTestMethodTestCase.class, 1, 1, 0, 1 },//
{ FailingBeforeTransactionTestCase.class, 1, 0, 0, 1 },//
{ FailingAfterTransactionTestCase.class, 1, 1, 0, 1 } //
{ AlwaysFailingBeforeTestClassTestCase.class.getSimpleName(), 1, 0, 0, 1 },//
{ AlwaysFailingAfterTestClassTestCase.class.getSimpleName(), 1, 1, 0, 1 },//
{ AlwaysFailingPrepareTestInstanceTestCase.class.getSimpleName(), 1, 0, 0, 1 },//
{ AlwaysFailingBeforeTestMethodTestCase.class.getSimpleName(), 1, 0, 0, 1 },//
{ AlwaysFailingAfterTestMethodTestCase.class.getSimpleName(), 1, 1, 0, 1 },//
{ FailingBeforeTransactionTestCase.class.getSimpleName(), 1, 0, 0, 1 },//
{ FailingAfterTransactionTestCase.class.getSimpleName(), 1, 1, 0, 1 } //
});
}
public FailingBeforeAndAfterMethodsTestNGTests(String testClassName, int expectedTestStartCount,
int expectedTestSuccessCount, int expectedFailureCount, int expectedFailedConfigurationsCount) throws Exception {
this.clazz = ClassUtils.forName(getClass().getName() + "." + testClassName, getClass().getClassLoader());
this.expectedTestStartCount = expectedTestStartCount;
this.expectedTestSuccessCount = expectedTestSuccessCount;
this.expectedFailureCount = expectedFailureCount;
this.expectedFailedConfigurationsCount = expectedFailedConfigurationsCount;
}
@Test
public void runTestAndAssertCounters() throws Exception {
final TrackingTestNGTestListener listener = new TrackingTestNGTestListener();

21
spring-test/src/test/java/org/springframework/test/context/junit4/ParameterizedDependencyInjectionTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,6 +27,7 @@ import org.junit.BeforeClass; @@ -27,6 +27,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
@ -58,26 +59,22 @@ public class ParameterizedDependencyInjectionTests { @@ -58,26 +59,22 @@ public class ParameterizedDependencyInjectionTests {
private static final List<Employee> employees = new ArrayList<Employee>();
private final TestContextManager testContextManager = new TestContextManager(getClass());
@Autowired
private ApplicationContext applicationContext;
@Autowired
private Pet pet;
private final String employeeBeanName;
private final String employeeName;
private final TestContextManager testContextManager;
@Parameter(0)
public String employeeBeanName;
@Parameter(1)
public String employeeName;
public ParameterizedDependencyInjectionTests(final String employeeBeanName, final String employeeName)
throws Exception {
this.testContextManager = new TestContextManager(getClass());
this.employeeBeanName = employeeBeanName;
this.employeeName = employeeName;
}
@Parameters
@Parameters(name = "bean [{0}], employee [{1}]")
public static Collection<String[]> employeeData() {
return Arrays.asList(new String[][] { { "employee1", "John Smith" }, { "employee2", "Jane Smith" } });
}

37
spring-test/src/test/java/org/springframework/test/context/junit4/RepeatedSpringRunnerTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,6 +33,7 @@ import org.junit.runners.Parameterized.Parameters; @@ -33,6 +33,7 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Timed;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.util.ClassUtils;
import static org.junit.Assert.*;
@ -52,7 +53,7 @@ public class RepeatedSpringRunnerTests { @@ -52,7 +53,7 @@ public class RepeatedSpringRunnerTests {
private static final AtomicInteger invocationCount = new AtomicInteger();
private final Class<? extends AbstractRepeatedTestCase> testClass;
private final Class<?> testClass;
private final int expectedFailureCount;
@ -63,28 +64,28 @@ public class RepeatedSpringRunnerTests { @@ -63,28 +64,28 @@ public class RepeatedSpringRunnerTests {
private final int expectedInvocationCount;
public RepeatedSpringRunnerTests(Class<? extends AbstractRepeatedTestCase> testClass, int expectedFailureCount,
int expectedTestStartedCount, int expectedTestFinishedCount, int expectedInvocationCount) {
this.testClass = testClass;
this.expectedFailureCount = expectedFailureCount;
this.expectedTestStartedCount = expectedTestStartedCount;
this.expectedTestFinishedCount = expectedTestFinishedCount;
this.expectedInvocationCount = expectedInvocationCount;
}
@Parameters
@Parameters(name = "{0}")
public static Collection<Object[]> repetitionData() {
return Arrays.asList(new Object[][] {//
//
{ NonAnnotatedRepeatedTestCase.class, 0, 1, 1, 1 },//
{ DefaultRepeatValueRepeatedTestCase.class, 0, 1, 1, 1 },//
{ NegativeRepeatValueRepeatedTestCase.class, 0, 1, 1, 1 },//
{ RepeatedFiveTimesRepeatedTestCase.class, 0, 1, 1, 5 },//
{ RepeatedFiveTimesViaMetaAnnotationRepeatedTestCase.class, 0, 1, 1, 5 },//
{ TimedRepeatedTestCase.class, 3, 4, 4, (5 + 1 + 4 + 10) } //
{ NonAnnotatedRepeatedTestCase.class.getSimpleName(), 0, 1, 1, 1 },//
{ DefaultRepeatValueRepeatedTestCase.class.getSimpleName(), 0, 1, 1, 1 },//
{ NegativeRepeatValueRepeatedTestCase.class.getSimpleName(), 0, 1, 1, 1 },//
{ RepeatedFiveTimesRepeatedTestCase.class.getSimpleName(), 0, 1, 1, 5 },//
{ RepeatedFiveTimesViaMetaAnnotationRepeatedTestCase.class.getSimpleName(), 0, 1, 1, 5 },//
{ TimedRepeatedTestCase.class.getSimpleName(), 3, 4, 4, (5 + 1 + 4 + 10) } //
});
}
public RepeatedSpringRunnerTests(String testClassName, int expectedFailureCount,
int expectedTestStartedCount, int expectedTestFinishedCount, int expectedInvocationCount) throws Exception {
this.testClass = ClassUtils.forName(getClass().getName() + "." + testClassName, getClass().getClassLoader());
this.expectedFailureCount = expectedFailureCount;
this.expectedTestStartedCount = expectedTestStartedCount;
this.expectedTestFinishedCount = expectedTestFinishedCount;
this.expectedInvocationCount = expectedInvocationCount;
}
@Test
public void assertRepetitions() throws Exception {
TrackingRunListener listener = new TrackingRunListener();

30
spring-test/src/test/java/org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,10 +25,10 @@ import org.junit.Test; @@ -25,10 +25,10 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextLoader;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import static org.junit.Assert.*;
@ -55,12 +55,7 @@ public class GenericXmlContextLoaderResourceLocationsTests { @@ -55,12 +55,7 @@ public class GenericXmlContextLoaderResourceLocationsTests {
protected final String[] expectedLocations;
public GenericXmlContextLoaderResourceLocationsTests(final Class<?> testClass, final String[] expectedLocations) {
this.testClass = testClass;
this.expectedLocations = expectedLocations;
}
@Parameters
@Parameters(name = "{0}")
public static Collection<Object[]> contextConfigurationLocationsData() {
@ContextConfiguration
class ClasspathNonExistentDefaultLocationsTestCase {
@ -93,25 +88,25 @@ public class GenericXmlContextLoaderResourceLocationsTests { @@ -93,25 +88,25 @@ public class GenericXmlContextLoaderResourceLocationsTests {
return Arrays.asList(new Object[][] {
{ ClasspathNonExistentDefaultLocationsTestCase.class, new String[] {} },
{ ClasspathNonExistentDefaultLocationsTestCase.class.getSimpleName(), new String[] {} },
{
ClasspathExistentDefaultLocationsTestCase.class,
ClasspathExistentDefaultLocationsTestCase.class.getSimpleName(),
new String[] { "classpath:org/springframework/test/context/support/GenericXmlContextLoaderResourceLocationsTests$1ClasspathExistentDefaultLocationsTestCase-context.xml" } },
{
ImplicitClasspathLocationsTestCase.class,
ImplicitClasspathLocationsTestCase.class.getSimpleName(),
new String[] { "classpath:/org/springframework/test/context/support/context1.xml",
"classpath:/org/springframework/test/context/support/context2.xml" } },
{ ExplicitClasspathLocationsTestCase.class, new String[] { "classpath:context.xml" } },
{ ExplicitClasspathLocationsTestCase.class.getSimpleName(), new String[] { "classpath:context.xml" } },
{ ExplicitFileLocationsTestCase.class, new String[] { "file:/testing/directory/context.xml" } },
{ ExplicitFileLocationsTestCase.class.getSimpleName(), new String[] { "file:/testing/directory/context.xml" } },
{ ExplicitUrlLocationsTestCase.class, new String[] { "http://example.com/context.xml" } },
{ ExplicitUrlLocationsTestCase.class.getSimpleName(), new String[] { "http://example.com/context.xml" } },
{
ExplicitMixedPathTypesLocationsTestCase.class,
ExplicitMixedPathTypesLocationsTestCase.class.getSimpleName(),
new String[] { "classpath:/org/springframework/test/context/support/context1.xml",
"classpath:context2.xml", "classpath:/context3.xml", "file:/testing/directory/context.xml",
"http://example.com/context.xml" } }
@ -119,6 +114,11 @@ public class GenericXmlContextLoaderResourceLocationsTests { @@ -119,6 +114,11 @@ public class GenericXmlContextLoaderResourceLocationsTests {
});
}
public GenericXmlContextLoaderResourceLocationsTests(final String testClassName, final String[] expectedLocations) throws Exception {
this.testClass = ClassUtils.forName(getClass().getName() + "$1" + testClassName, getClass().getClassLoader());
this.expectedLocations = expectedLocations;
}
@Test
public void assertContextConfigurationLocations() throws Exception {

14
spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestHttpMethodsTests.java

@ -16,8 +16,6 @@ @@ -16,8 +16,6 @@
package org.springframework.web.context.request;
import static org.junit.Assert.*;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
@ -27,11 +25,14 @@ import org.junit.Before; @@ -27,11 +25,14 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import static org.junit.Assert.*;
/**
* Parameterized tests for ServletWebRequest
* @author Juergen Hoeller
@ -49,9 +50,10 @@ public class ServletWebRequestHttpMethodsTests { @@ -49,9 +50,10 @@ public class ServletWebRequestHttpMethodsTests {
private ServletWebRequest request;
private String method;
@Parameter
public String method;
@Parameters
@Parameters(name = "{0}")
static public Iterable<Object[]> safeMethods() {
return Arrays.asList(new Object[][] {
{"GET"},
@ -59,10 +61,6 @@ public class ServletWebRequestHttpMethodsTests { @@ -59,10 +61,6 @@ public class ServletWebRequestHttpMethodsTests {
});
}
public ServletWebRequestHttpMethodsTests(String method) {
this.method = method;
}
@Before
public void setUp() {
dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);

8
spring-websocket/src/test/java/org/springframework/web/socket/WebSocketIntegrationTests.java

@ -16,9 +16,6 @@ @@ -16,9 +16,6 @@
package org.springframework.web.socket;
import static org.junit.Assert.*;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
@ -29,6 +26,8 @@ import java.util.concurrent.TimeUnit; @@ -29,6 +26,8 @@ import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -41,6 +40,7 @@ import org.springframework.web.socket.handler.AbstractWebSocketHandler; @@ -41,6 +40,7 @@ import org.springframework.web.socket.handler.AbstractWebSocketHandler;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
import static org.junit.Assert.*;
/**
* Client and server-side WebSocket integration tests.
@ -50,7 +50,7 @@ import org.springframework.web.socket.server.support.DefaultHandshakeHandler; @@ -50,7 +50,7 @@ import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
@RunWith(Parameterized.class)
public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
@Parameterized.Parameters
@Parameters(name = "server [{0}], client [{1}]")
public static Iterable<Object[]> arguments() {
return Arrays.asList(new Object[][] {
{new JettyWebSocketTestServer(), new JettyWebSocketClient()},

4
spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ import static org.junit.Assert.*; @@ -49,7 +49,7 @@ import static org.junit.Assert.*;
@RunWith(Parameterized.class)
public class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTests {
@Parameters
@Parameters(name = "server [{0}], client [{1}]")
public static Iterable<Object[]> arguments() {
return Arrays.asList(new Object[][] {
{new JettyWebSocketTestServer(), new JettyWebSocketClient()},

4
spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -71,7 +71,7 @@ import static org.springframework.web.socket.messaging.StompTextMessageBuilder.* @@ -71,7 +71,7 @@ import static org.springframework.web.socket.messaging.StompTextMessageBuilder.*
@RunWith(Parameterized.class)
public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegrationTests {
@Parameters
@Parameters(name = "server [{0}], client [{1}]")
public static Iterable<Object[]> arguments() {
return Arrays.asList(new Object[][] {
{new JettyWebSocketTestServer(), new JettyWebSocketClient()},

Loading…
Cancel
Save