You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2011/07/25 17:22:33 UTC
svn commit: r1150747 - in /tomcat/trunk/test/org/apache: catalina/valves/
coyote/http11/ juli/ naming/resources/ tomcat/util/buf/ tomcat/util/http/
tomcat/util/http/mapper/ tomcat/util/res/ tomcat/util/threads/
Author: kkolinko
Date: Mon Jul 25 15:22:30 2011
New Revision: 1150747
URL: http://svn.apache.org/viewvc?rev=1150747&view=rev
Log:
Converted the tests to JUnit 4.
Modified:
tomcat/trunk/test/org/apache/catalina/valves/Benchmarks.java
tomcat/trunk/test/org/apache/catalina/valves/TestRemoteIpValve.java
tomcat/trunk/test/org/apache/coyote/http11/TestGzipOutputFilter.java
tomcat/trunk/test/org/apache/juli/TestClassLoaderLogManager.java
tomcat/trunk/test/org/apache/naming/resources/TestDirContextURLStreamHandlerFactory.java
tomcat/trunk/test/org/apache/tomcat/util/buf/TestByteChunk.java
tomcat/trunk/test/org/apache/tomcat/util/http/TestCookies.java
tomcat/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java
tomcat/trunk/test/org/apache/tomcat/util/res/TestStringManager.java
tomcat/trunk/test/org/apache/tomcat/util/threads/DedicatedThreadExecutorTest.java
tomcat/trunk/test/org/apache/tomcat/util/threads/TestLimitLatch.java
Modified: tomcat/trunk/test/org/apache/catalina/valves/Benchmarks.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/valves/Benchmarks.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/valves/Benchmarks.java (original)
+++ tomcat/trunk/test/org/apache/catalina/valves/Benchmarks.java Mon Jul 25 15:22:30 2011
@@ -20,7 +20,7 @@ package org.apache.catalina.valves;
import java.text.SimpleDateFormat;
import java.util.Date;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Some simple micro-benchmarks to help determine best approach for thread
@@ -28,7 +28,8 @@ import junit.framework.TestCase;
* JUnit tests to make the simple to execute but does not used Test* as the
* class name to avoid being included in the automated unit tests.
*/
-public class Benchmarks extends TestCase {
+public class Benchmarks {
+ @Test
public void testAccessLogGetDate() throws Exception {
// Is it better to use a sync or a thread local here?
BenchmarkTest benchmark = new BenchmarkTest();
@@ -171,6 +172,7 @@ public class Benchmarks extends TestCase
}
}
+ @Test
public void testAccessLogTimeDateElement() throws Exception {
// Is it better to use a sync or a thread local here?
BenchmarkTest benchmark = new BenchmarkTest();
Modified: tomcat/trunk/test/org/apache/catalina/valves/TestRemoteIpValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/valves/TestRemoteIpValve.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/valves/TestRemoteIpValve.java (original)
+++ tomcat/trunk/test/org/apache/catalina/valves/TestRemoteIpValve.java Mon Jul 25 15:22:30 2011
@@ -24,7 +24,13 @@ import java.util.List;
import javax.servlet.ServletException;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
@@ -32,7 +38,7 @@ import org.apache.catalina.connector.Res
/**
* {@link RemoteIpValve} Tests
*/
-public class TestRemoteIpValve extends TestCase {
+public class TestRemoteIpValve {
static class RemoteAddrAndHostTrackerValve extends ValveBase {
private String remoteAddr;
@@ -78,23 +84,27 @@ public class TestRemoteIpValve extends T
}
}
+ @Test
public void testListToCommaDelimitedString() {
List<String> elements = Arrays.asList("element1", "element2", "element3");
String actual = RemoteIpValve.listToCommaDelimitedString(elements);
assertEquals("element1, element2, element3", actual);
}
+ @Test
public void testListToCommaDelimitedStringEmptyList() {
List<String> elements = new ArrayList<String>();
String actual = RemoteIpValve.listToCommaDelimitedString(elements);
assertEquals("", actual);
}
+ @Test
public void testCommaDelimitedListToStringArrayNullList() {
String actual = RemoteIpValve.listToCommaDelimitedString(null);
assertEquals("", actual);
}
+ @Test
public void testInvokeAllowedRemoteAddrWithNullRemoteIpHeader() throws Exception {
// PREPARE
RemoteIpValve remoteIpValve = new RemoteIpValve();
@@ -134,6 +144,7 @@ public class TestRemoteIpValve extends T
}
+ @Test
public void testInvokeAllProxiesAreTrusted() throws Exception {
// PREPARE
@@ -174,6 +185,7 @@ public class TestRemoteIpValve extends T
assertEquals("postInvoke remoteAddr", "remote-host-original-value", actualPostInvokeRemoteHost);
}
+ @Test
public void testInvokeAllProxiesAreTrustedOrInternal() throws Exception {
// PREPARE
@@ -215,6 +227,7 @@ public class TestRemoteIpValve extends T
assertEquals("postInvoke remoteAddr", "remote-host-original-value", actualPostInvokeRemoteHost);
}
+ @Test
public void testInvokeAllProxiesAreInternal() throws Exception {
// PREPARE
@@ -255,6 +268,7 @@ public class TestRemoteIpValve extends T
assertEquals("postInvoke remoteAddr", "remote-host-original-value", actualPostInvokeRemoteHost);
}
+ @Test
public void testInvokeAllProxiesAreTrustedAndRemoteAddrMatchRegexp() throws Exception {
// PREPARE
@@ -297,6 +311,7 @@ public class TestRemoteIpValve extends T
assertEquals("postInvoke remoteAddr", "remote-host-original-value", actualPostInvokeRemoteHost);
}
+ @Test
public void testInvokeXforwardedProtoSaysHttpsForIncomingHttpRequest() throws Exception {
// PREPARE
@@ -349,10 +364,10 @@ public class TestRemoteIpValve extends T
assertEquals("x-forwarded-proto says https", 443, actualServerPort);
boolean actualSecure = remoteAddrAndHostTrackerValve.isSecure();
- assertEquals("x-forwarded-proto says https", true, actualSecure);
+ assertTrue("x-forwarded-proto says https", actualSecure);
boolean actualPostInvokeSecure = request.isSecure();
- assertEquals("postInvoke secure", false, actualPostInvokeSecure);
+ assertFalse("postInvoke secure", actualPostInvokeSecure);
int actualPostInvokeServerPort = request.getServerPort();
assertEquals("postInvoke serverPort", 8080, actualPostInvokeServerPort);
@@ -361,6 +376,7 @@ public class TestRemoteIpValve extends T
assertEquals("postInvoke scheme", "http", actualPostInvokeScheme);
}
+ @Test
public void testInvokeXforwardedProtoIsNullForIncomingHttpRequest() throws Exception {
// PREPARE
@@ -413,10 +429,10 @@ public class TestRemoteIpValve extends T
assertEquals("x-forwarded-proto is null", 8080, actualServerPort);
boolean actualSecure = remoteAddrAndHostTrackerValve.isSecure();
- assertEquals("x-forwarded-proto is null", false, actualSecure);
+ assertFalse("x-forwarded-proto is null", actualSecure);
boolean actualPostInvokeSecure = request.isSecure();
- assertEquals("postInvoke secure", false, actualPostInvokeSecure);
+ assertFalse("postInvoke secure", actualPostInvokeSecure);
int actualPostInvokeServerPort = request.getServerPort();
assertEquals("postInvoke serverPort", 8080, actualPostInvokeServerPort);
@@ -425,6 +441,7 @@ public class TestRemoteIpValve extends T
assertEquals("postInvoke scheme", "http", actualPostInvokeScheme);
}
+ @Test
public void testInvokeXforwardedProtoSaysHttpForIncomingHttpsRequest() throws Exception {
// PREPARE
@@ -477,10 +494,10 @@ public class TestRemoteIpValve extends T
assertEquals("x-forwarded-proto says http", 80, actualServerPort);
boolean actualSecure = remoteAddrAndHostTrackerValve.isSecure();
- assertEquals("x-forwarded-proto says http", false, actualSecure);
+ assertFalse("x-forwarded-proto says http", actualSecure);
boolean actualPostInvokeSecure = request.isSecure();
- assertEquals("postInvoke secure", true, actualPostInvokeSecure);
+ assertTrue("postInvoke secure", actualPostInvokeSecure);
int actualPostInvokeServerPort = request.getServerPort();
assertEquals("postInvoke serverPort", 8443, actualPostInvokeServerPort);
@@ -489,6 +506,7 @@ public class TestRemoteIpValve extends T
assertEquals("postInvoke scheme", "https", actualPostInvokeScheme);
}
+ @Test
public void testInvokeXforwardedProtoIsNullForIncomingHttpsRequest() throws Exception {
// PREPARE
@@ -541,10 +559,10 @@ public class TestRemoteIpValve extends T
assertEquals("x-forwarded-proto is null", 8443, actualServerPort);
boolean actualSecure = remoteAddrAndHostTrackerValve.isSecure();
- assertEquals("x-forwarded-proto is null", true, actualSecure);
+ assertTrue("x-forwarded-proto is null", actualSecure);
boolean actualPostInvokeSecure = request.isSecure();
- assertEquals("postInvoke secure", true, actualPostInvokeSecure);
+ assertTrue("postInvoke secure", actualPostInvokeSecure);
int actualPostInvokeServerPort = request.getServerPort();
assertEquals("postInvoke serverPort", 8443, actualPostInvokeServerPort);
@@ -553,6 +571,7 @@ public class TestRemoteIpValve extends T
assertEquals("postInvoke scheme", "https", actualPostInvokeScheme);
}
+ @Test
public void testInvokeNotAllowedRemoteAddr() throws Exception {
// PREPARE
RemoteIpValve remoteIpValve = new RemoteIpValve();
@@ -592,6 +611,7 @@ public class TestRemoteIpValve extends T
assertEquals("postInvoke remoteAddr", "not-allowed-internal-proxy-host", actualPostInvokeRemoteHost);
}
+ @Test
public void testInvokeUntrustedProxyInTheChain() throws Exception {
// PREPARE
RemoteIpValve remoteIpValve = new RemoteIpValve();
@@ -632,6 +652,7 @@ public class TestRemoteIpValve extends T
assertEquals("postInvoke remoteAddr", "remote-host-original-value", actualPostInvokeRemoteHost);
}
+ @Test
public void testCommaDelimitedListToStringArray() {
String[] actual = RemoteIpValve.commaDelimitedListToStringArray("element1, element2, element3");
String[] expected = new String[] {
@@ -640,6 +661,7 @@ public class TestRemoteIpValve extends T
assertArrayEquals(expected, actual);
}
+ @Test
public void testCommaDelimitedListToStringArrayMixedSpaceChars() {
String[] actual = RemoteIpValve.commaDelimitedListToStringArray("element1 , element2,\t element3");
String[] expected = new String[] {
Modified: tomcat/trunk/test/org/apache/coyote/http11/TestGzipOutputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/TestGzipOutputFilter.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/TestGzipOutputFilter.java (original)
+++ tomcat/trunk/test/org/apache/coyote/http11/TestGzipOutputFilter.java Mon Jul 25 15:22:30 2011
@@ -20,7 +20,9 @@ package org.apache.coyote.http11;
import java.io.ByteArrayOutputStream;
import java.util.zip.GZIPOutputStream;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import org.apache.coyote.Response;
import org.apache.coyote.http11.filters.GzipOutputFilter;
@@ -30,7 +32,7 @@ import org.apache.tomcat.util.buf.ByteCh
* Test case to demonstrate the interaction between gzip and flushing in the
* output filter.
*/
-public class TestGzipOutputFilter extends TestCase {
+public class TestGzipOutputFilter {
/**
* Test the interaction betwen gzip and flushing. The idea is to: 1. create
@@ -46,6 +48,7 @@ public class TestGzipOutputFilter extend
*
* @throws Exception
*/
+ @Test
public void testFlushingWithGzip() throws Exception {
// set up response, InternalOutputBuffer, and ByteArrayOutputStream
Response res = new Response();
Modified: tomcat/trunk/test/org/apache/juli/TestClassLoaderLogManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/juli/TestClassLoaderLogManager.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/juli/TestClassLoaderLogManager.java (original)
+++ tomcat/trunk/test/org/apache/juli/TestClassLoaderLogManager.java Mon Jul 25 15:22:30 2011
@@ -17,13 +17,16 @@
package org.apache.juli;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Test cases for {@link ClassLoaderLogManager}.
*/
-public class TestClassLoaderLogManager extends TestCase {
+public class TestClassLoaderLogManager {
+ @Test
public void testReplace() {
ClassLoaderLogManager logManager = new ClassLoaderLogManager();
assertEquals("", logManager.replace(""));
Modified: tomcat/trunk/test/org/apache/naming/resources/TestDirContextURLStreamHandlerFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/naming/resources/TestDirContextURLStreamHandlerFactory.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/naming/resources/TestDirContextURLStreamHandlerFactory.java (original)
+++ tomcat/trunk/test/org/apache/naming/resources/TestDirContextURLStreamHandlerFactory.java Mon Jul 25 15:22:30 2011
@@ -21,10 +21,14 @@ import java.net.URL;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
-public class TestDirContextURLStreamHandlerFactory extends TestCase {
+import org.junit.Test;
+public class TestDirContextURLStreamHandlerFactory {
+
+ @Test
public void testUserSuppliedFactory() throws Exception {
URL url = null;
Modified: tomcat/trunk/test/org/apache/tomcat/util/buf/TestByteChunk.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/buf/TestByteChunk.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/buf/TestByteChunk.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/buf/TestByteChunk.java Mon Jul 25 15:22:30 2011
@@ -20,13 +20,17 @@ package org.apache.tomcat.util.buf;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
/**
* Test cases for {@link ByteChunk}.
*/
-public class TestByteChunk extends TestCase {
+public class TestByteChunk {
+ @Test
public void testConvertToBytes() throws UnsupportedEncodingException {
String string = "HTTP/1.1 100 Continue\r\n";
byte[] bytes = ByteChunk.convertToBytes(string);
@@ -43,6 +47,7 @@ public class TestByteChunk extends TestC
* any chars outside of the range. {@code ByteChunk.findByte()} works for
* any ISO-8859-1 chars.
*/
+ @Test
public void testFindByte() throws UnsupportedEncodingException {
// 0xa0 = 160 = character
byte[] bytes = "Hello\u00a0world".getBytes("ISO-8859-1");
@@ -68,6 +73,7 @@ public class TestByteChunk extends TestC
assertEquals(-1, ByteChunk.indexOf(bytes, 5, 5, 'w'));
}
+ @Test
public void testIndexOf_Char() throws UnsupportedEncodingException {
byte[] bytes = "Hello\u00a0world".getBytes("ISO-8859-1");
final int len = bytes.length;
@@ -89,6 +95,7 @@ public class TestByteChunk extends TestC
assertEquals(-1, bc.indexOf('d', 0));
}
+ @Test
public void testIndexOf_String() throws UnsupportedEncodingException {
byte[] bytes = "Hello\u00a0world".getBytes("ISO-8859-1");
final int len = bytes.length;
@@ -113,6 +120,7 @@ public class TestByteChunk extends TestC
assertEquals(-1, bc.indexOf("d", 0, 1, 0));
}
+ @Test
public void testFindBytes() throws UnsupportedEncodingException {
byte[] bytes = "Hello\u00a0world".getBytes("ISO-8859-1");
final int len = bytes.length;
@@ -129,6 +137,7 @@ public class TestByteChunk extends TestC
assertEquals(-1, ByteChunk.findBytes(bytes, 2, 5, new byte[] { 'w' }));
}
+ @Test
public void testFindNotBytes() throws UnsupportedEncodingException {
byte[] bytes = "Hello\u00a0world".getBytes("ISO-8859-1");
final int len = bytes.length;
Modified: tomcat/trunk/test/org/apache/tomcat/util/http/TestCookies.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/TestCookies.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/http/TestCookies.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/http/TestCookies.java Mon Jul 25 15:22:30 2011
@@ -17,10 +17,11 @@
package org.apache.tomcat.util.http;
-import junit.framework.TestCase;
+import org.junit.Test;
-public class TestCookies extends TestCase {
+public class TestCookies {
+ @Test
public void testCookies() throws Exception {
test("foo=bar; a=b", "foo", "bar", "a", "b");
test("foo=bar;a=b", "foo", "bar", "a", "b");
@@ -99,7 +100,7 @@ public class TestCookies extends TestCas
test("$Version=0;foo=bar", 0);
}
-
+ @Test
public void testNameOnlyCookies() throws Exception {
// Bug 49000
test("fred=1; jim=2; bob", "fred", "1", "jim", "2");
Modified: tomcat/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java Mon Jul 25 15:22:30 2011
@@ -16,16 +16,20 @@
*/
package org.apache.tomcat.util.http.mapper;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
import org.apache.tomcat.util.buf.MessageBytes;
-public class TestMapper extends TestCase {
+public class TestMapper {
private Mapper mapper;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
mapper = new Mapper();
mapper.addHost("sjbjdvwsbvhrb", new String[0], "blah1");
@@ -77,8 +81,8 @@ public class TestMapper extends TestCase
mapper.addWrapper("iowejoiejfoiew", "/foo/bar/bla", "0", "/bobou/*",
"wrapper7", false, false);
}
-
+ @Test
public void testAddHost() throws Exception {
// Check we have the right number (add 16 but one is a duplicate)
assertEquals(15, mapper.hosts.length);
@@ -95,8 +99,8 @@ public class TestMapper extends TestCase
assertTrue(previous.compareTo(current) < 0);
}
}
-
-
+
+ @Test
public void testMap() throws Exception {
MappingData mappingData = new MappingData();
MessageBytes host = MessageBytes.newInstance();
@@ -129,8 +133,8 @@ public class TestMapper extends TestCase
assertEquals("/foo", mappingData.pathInfo.toString());
assertTrue(mappingData.redirectPath.isNull());
}
-
-
+
+ @Test
public void testPerformance() throws Exception {
MappingData mappingData = new MappingData();
MessageBytes host = MessageBytes.newInstance();
Modified: tomcat/trunk/test/org/apache/tomcat/util/res/TestStringManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/res/TestStringManager.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/res/TestStringManager.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/res/TestStringManager.java Mon Jul 25 15:22:30 2011
@@ -17,13 +17,16 @@
package org.apache.tomcat.util.res;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertTrue;
-public class TestStringManager extends TestCase {
+import org.junit.Test;
+
+public class TestStringManager {
private static final StringManager sm =
StringManager.getManager("org.apache.naming");
+ @Test
public void testNullKey() {
boolean iaeThrown = false;
@@ -32,9 +35,10 @@ public class TestStringManager extends T
} catch (IllegalArgumentException iae) {
iaeThrown = true;
}
- assertEquals("IAE not thrown on null key", true, iaeThrown);
+ assertTrue("IAE not thrown on null key", iaeThrown);
}
-
+
+ @Test
public void testBug46933() {
// Check null args are OK
sm.getString("namingContext.nameNotBound");
Modified: tomcat/trunk/test/org/apache/tomcat/util/threads/DedicatedThreadExecutorTest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/threads/DedicatedThreadExecutorTest.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/threads/DedicatedThreadExecutorTest.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/threads/DedicatedThreadExecutorTest.java Mon Jul 25 15:22:30 2011
@@ -18,11 +18,17 @@ package org.apache.tomcat.util.threads;
import java.util.concurrent.Callable;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
-public class DedicatedThreadExecutorTest extends TestCase {
+import org.junit.Test;
+
+public class DedicatedThreadExecutorTest {
private Thread dedicatedThread;
+ @Test
public void testExecute() {
final Thread testingThread = Thread.currentThread();
DedicatedThreadExecutor executor = new DedicatedThreadExecutor();
@@ -30,8 +36,7 @@ public class DedicatedThreadExecutorTest
@Override
public Long call() throws Exception {
dedicatedThread = Thread.currentThread();
- DedicatedThreadExecutorTest.assertNotSame(testingThread,
- dedicatedThread);
+ assertNotSame(testingThread, dedicatedThread);
return Long.valueOf(123);
}
});
@@ -41,8 +46,7 @@ public class DedicatedThreadExecutorTest
executor.execute(new Callable<Void>() {
@Override
public Void call() throws Exception {
- DedicatedThreadExecutorTest.assertSame(dedicatedThread,
- Thread.currentThread());
+ assertSame(dedicatedThread, Thread.currentThread());
return null;
}
});
@@ -51,6 +55,7 @@ public class DedicatedThreadExecutorTest
assertFalse(dedicatedThread.isAlive());
}
+ @Test
public void testExecuteInOwnThread() {
final Thread testingThread = Thread.currentThread();
Long result =
@@ -58,8 +63,7 @@ public class DedicatedThreadExecutorTest
@Override
public Long call() throws Exception {
dedicatedThread = Thread.currentThread();
- DedicatedThreadExecutorTest.assertNotSame(testingThread,
- dedicatedThread);
+ assertNotSame(testingThread, dedicatedThread);
return Long.valueOf(456);
}
});
Modified: tomcat/trunk/test/org/apache/tomcat/util/threads/TestLimitLatch.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/tomcat/util/threads/TestLimitLatch.java?rev=1150747&r1=1150746&r2=1150747&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/tomcat/util/threads/TestLimitLatch.java (original)
+++ tomcat/trunk/test/org/apache/tomcat/util/threads/TestLimitLatch.java Mon Jul 25 15:22:30 2011
@@ -16,20 +16,23 @@
*/
package org.apache.tomcat.util.threads;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
-public class TestLimitLatch extends TestCase {
+import org.junit.Test;
+public class TestLimitLatch {
+
+ @Test
public void testNoThreads() throws Exception {
LimitLatch latch = new LimitLatch(0);
- assertEquals("No threads should be waiting", false,
- latch.hasQueuedThreads());
+ assertFalse("No threads should be waiting", latch.hasQueuedThreads());
}
+ @Test
public void testOneThreadNoWait() throws Exception {
LimitLatch latch = new LimitLatch(1);
- assertEquals("No threads should be waiting", false,
- latch.hasQueuedThreads());
+ assertFalse("No threads should be waiting", latch.hasQueuedThreads());
Thread testThread = new TestThread(latch);
testThread.start();
Thread.sleep(50);
@@ -37,14 +40,13 @@ public class TestLimitLatch extends Test
latch.getQueuedThreads().size());
latch.countUpOrAwait();
Thread.sleep(50);
- assertEquals("No threads should be waiting", false,
- latch.hasQueuedThreads());
+ assertFalse("No threads should be waiting", latch.hasQueuedThreads());
}
+ @Test
public void testOneThreadWaitCountUp() throws Exception {
LimitLatch latch = new LimitLatch(1);
- assertEquals("No threads should be waiting", false,
- latch.hasQueuedThreads());
+ assertFalse("No threads should be waiting", latch.hasQueuedThreads());
Thread testThread = new TestThread(latch);
latch.countUpOrAwait();
testThread.start();
@@ -53,14 +55,13 @@ public class TestLimitLatch extends Test
latch.getQueuedThreads().size());
latch.countDown();
Thread.sleep(50);
- assertEquals("No threads should be waiting", false,
- latch.hasQueuedThreads());
+ assertFalse("No threads should be waiting", latch.hasQueuedThreads());
}
+ @Test
public void testOneRelease() throws Exception {
LimitLatch latch = new LimitLatch(1);
- assertEquals("No threads should be waiting", false,
- latch.hasQueuedThreads());
+ assertFalse("No threads should be waiting", latch.hasQueuedThreads());
Thread testThread = new TestThread(latch);
latch.countUpOrAwait();
testThread.start();
@@ -69,14 +70,13 @@ public class TestLimitLatch extends Test
latch.getQueuedThreads().size());
latch.releaseAll();
Thread.sleep(50);
- assertEquals("No threads should be waiting", false,
- latch.hasQueuedThreads());
+ assertFalse("No threads should be waiting", latch.hasQueuedThreads());
}
+ @Test
public void testTenWait() throws Exception {
LimitLatch latch = new LimitLatch(10);
- assertEquals("No threads should be waiting", false,
- latch.hasQueuedThreads());
+ assertFalse("No threads should be waiting", latch.hasQueuedThreads());
Thread[] testThread = new TestThread[30];
for (int i = 0; i < 30; i++) {
testThread[i] = new TestThread(latch, 1000);
@@ -89,8 +89,7 @@ public class TestLimitLatch extends Test
assertEquals("10 threads should be waiting", 10,
latch.getQueuedThreads().size());
Thread.sleep(1000);
- assertEquals("No threads should be waiting", false,
- latch.hasQueuedThreads());
+ assertFalse("No threads should be waiting", latch.hasQueuedThreads());
}
private class TestThread extends Thread {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org