Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test refactoring.

  • Loading branch information...
commit 39f80bc02a964fffe1a883d86aa1483b2f841595 1 parent 349a050
@cbeust authored
View
5 src/test/java/test/thread/BaseThreadTest.java
@@ -1,5 +1,6 @@
package test.thread;
+import org.testng.Assert;
import org.testng.collections.Maps;
import org.testng.internal.annotations.Sets;
@@ -47,4 +48,8 @@ protected void log(String cls, String s) {
}
}
+ protected void verifyThreads(int expected) {
+ Assert.assertEquals(getThreadCount(), expected,
+ "Ran on " + getThreadCount() + " instead of " + expected);
+ }
}
View
18 src/test/java/test/thread/ThreadPoolSizeBase.java
@@ -0,0 +1,18 @@
+package test.thread;
+
+import org.testng.annotations.BeforeClass;
+
+public class ThreadPoolSizeBase extends BaseThreadTest {
+ @BeforeClass
+ public void setUp() {
+ log(getClass().getName(), "Init log ids");
+ initThreadLog();
+ }
+
+ protected void logThread() {
+ long n = Thread.currentThread().getId();
+ log(getClass().getName(), "threadPoolSize:3");
+ logThread(n);
+ }
+
+}
View
18 src/test/java/test/thread/ThreadPoolSizeTest.java
@@ -1,28 +1,16 @@
package test.thread;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-public class ThreadPoolSizeTest extends BaseThreadTest {
- @BeforeClass
- public void setUp() {
- log(getClass().getName(), "Init log ids");
- initThreadLog();
- }
-
+public class ThreadPoolSizeTest extends ThreadPoolSizeBase {
@Test(invocationCount = 5, threadPoolSize = 3)
public void f1() {
- long n = Thread.currentThread().getId();
- log(getClass().getName(), "threadPoolSize:20");
- logThread(n);
+ logThread();
}
@Test(dependsOnMethods = {"f1"})
public void verify() {
- int expected = 3;
- Assert.assertEquals(getThreadCount(), expected,
- "Should have run on " + expected + " threads but ran on " + getThreadCount());
+ verifyThreads(3);
}
}
View
17 src/test/java/test/thread/ThreadPoolSizeWithTimeOutTest.java
@@ -1,28 +1,17 @@
package test.thread;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-public class ThreadPoolSizeWithTimeOutTest extends BaseThreadTest {
- @BeforeClass
- public void setUp() {
- log(getClass().getName(), "Init log ids");
- initThreadLog();
- }
+public class ThreadPoolSizeWithTimeOutTest extends ThreadPoolSizeBase {
@Test(invocationCount = 5, threadPoolSize = 3, timeOut = 1000)
public void f1() {
- long n = Thread.currentThread().getId();
- log(getClass().getName(), "threadPoolSize:20");
- logThread(n);
+ logThread();
}
@Test(dependsOnMethods = {"f1"})
public void verify() {
- int expected = 3;
- Assert.assertEquals(getThreadCount(), expected,
- "Should have run on " + expected + " threads but ran on " + getThreadCount());
+ verifyThreads(3);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.