Skip to content

Commit ebd6521

Browse files
committed
Add tool chain to use Java 7 for compilation; fix global timeout impl
1 parent 788e4ec commit ebd6521

File tree

7 files changed

+97
-39
lines changed

7 files changed

+97
-39
lines changed

pom.xml

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@
2929
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3030
<maven.compiler.source>1.7</maven.compiler.source>
3131
<maven.compiler.target>1.7</maven.compiler.target>
32-
<java-utils.version>1.9.0</java-utils.version>
33-
<surefire-plugin.version>2.22.0</surefire-plugin.version>
34-
<source-plugin.version>3.0.1</source-plugin.version>
35-
<javadoc-plugin.version>2.10.4</javadoc-plugin.version>
36-
<settings.version>2.3.0</settings.version>
32+
<java-utils.version>1.9.1</java-utils.version>
33+
<settings.version>2.3.1</settings.version>
3734
<junit.version>4.12</junit.version>
3835
<testng.version>6.10</testng.version>
3936
<bytebuddy.version>1.9.5</bytebuddy.version>
4037
<logback.version>1.2.2</logback.version>
41-
<guava.version>23.5-jre</guava.version>
38+
<guava.version>19.0</guava.version>
39+
<toolchains-plugin.version>1.1</toolchains-plugin.version>
40+
<surefire-plugin.version>2.22.0</surefire-plugin.version>
41+
<source-plugin.version>3.0.1</source-plugin.version>
42+
<javadoc-plugin.version>2.10.4</javadoc-plugin.version>
4243
<gpg-plugin.version>1.6</gpg-plugin.version>
4344
<staging-plugin.version>1.6.7</staging-plugin.version>
4445
<release-plugin.version>2.5.3</release-plugin.version>
@@ -149,6 +150,11 @@
149150
<build>
150151
<pluginManagement>
151152
<plugins>
153+
<plugin>
154+
<groupId>org.apache.maven.plugins</groupId>
155+
<artifactId>maven-toolchains-plugin</artifactId>
156+
<version>${toolchains-plugin.version}</version>
157+
</plugin>
152158
<plugin>
153159
<groupId>org.apache.maven.plugins</groupId>
154160
<artifactId>maven-surefire-plugin</artifactId>
@@ -184,10 +190,53 @@
184190
<artifactId>maven-jar-plugin</artifactId>
185191
<version>${jar-plugin.version}</version>
186192
</plugin>
193+
<plugin>
194+
<groupId>org.eclipse.m2e</groupId>
195+
<artifactId>lifecycle-mapping</artifactId>
196+
<version>1.0.0</version>
197+
<configuration>
198+
<lifecycleMappingMetadata>
199+
<pluginExecutions>
200+
<pluginExecution>
201+
<pluginExecutionFilter>
202+
<groupId>org.apache.maven.plugins</groupId>
203+
<artifactId>maven-toolchains-plugin</artifactId>
204+
<versionRange>[1.0.0,)</versionRange>
205+
<goals>
206+
<goal>toolchain</goal>
207+
</goals>
208+
</pluginExecutionFilter>
209+
<action>
210+
<execute />
211+
</action>
212+
</pluginExecution>
213+
</pluginExecutions>
214+
</lifecycleMappingMetadata>
215+
</configuration>
216+
</plugin>
187217
</plugins>
188218
</pluginManagement>
189219

190220
<plugins>
221+
<plugin>
222+
<groupId>org.apache.maven.plugins</groupId>
223+
<artifactId>maven-toolchains-plugin</artifactId>
224+
<executions>
225+
<execution>
226+
<goals>
227+
<goal>toolchain</goal>
228+
</goals>
229+
</execution>
230+
</executions>
231+
<configuration>
232+
<toolchains>
233+
<jdk>
234+
<version>1.7</version>
235+
<vendor>oracle</vendor>
236+
</jdk>
237+
</toolchains>
238+
</configuration>
239+
</plugin>
191240
<plugin>
192241
<groupId>org.apache.maven.plugins</groupId>
193242
<artifactId>maven-surefire-plugin</artifactId>

