308866 Update test suite to JUnit4 - Module jetty-util

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1818 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Michael Gorovoy 2010-05-18 02:43:31 +00:00
parent f5559e3f3a
commit 14d997de30
26 changed files with 317 additions and 296 deletions

View File

@ -1,4 +1,5 @@
jetty-SNAPSHOT
+ 308866 Update test suite to JUnit4 - Module jetty-util
+ 313196 randomly allocate ports for session test.
jetty-7.1.1.v20100517

View File

@ -66,6 +66,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit4-version}</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -13,11 +13,16 @@
package org.eclipse.jetty.util;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ArrayQueueTest extends TestCase
import org.junit.Test;
public class ArrayQueueTest
{
@Test
public void testWrap() throws Exception
{
ArrayQueue<String> queue = new ArrayQueue<String>(3,3);
@ -63,6 +68,7 @@ public class ArrayQueueTest extends TestCase
}
@Test
public void testRemove() throws Exception
{
ArrayQueue<String> queue = new ArrayQueue<String>(3,3);
@ -82,6 +88,7 @@ public class ArrayQueueTest extends TestCase
assertEquals(i+"!",queue.get(i));
}
@Test
public void testGrow() throws Exception
{
ArrayQueue<String> queue = new ArrayQueue<String>(3,5);
@ -123,10 +130,9 @@ public class ArrayQueueTest extends TestCase
for (int i=0;i<12;i++)
queue.add(""+('a'+i));
assertEquals(13,queue.getCapacity());
}
@Test
public void testFullEmpty() throws Exception
{
ArrayQueue<String> queue = new ArrayQueue<String>(2);

View File

@ -13,17 +13,22 @@
package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.HashSet;
import java.util.Random;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.junit.Test;
public class BlockingArrayQueueTest extends TestCase
public class BlockingArrayQueueTest
{
@Test
public void testWrap() throws Exception
{
BlockingArrayQueue<String> queue = new BlockingArrayQueue<String>(3);
@ -66,6 +71,7 @@ public class BlockingArrayQueueTest extends TestCase
}
@Test
public void testRemove() throws Exception
{
BlockingArrayQueue<String> queue = new BlockingArrayQueue<String>(3,3);
@ -85,6 +91,7 @@ public class BlockingArrayQueueTest extends TestCase
assertEquals(i+"!",queue.get(i));
}
@Test
public void testGrow() throws Exception
{
BlockingArrayQueue<String> queue = new BlockingArrayQueue<String>(3,2);
@ -128,11 +135,9 @@ public class BlockingArrayQueueTest extends TestCase
s+=2;
c+=2;
}
}
@Test
public void testTake() throws Exception
{
final String[] data=new String[4];
@ -178,6 +183,7 @@ public class BlockingArrayQueueTest extends TestCase
volatile boolean _running;
@Test
public void testConcurrentAccess() throws Exception
{
final int THREADS=50;
@ -306,9 +312,5 @@ public class BlockingArrayQueueTest extends TestCase
HashSet<Integer> consSet = new HashSet<Integer>(consumed);
assertEquals(prodSet,consSet);
}
}

View File

@ -13,37 +13,23 @@
package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Locale;
import java.util.TimeZone;
import junit.framework.TestSuite;
import org.junit.Test;
/* ------------------------------------------------------------ */
/** Util meta Tests.
*
*/
public class DateCacheTest extends junit.framework.TestCase
public class DateCacheTest
{
public DateCacheTest(String name)
{
super(name);
}
public static junit.framework.Test suite() {
TestSuite suite = new TestSuite(DateCacheTest.class);
return suite;
}
/* ------------------------------------------------------------ */
/** main.
*/
public static void main(String[] args)
{
junit.textui.TestRunner.run(suite());
}
/* ------------------------------------------------------------ */
@Test
public void testDateCache() throws Exception
{
//@WAS: Test t = new Test("org.eclipse.jetty.util.DateCache");

View File

@ -13,32 +13,28 @@
package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import junit.framework.TestCase;
import org.junit.Test;
/**
*
*
*/
public class LazyListTest extends TestCase
public class LazyListTest
{
/**
* Constructor for LazyListTest.
* @param arg0
*/
public LazyListTest(String arg0)
{
super(arg0);
}
/*
* Test for Object add(Object, Object)
*/
@Test
public void testAddObjectObject()
{
Object list=null;
@ -79,6 +75,7 @@ public class LazyListTest extends TestCase
/*
* Test for Object add(Object, int, Object)
*/
@Test
public void testAddObjectintObject()
{
Object list=null;
@ -100,7 +97,7 @@ public class LazyListTest extends TestCase
assertTrue(list instanceof List);
}
@Test
public void testAddCollection()
{
ArrayList l=new ArrayList();
@ -118,6 +115,7 @@ public class LazyListTest extends TestCase
assertEquals("b",LazyList.get(list,3));
}
@Test
public void testEnsureSize()
{
assertTrue(LazyList.ensureSize(null,10)!=null);
@ -134,6 +132,7 @@ public class LazyListTest extends TestCase
/*
* Test for Object remove(Object, Object)
*/
@Test
public void testRemoveObjectObject()
{
Object list=null;
@ -166,6 +165,7 @@ public class LazyListTest extends TestCase
/*
* Test for Object remove(Object, int)
*/
@Test
public void testRemoveObjectint()
{
Object list=null;
@ -197,6 +197,7 @@ public class LazyListTest extends TestCase
/*
* Test for List getList(Object)
*/
@Test
public void testGetListObject()
{
assertEquals(0,LazyList.getList(null).size());
@ -211,12 +212,14 @@ public class LazyListTest extends TestCase
/*
* Test for List getList(Object, boolean)
*/
@Test
public void testGetListObjectboolean()
{
assertEquals(0,LazyList.getList(null,false).size());
assertEquals(null,LazyList.getList(null,true));
}
@Test
public void testToStringArray()
{
assertEquals(0,LazyList.toStringArray(null).length);
@ -237,6 +240,7 @@ public class LazyListTest extends TestCase
}
@Test
public void testSize()
{
ArrayList l=new ArrayList();
@ -249,6 +253,7 @@ public class LazyListTest extends TestCase
assertEquals(2,LazyList.size(l));
}
@Test
public void testGet()
{
testAddObjectObject();
@ -274,6 +279,7 @@ public class LazyListTest extends TestCase
}
}
@Test
public void testContains()
{
ArrayList l=new ArrayList();
@ -289,8 +295,7 @@ public class LazyListTest extends TestCase
}
@Test
public void testIterator()
{
ArrayList l=new ArrayList();
@ -312,6 +317,7 @@ public class LazyListTest extends TestCase
assertFalse(i.hasNext());
}
@Test
public void testListIterator()
{
ArrayList l=new ArrayList();
@ -341,6 +347,7 @@ public class LazyListTest extends TestCase
assertEquals("a",i.previous());
}
@Test
public void testCloneToString()
{
ArrayList l=new ArrayList();

View File

@ -3,9 +3,16 @@ package org.eclipse.jetty.util;
import java.io.IOException;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class MultiExceptionTest extends TestCase
import org.junit.Test;
public class MultiExceptionTest
{
@Test
public void testEmpty() throws Exception
{
MultiException me = new MultiException();
@ -16,6 +23,7 @@ public class MultiExceptionTest extends TestCase
me.ifExceptionThrowRuntime();
}
@Test
public void testOne() throws Exception
{
MultiException me = new MultiException();
@ -69,6 +77,7 @@ public class MultiExceptionTest extends TestCase
}
}
@Test
public void testTwo() throws Exception
{
MultiException me = new MultiException();

View File

@ -13,27 +13,23 @@
package org.eclipse.jetty.util;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
*
*
*/
public class QuotedStringTokenizerTest extends TestCase
public class QuotedStringTokenizerTest
{
/**
* Constructor for QuotedStringTokenizerTest.
* @param arg0
*/
public QuotedStringTokenizerTest(String arg0)
{
super(arg0);
}
/*
* Test for String nextToken()
*/
@Test
public void testTokenizer0()
{
QuotedStringTokenizer tok =
@ -44,6 +40,7 @@ public class QuotedStringTokenizerTest extends TestCase
/*
* Test for String nextToken()
*/
@Test
public void testTokenizer1()
{
QuotedStringTokenizer tok =
@ -55,6 +52,7 @@ public class QuotedStringTokenizerTest extends TestCase
/*
* Test for String nextToken()
*/
@Test
public void testTokenizer2()
{
QuotedStringTokenizer tok =
@ -70,6 +68,7 @@ public class QuotedStringTokenizerTest extends TestCase
/*
* Test for String nextToken()
*/
@Test
public void testTokenizer3()
{
QuotedStringTokenizer tok;
@ -91,6 +90,7 @@ public class QuotedStringTokenizerTest extends TestCase
checkTok(tok,true,true);
}
@Test
public void testQuote()
{
StringBuffer buf = new StringBuffer();
@ -120,6 +120,7 @@ public class QuotedStringTokenizerTest extends TestCase
/*
* Test for String nextToken()
*/
@Test
public void testTokenizer4()
{
QuotedStringTokenizer tok = new QuotedStringTokenizer("abc'def,ghi'jkl",",");
@ -150,6 +151,7 @@ public class QuotedStringTokenizerTest extends TestCase
/*
* Test for String quote(String, String)
*/
@Test
public void testQuoteString()
{
assertEquals("abc",QuotedStringTokenizer.quote("abc", " ,"));
@ -158,7 +160,7 @@ public class QuotedStringTokenizerTest extends TestCase
assertEquals("\"a\\n\\r\\t\"",QuotedStringTokenizer.quote("a\n\r\t"));
}
@Test
public void testUnquote()
{
assertEquals("abc",QuotedStringTokenizer.unquote("abc"));

View File

@ -13,6 +13,10 @@
package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
@ -20,37 +24,28 @@ import java.io.ObjectOutputStream;
import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
/**
*
*
*/
public class StringMapTest extends TestCase
public class StringMapTest
{
StringMap m0;
StringMap m1;
StringMap m5;
StringMap m5i;
/**
* Constructor for StringMapTest.
* @param arg0
*/
public StringMapTest(String arg0)
{
super(arg0);
}
/*
* @see TestCase#setUp()
*/
@Override
protected void setUp() throws Exception
{
super.setUp();
@Before
public void setUp() throws Exception
{
m0=new StringMap();
m1=new StringMap(false);
m1.put("abc", "0");
@ -70,15 +65,7 @@ public class StringMapTest extends TestCase
m5i.put("bbb", null);
}
/*
* @see TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception
{
super.tearDown();
}
@Test
public void testSize()
{
assertEquals(0, m0.size());
@ -96,6 +83,7 @@ public class StringMapTest extends TestCase
assertEquals(5, m5i.size());
}
@Test
public void testIsEmpty()
{
assertTrue(m0.isEmpty());
@ -104,6 +92,7 @@ public class StringMapTest extends TestCase
assertFalse(m5i.isEmpty());
}
@Test
public void testClear()
{
m0.clear();
@ -123,6 +112,7 @@ public class StringMapTest extends TestCase
/*
* Test for Object put(Object, Object)
*/
@Test
public void testPutGet()
{
assertEquals("2",m5.get("abc"));
@ -146,11 +136,10 @@ public class StringMapTest extends TestCase
}
/*
* Test for Map.Entry getEntry(String, int, int)
*/
@Test
public void testGetEntryStringintint()
{
Map.Entry entry;
@ -187,6 +176,7 @@ public class StringMapTest extends TestCase
/*
* Test for Map.Entry getEntry(char[], int, int)
*/
@Test
public void testGetEntrycharArrayintint()
{
char[] xabcyz = {'x','a','b','c','y','z'};
@ -210,6 +200,7 @@ public class StringMapTest extends TestCase
/*
* Test for Object remove(Object)
*/
@Test
public void testRemove()
{
m0.remove("abc");
@ -230,10 +221,10 @@ public class StringMapTest extends TestCase
assertEquals(null,m5i.get(null));
}
/*
* Test for Set entrySet()
*/
@Test
public void testEntrySet()
{
Set es0=m0.entrySet();
@ -247,6 +238,7 @@ public class StringMapTest extends TestCase
/*
* Test for boolean containsKey(Object)
*/
@Test
public void testContainsKey()
{
assertTrue(m5.containsKey("abc"));
@ -260,6 +252,7 @@ public class StringMapTest extends TestCase
assertTrue(m5i.containsKey("ABC"));
}
@Test
public void testWriteExternal()
throws Exception
{
@ -288,6 +281,7 @@ public class StringMapTest extends TestCase
}
@Test
public void testToString()
{
assertEquals("{}",m0.toString());
@ -295,7 +289,7 @@ public class StringMapTest extends TestCase
assertTrue(m5.toString().indexOf("abc=2")>0);
}
@Test
public void testIgnoreCase()
{
StringMap map = new StringMap(true);

View File

@ -13,43 +13,20 @@
package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import junit.framework.TestCase;
/**
*
*
*/
public class StringUtilTest extends TestCase
public class StringUtilTest
{
/**
* Constructor for StringUtilTest.
* @param arg0
*/
public StringUtilTest(String arg0)
{
super(arg0);
}
/*
* @see TestCase#setUp()
*/
@Override
protected void setUp() throws Exception
{
super.setUp();
}
/*
* @see TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception
{
super.tearDown();
}
@Test
public void testAsciiToLowerCase()
{
String lc="\u0690bc def 1\u06903";
@ -57,6 +34,7 @@ public class StringUtilTest extends TestCase
assertTrue(StringUtil.asciiToLowerCase(lc)==lc);
}
@Test
public void testStartsWithIgnoreCase()
{
@ -74,6 +52,7 @@ public class StringUtilTest extends TestCase
assertFalse(StringUtil.startsWithIgnoreCase("\u0690", "xyz"));
}
@Test
public void testEndsWithIgnoreCase()
{
assertTrue(StringUtil.endsWithIgnoreCase("\u0690bcd\u0690f\u0690", "\u0690f\u0690"));
@ -90,6 +69,7 @@ public class StringUtilTest extends TestCase
assertFalse(StringUtil.endsWithIgnoreCase("\u0690", "xyz"));
}
@Test
public void testIndexFrom()
{
assertEquals(StringUtil.indexFrom("\u0690bcd", "xyz"),-1);
@ -98,6 +78,7 @@ public class StringUtilTest extends TestCase
assertEquals(StringUtil.indexFrom("\u0690bcd", "dxy"),3);
}
@Test
public void testReplace()
{
String s="\u0690bc \u0690bc \u0690bc";
@ -109,6 +90,7 @@ public class StringUtilTest extends TestCase
}
@Test
public void testUnquote()
{
String uq =" not quoted ";
@ -120,6 +102,7 @@ public class StringUtilTest extends TestCase
}
@Test
public void testNonNull()
{
String nn="";
@ -130,12 +113,14 @@ public class StringUtilTest extends TestCase
/*
* Test for boolean equals(String, char[], int, int)
*/
@Test
public void testEqualsStringcharArrayintint()
{
assertTrue(StringUtil.equals("\u0690bc", new char[] {'x','\u0690','b','c','z'},1,3));
assertFalse(StringUtil.equals("axc", new char[] {'x','a','b','c','z'},1,3));
}
@Test
public void testAppend()
{
StringBuilder buf = new StringBuilder();

View File

@ -13,35 +13,40 @@
package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import junit.framework.TestCase;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* TestInjection
*
*
*/
public class TestIntrospectionUtil extends TestCase
public class TestIntrospectionUtil
{
public final Class[] __INTEGER_ARG = new Class[] {Integer.class};
Field privateAField;
Field protectedAField;
Field publicAField;
Field defaultAField;
Field privateBField;
Field protectedBField;
Field publicBField;
Field defaultBField;
Method privateCMethod;
Method protectedCMethod;
Method publicCMethod;
Method defaultCMethod;
Method privateDMethod;
Method protectedDMethod;
Method publicDMethod;
Method defaultDMethod;
public final static Class[] __INTEGER_ARG = new Class[] {Integer.class};
static Field privateAField;
static Field protectedAField;
static Field publicAField;
static Field defaultAField;
static Field privateBField;
static Field protectedBField;
static Field publicBField;
static Field defaultBField;
static Method privateCMethod;
static Method protectedCMethod;
static Method publicCMethod;
static Method defaultCMethod;
static Method privateDMethod;
static Method protectedDMethod;
static Method publicDMethod;
static Method defaultDMethod;
public class ServletA
{
@ -75,8 +80,8 @@ public class TestIntrospectionUtil extends TestCase
void setDefaultD(Integer d) {}
}
@Override
public void setUp()
@BeforeClass
public static void setUp()
throws Exception
{
privateAField = ServletA.class.getDeclaredField("privateA");
@ -97,7 +102,7 @@ public class TestIntrospectionUtil extends TestCase
defaultDMethod = ServletD.class.getDeclaredMethod("setDefaultD", __INTEGER_ARG);
}
@Test
public void testFieldPrivate ()
throws Exception
{
@ -117,6 +122,7 @@ public class TestIntrospectionUtil extends TestCase
}
}
@Test
public void testFieldProtected()
throws Exception
{
@ -129,6 +135,7 @@ public class TestIntrospectionUtil extends TestCase
assertEquals(f, protectedAField);
}
@Test
public void testFieldPublic()
throws Exception
{
@ -141,6 +148,7 @@ public class TestIntrospectionUtil extends TestCase
assertEquals(f, publicAField);
}
@Test
public void testFieldDefault()
throws Exception
{
@ -153,6 +161,7 @@ public class TestIntrospectionUtil extends TestCase
assertEquals(f, defaultAField);
}
@Test
public void testMethodPrivate ()
throws Exception
{
@ -172,6 +181,7 @@ public class TestIntrospectionUtil extends TestCase
}
}
@Test
public void testMethodProtected ()
throws Exception
{
@ -184,6 +194,7 @@ public class TestIntrospectionUtil extends TestCase
assertEquals(m, protectedCMethod);
}
@Test
public void testMethodPublic ()
throws Exception
{
@ -196,6 +207,7 @@ public class TestIntrospectionUtil extends TestCase
assertEquals(m, publicCMethod);
}
@Test
public void testMethodDefault ()
throws Exception
{

View File

@ -13,34 +13,19 @@
package org.eclipse.jetty.util;
import junit.framework.TestSuite;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/* ------------------------------------------------------------ */
/** Util meta Tests.
*
*/
public class URITest extends junit.framework.TestCase
public class URITest
{
public URITest(String name)
{
super(name);
}
public static junit.framework.Test suite() {
TestSuite suite = new TestSuite(URITest.class);
return suite;
}
/* ------------------------------------------------------------ */
/** main.
*/
public static void main(String[] args)
{
junit.textui.TestRunner.run(suite());
}
/* ------------------------------------------------------------ */
@Test
public void testEncodePath()
{
// test basic encode/decode
@ -63,6 +48,7 @@ public class URITest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testDecodePath()
{
assertEquals("foo%23;,:=b a r",URIUtil.decodePath("foo%2523%3b%2c:%3db%20a%20r"));
@ -72,6 +58,7 @@ public class URITest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testAddPaths()
{
assertEquals("null+null", URIUtil.addPaths(null,null),null);
@ -161,6 +148,7 @@ public class URITest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testCompactPath()
{
assertEquals("/foo/bar", URIUtil.compactPath("/foo/bar"));
@ -174,6 +162,7 @@ public class URITest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testParentPath()
{
assertEquals("parent /aaa/bbb/","/aaa/", URIUtil.parentPath("/aaa/bbb/"));
@ -186,6 +175,7 @@ public class URITest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testCanonicalPath()
{
String[][] canonical =

View File

@ -13,38 +13,23 @@
package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import junit.framework.TestSuite;
import org.junit.Test;
/* ------------------------------------------------------------ */
/** Util meta Tests.
*
*/
public class URLEncodedTest extends junit.framework.TestCase
public class URLEncodedTest
{
public URLEncodedTest(String name)
{
super(name);
}
public static junit.framework.Test suite() {
TestSuite suite = new TestSuite(URLEncodedTest.class);
return suite;
}
/* ------------------------------------------------------------ */
/** main.
*/
public static void main(String[] args)
{
junit.textui.TestRunner.run(suite());
}
/* -------------------------------------------------------------- */
@Test
public void testUrlEncoded() throws UnsupportedEncodingException
{
@ -147,6 +132,7 @@ public class URLEncodedTest extends junit.framework.TestCase
/* -------------------------------------------------------------- */
@Test
public void testUrlEncodedStream()
throws Exception
{
@ -185,6 +171,7 @@ public class URLEncodedTest extends junit.framework.TestCase
}
/* -------------------------------------------------------------- */
@Test
public void testUtf8()
throws Exception
{

View File

@ -13,10 +13,14 @@
package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class Utf8StringBufferTest extends junit.framework.TestCase
import org.junit.Test;
public class Utf8StringBufferTest
{
public void testUtfStringBuffer()
throws Exception
{
@ -30,6 +34,7 @@ public class Utf8StringBufferTest extends junit.framework.TestCase
}
@Test
public void testShort()
throws Exception
{
@ -49,6 +54,7 @@ public class Utf8StringBufferTest extends junit.framework.TestCase
}
}
@Test
public void testLong()
throws Exception
{

View File

@ -13,10 +13,15 @@
package org.eclipse.jetty.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class Utf8StringBuilderTest extends junit.framework.TestCase
import org.junit.Test;
public class Utf8StringBuilderTest
{
@Test
public void testUtfStringBuilder()
throws Exception
{
@ -29,6 +34,7 @@ public class Utf8StringBuilderTest extends junit.framework.TestCase
assertTrue(buffer.toString().endsWith("jetty"));
}
@Test
public void testShort()
throws Exception
{
@ -48,6 +54,7 @@ public class Utf8StringBuilderTest extends junit.framework.TestCase
}
}
@Test
public void testLong()
throws Exception
{

View File

@ -13,14 +13,18 @@
package org.eclipse.jetty.util.ajax;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Test to convert POJOs to JSON and vice versa with automatic convertor creation.
*/
public class JSONPojoConvertorFactoryTest extends TestCase {
public class JSONPojoConvertorFactoryTest
{
@Test
public void testFoo()
{
JSON jsonOut = new JSON();

View File

@ -13,15 +13,20 @@
package org.eclipse.jetty.util.ajax;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Test to converts POJOs to JSON and vice versa.
*
*
*
*/
public class JSONPojoConvertorTest extends TestCase
public class JSONPojoConvertorTest
{
@Test
public void testFoo()
{
JSON json = new JSON();
@ -66,6 +71,7 @@ public class JSONPojoConvertorTest extends TestCase
assertEquals(Color.Green,br.getColor());
}
@Test
public void testExclude()
{
JSON json = new JSON();

View File

@ -12,6 +12,10 @@
// ========================================================================
package org.eclipse.jetty.util.ajax;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.StringReader;
import java.lang.reflect.Array;
import java.math.BigDecimal;
@ -21,12 +25,13 @@ import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import junit.framework.TestCase;
import org.eclipse.jetty.util.DateCache;
import org.eclipse.jetty.util.ajax.JSON.Output;
import org.junit.BeforeClass;
import org.junit.Test;
public class JSONTest extends TestCase
public class JSONTest
{
String test="\n\n\n\t\t "+
"// ignore this ,a [ \" \n"+
@ -45,6 +50,17 @@ public class JSONTest extends TestCase
"\"undefined\": undefined," +
"}";
/* ------------------------------------------------------------ */
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
@BeforeClass
public static void setUp() throws Exception
{
JSON.registerConvertor(Gadget.class,new JSONObjectConvertor(false));
}
@Test
public void testToString()
{
HashMap map = new HashMap();
@ -94,26 +110,16 @@ public class JSONTest extends TestCase
gadget.setWoggles(new Woggle[]{w0,w1});
s = JSON.toString(new Gadget[]{gadget});
System.out.println(s);
assertTrue(s.startsWith("["));
assertTrue(s.indexOf("\"modulated\":false")>=0);
assertTrue(s.indexOf("\"shields\":42")>=0);
assertTrue(s.indexOf("\"name\":\"woggle0\"")>=0);
assertTrue(s.indexOf("\"name\":\"woggle1\"")>=0);
}
/* ------------------------------------------------------------ */
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception
{
JSON.registerConvertor(Gadget.class,new JSONObjectConvertor(false));
}
/* ------------------------------------------------------------ */
@Test
public void testParse()
{
Map map = (Map)JSON.parse(test);
@ -134,6 +140,7 @@ public class JSONTest extends TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testParseReader() throws Exception
{
Map map = (Map)JSON.parse(new StringReader(test));
@ -149,6 +156,7 @@ public class JSONTest extends TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testStripComment()
{
String test="\n\n\n\t\t "+
@ -171,6 +179,7 @@ public class JSONTest extends TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testQuote()
{
String test="\"abc123|\\\"|\\\\|\\/|\\b|\\f|\\n|\\r|\\t|\\uaaaa|\"";
@ -180,6 +189,7 @@ public class JSONTest extends TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testBigDecimal()
{
Object obj = JSON.parse("1.0E7");
@ -247,6 +257,7 @@ public class JSONTest extends TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testConvertor()
{
// test case#1 - force timezone to GMT
@ -316,6 +327,7 @@ public class JSONTest extends TestCase
enum Color { Red, Green, Blue };
@Test
public void testEnumConvertor()
{
JSON json = new JSON();

View File

@ -13,34 +13,20 @@
package org.eclipse.jetty.util.component;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.StdErrLog;
import org.junit.Test;
public class LifeCycleListenerTest extends TestCase
public class LifeCycleListenerTest
{
static Exception cause = new Exception("expected test exception");
public LifeCycleListenerTest(String name)
{
super(name);
}
public static void main(String[] args)
{
TestRunner.run(suite());
}
public static Test suite()
{
TestSuite suite = new TestSuite(LifeCycleListenerTest.class);
return suite;
}
@Test
public void testStart() throws Exception
{
TestLifeCycle lifecycle = new TestLifeCycle();
@ -78,6 +64,7 @@ public class LifeCycleListenerTest extends TestCase
assertTrue("The lifecycle state is not started",lifecycle.isStarted());
}
@Test
public void testStop() throws Exception
{
TestLifeCycle lifecycle = new TestLifeCycle();
@ -126,6 +113,7 @@ public class LifeCycleListenerTest extends TestCase
}
@Test
public void testRemoveLifecycleListener ()
throws Exception
{

View File

@ -13,26 +13,31 @@
package org.eclipse.jetty.util.log;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import junit.framework.TestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class LogTest extends TestCase
public class LogTest
{
PrintStream _orig= System.err;
ByteArrayOutputStream _out = new ByteArrayOutputStream();
PrintStream _pout = new PrintStream(_out);
static PrintStream _orig= System.err;
static ByteArrayOutputStream _out = new ByteArrayOutputStream();
static PrintStream _pout = new PrintStream(_out);
@Override
public void setUp()
@BeforeClass
public static void setUp()
{
System.setErr(_pout);
}
@Override
public void tearDown()
@AfterClass
public static void tearDown()
{
System.setErr(_orig);
}
@ -64,6 +69,7 @@ public class LogTest extends TestCase
assertTrue(false);
}
@Test
public void testStdErrLogFormat()
{
StdErrLog log = new StdErrLog("test");
@ -90,6 +96,7 @@ public class LogTest extends TestCase
logContains("INFO:test:testing");
}
@Test
public void testStdErrLogDebug()
{
StdErrLog log = new StdErrLog("xxx");
@ -109,6 +116,7 @@ public class LogTest extends TestCase
logNotContains("YOU SHOULD NOT SEE THIS!");
}
@Test
public void testStdErrLogName()
{
StdErrLog log = new StdErrLog("test");
@ -119,6 +127,7 @@ public class LogTest extends TestCase
}
@Test
public void testStdErrThrowable()
{
Throwable th = new Throwable("Message");

View File

@ -18,10 +18,20 @@ import java.io.File;
import java.io.InputStreamReader;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class ResourceCollectionTest extends TestCase
import org.junit.Test;
import org.junit.BeforeClass;
import org.junit.AfterClass;
public class ResourceCollectionTest
{
@Test
public void testMutlipleSources1() throws Exception
{
ResourceCollection rc1 = new ResourceCollection(new String[]{
@ -47,6 +57,7 @@ public class ResourceCollectionTest extends TestCase
System.err.println(s);
}
@Test
public void testMergedDir() throws Exception
{
ResourceCollection rc = new ResourceCollection(new String[]{
@ -63,6 +74,7 @@ public class ResourceCollectionTest extends TestCase
assertEquals("3 - three", getContent(rc, "3.txt"));
}
@Test
public void testCopyTo() throws Exception
{
ResourceCollection rc = new ResourceCollection(new String[]{

View File

@ -13,6 +13,10 @@
package org.eclipse.jetty.util.resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FilePermission;
@ -24,8 +28,11 @@ import java.util.jar.JarInputStream;
import junit.framework.TestSuite;
import org.eclipse.jetty.util.IO;
import org.junit.BeforeClass;
import org.junit.Test;
public class ResourceTest extends junit.framework.TestCase
public class ResourceTest
{
public static String __userDir = System.getProperty("basedir", ".");
@ -36,7 +43,7 @@ public class ResourceTest extends junit.framework.TestCase
private static final boolean DIR=true;
private static final boolean EXISTS=true;
class Data
static class Data
{
Resource resource;
String test;
@ -94,26 +101,9 @@ public class ResourceTest extends junit.framework.TestCase
public static Data[] data;
public ResourceTest(String name)
{
super(name);
}
/* ------------------------------------------------------------ */
public static void main(String[] args)
{
junit.textui.TestRunner.run(suite());
}
/* ------------------------------------------------------------ */
public static junit.framework.Test suite()
{
return new TestSuite(ResourceTest.class);
}
/* ------------------------------------------------------------ */
@Override
protected void setUp()
@BeforeClass
public static void setUp()
throws Exception
{
if (data!=null)
@ -189,16 +179,8 @@ public class ResourceTest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Override
protected void tearDown()
throws Exception
{
}
/* ------------------------------------------------------------ */
@Test
public void testResourceExists()
{
for (int i=0;i<data.length;i++)
@ -211,6 +193,7 @@ public class ResourceTest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testResourceDir()
{
for (int i=0;i<data.length;i++)
@ -223,6 +206,7 @@ public class ResourceTest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testResourceContent()
throws Exception
{
@ -238,6 +222,7 @@ public class ResourceTest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testEncoding() throws Exception
{
Resource r =Resource.newResource("/tmp/a file with,spe#ials/");
@ -246,6 +231,7 @@ public class ResourceTest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testJarFile()
throws Exception
{
@ -256,9 +242,9 @@ public class ResourceTest extends junit.framework.TestCase
JarInputStream jin = new JarInputStream(is);
assertNotNull(is);
assertNotNull(jin);
}
@Test
public void testJarFileIsContainedIn ()
throws Exception
{
@ -276,6 +262,7 @@ public class ResourceTest extends junit.framework.TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testJarFileCopyToDirectoryTraversal () throws Exception
{
String s = "jar:"+__userURL+"TestData/extract.zip!/";
@ -333,6 +320,7 @@ public class ResourceTest extends junit.framework.TestCase
/**
* Test a class path resource for existence.
*/
@Test
public void testClassPathResourceClassRelative()
{
final String classPathName="Resource.class";
@ -351,6 +339,7 @@ public class ResourceTest extends junit.framework.TestCase
/**
* Test a class path resource for existence.
*/
@Test
public void testClassPathResourceClassAbsolute()
{
final String classPathName="/org/eclipse/jetty/util/resource/Resource.class";
@ -369,6 +358,7 @@ public class ResourceTest extends junit.framework.TestCase
/**
* Test a class path resource for directories.
*/
@Test
public void testClassPathResourceDirectory() throws Exception
{
final String classPathName="/";
@ -390,6 +380,7 @@ public class ResourceTest extends junit.framework.TestCase
/**
* Test a class path resource for a file.
*/
@Test
public void testClassPathResourceFile() throws Exception
{
final String fileName="resource.txt";

View File

@ -1,12 +1,13 @@
package org.eclipse.jetty.util.statistic;
import org.eclipse.jetty.util.statistic.SampleStatistic;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase;
import org.junit.Test;
/* ------------------------------------------------------------ */
public class SampleStatisticTest extends TestCase
public class SampleStatisticTest
{
private static long[][] data =
{
@ -26,6 +27,7 @@ public class SampleStatisticTest extends TestCase
};
@Test
public void testData()
throws Exception
{

View File

@ -11,14 +11,17 @@
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.util.thread;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.atomic.AtomicInteger;
import junit.framework.TestCase;
import org.junit.Test;
public class QueuedThreadPoolTest extends TestCase
public class QueuedThreadPoolTest
{
final AtomicInteger _jobs=new AtomicInteger();
volatile long _sleep=100;
@ -44,6 +47,7 @@ public class QueuedThreadPoolTest extends TestCase
@Test
public void testThreadPool() throws Exception
{
_sleep=100;
@ -129,6 +133,7 @@ public class QueuedThreadPoolTest extends TestCase
tp.stop();
}
@Test
public void testShrink() throws Exception
{
Runnable job = new Runnable()
@ -184,6 +189,7 @@ public class QueuedThreadPoolTest extends TestCase
}
@Test
public void testMaxStopTime() throws Exception
{
_sleep=100;

View File

@ -13,11 +13,15 @@
package org.eclipse.jetty.util.thread;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.atomic.AtomicIntegerArray;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
public class TimeoutTest extends TestCase
public class TimeoutTest
{
Object lock = new Object();
Timeout timeout = new Timeout(null);
@ -27,11 +31,9 @@ public class TimeoutTest extends TestCase
/*
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception
@Before
public void setUp() throws Exception
{
super.setUp();
timeout=new Timeout(lock);
tasks= new Timeout.Task[10];
@ -45,17 +47,7 @@ public class TimeoutTest extends TestCase
}
/* ------------------------------------------------------------ */
/*
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception
{
super.tearDown();
}
/* ------------------------------------------------------------ */
@Test
public void testExpiry()
{
timeout.setDuration(200);
@ -69,6 +61,7 @@ public class TimeoutTest extends TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testCancel()
{
timeout.setDuration(200);
@ -87,6 +80,7 @@ public class TimeoutTest extends TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testTouch()
{
timeout.setDuration(200);
@ -110,6 +104,7 @@ public class TimeoutTest extends TestCase
/* ------------------------------------------------------------ */
@Test
public void testDelay()
{
Timeout.Task task = new Timeout.Task();
@ -132,6 +127,7 @@ public class TimeoutTest extends TestCase
}
/* ------------------------------------------------------------ */
@Test
public void testStress() throws Exception
{
final int LOOP=250;