Permalink
Browse files

Test refactoring.

  • Loading branch information...
1 parent 349a050 commit 39f80bc02a964fffe1a883d86aa1483b2f841595 @cbeust committed Feb 23, 2011
@@ -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);
+ }
}
@@ -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);
+ }
+
+}
@@ -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);
}
}
@@ -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);
}
}

0 comments on commit 39f80bc

Please sign in to comment.