src/main/java/com/nordstrom/automation/junit/CreateTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public static Object intercept(@This final Object runner,
5555

5656
TARGET_TO_RUNNER.put(testObj, runner);
5757
RUNNER_TO_TARGET.put(runner, testObj);
58-
LifecycleHooks.applyTimeout(testObj);
5958

6059
if (DEPTH.get().atGroundLevel()) {
6160
synchronized(objectWatcherLoader) {

src/main/java/com/nordstrom/automation/junit/LifecycleHooks.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -212,30 +212,6 @@ public static Description describeChild(Object target, Object child) {
212212
return invoke(runner, "describeChild", child);
213213
}
214214

215-
/**
216-
* If configured for default test timeout, apply this value to every test that doesn't already specify a longer
217-
* timeout interval.
218-
*
219-
* @param testObj test class object
220-
*/
221-
static void applyTimeout(Object testObj) {
222-
// if default test timeout is defined
223-
if (getConfig().containsKey(JUnitSettings.TEST_TIMEOUT.key())) {
224-
// get default test timeout
225-
long defaultTimeout = getConfig().getLong(JUnitSettings.TEST_TIMEOUT.key());
226-
// iterate over test object methods
227-
for (Method method : testObj.getClass().getDeclaredMethods()) {
228-
// get @Test annotation
229-
Test annotation = method.getAnnotation(Test.class);
230-
// if annotation declared and current timeout is less than default
231-
if ((annotation != null) && (annotation.timeout() < defaultTimeout)) {
232-
// set test timeout interval
233-
MutableTest.proxyFor(method).setTimeout(defaultTimeout);
234-
}
235-
}
236-
}
237-
}
238-
239215
/**
240216
* Get class of specified test class instance.
241217
*

src/main/java/com/nordstrom/automation/junit/MutableTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import org.junit.Ignore;
44
import org.junit.Test;
5-
import org.junit.rules.ExpectedException;
65
import org.junit.runners.model.TestTimedOutException;
76

87
import java.lang.annotation.Annotation;
9-
import java.lang.reflect.Executable;
108
import java.lang.reflect.Field;
119
import java.lang.reflect.Method;
1210
import java.util.Map;
@@ -104,7 +102,7 @@ public static MutableTest proxyFor(Method testMethod) {
104102
}
105103
if (declared != null) {
106104
try {
107-
Field field = Executable.class.getDeclaredField(DECLARED_ANNOTATIONS);
105+
Field field = Method.class.getDeclaredField(DECLARED_ANNOTATIONS);
108106
field.setAccessible(true);
109107
try {
110108
@SuppressWarnings("unchecked")

src/main/java/com/nordstrom/automation/junit/RunChild.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
import java.util.Map;
55
import java.util.concurrent.Callable;
66
import org.junit.Ignore;
7+
import org.junit.Test;
78
import org.junit.runner.notification.RunNotifier;
89
import org.junit.runners.model.FrameworkMethod;
10+
11+
import com.nordstrom.automation.junit.JUnitConfig.JUnitSettings;
12+
913
import net.bytebuddy.implementation.bind.annotation.Argument;
1014
import net.bytebuddy.implementation.bind.annotation.SuperCall;
1115
import net.bytebuddy.implementation.bind.annotation.This;
@@ -47,6 +51,8 @@ public static void intercept(@This final Object runner, @SuperCall final Callabl
4751
Run.pushThreadRunner(runner);
4852
if (child instanceof FrameworkMethod) {
4953
FrameworkMethod method = (FrameworkMethod) child;
54+
55+
applyTimeout(method);
5056
int count = RetryHandler.getMaxRetry(runner, method);
5157
boolean isIgnored = (null != method.getAnnotation(Ignore.class));
5258

@@ -77,4 +83,25 @@ static void finished() {
7783
}
7884
}
7985
}
86+
87+
/**
88+
* If configured for default test timeout, apply the timeout value to the specified framework method if it doesn't
89+
* already specify a longer timeout interval.
90+
*
91+
* @param method {@link FrameworkMethod} object
92+
*/
93+
private static void applyTimeout(FrameworkMethod method) {
94+
// if default test timeout is defined
95+
if (LifecycleHooks.getConfig().containsKey(JUnitSettings.TEST_TIMEOUT.key())) {
96+
// get default test timeout
97+
long defaultTimeout = LifecycleHooks.getConfig().getLong(JUnitSettings.TEST_TIMEOUT.key());
98+
// get @Test annotation
99+
Test annotation = method.getAnnotation(Test.class);
100+
// if annotation declared and current timeout is less than default
101+
if ((annotation != null) && (annotation.timeout() < defaultTimeout)) {
102+
// set test timeout interval
103+
MutableTest.proxyFor(method.getMethod()).setTimeout(defaultTimeout);
104+
}
105+
}
106+
}
80107
}

src/test/java/com/nordstrom/automation/junit/MethodExpectedTimeout.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
import java.util.concurrent.TimeUnit;
66

77
import org.junit.Test;
8-
import com.nordstrom.automation.junit.JUnitConfig.JUnitSettings;
98

109
public class MethodExpectedTimeout {
1110

12-
static {
13-
System.setProperty(JUnitSettings.TEST_TIMEOUT.key(), "500");
14-
}
15-
1611
@Test
1712
public void testTimeout() throws InterruptedException {
1813
System.out.println("testTimeout");

src/test/java/com/nordstrom/automation/junit/MethodTimeoutTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
import org.junit.runner.Result;
1111
import org.junit.runner.notification.Failure;
1212
import org.junit.runners.model.TestTimedOutException;
13+
import org.testng.annotations.AfterClass;
14+
import org.testng.annotations.BeforeClass;
1315
import org.testng.annotations.Test;
1416

17+
import com.nordstrom.automation.junit.JUnitConfig.JUnitSettings;
18+
1519
public class MethodTimeoutTest {
1620

1721
private static final Map<String, String> MESSAGE_MAP;
@@ -22,6 +26,11 @@ public class MethodTimeoutTest {
2226
MESSAGE_MAP.put("testTimeoutWithShorterInterval", "test timed out after 500 milliseconds");
2327
MESSAGE_MAP.put("testTimeoutWithLongerInterval", "test timed out after 600 milliseconds");
2428
}
29+
30+
@BeforeClass
31+
public static void before() {
32+
System.setProperty(JUnitSettings.TEST_TIMEOUT.key(), "500");
33+
}
2534

2635
@Test
2736
public void verifyHappyPath() {
@@ -52,6 +61,11 @@ public void verifyExpectedTimeout() {
5261
verifyFailureMessages(result);
5362
}
5463

64+
@AfterClass
65+
public static void after() {
66+
System.clearProperty(JUnitSettings.TEST_TIMEOUT.key());
67+
}
68+
5569
private static void verifyFailureMessages(Result result) {
5670
for (Failure failure : result.getFailures()) {
5771
String methodName = failure.getDescription().getMethodName();

0 commit comments

Comments
 (0)