You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2012/09/18 23:07:44 UTC
svn commit: r1387361 [5/5] - in /commons/proper/lang/trunk: ./
src/test/java/org/apache/commons/lang3/
src/test/java/org/apache/commons/lang3/concurrent/
src/test/java/org/apache/commons/lang3/event/
src/test/java/org/apache/commons/lang3/exception/ sr...
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/StrTokenizerTest.java Tue Sep 18 21:07:42 2012
@@ -17,13 +17,13 @@
package org.apache.commons.lang3.text;
+import org.junit.Test;
+import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ObjectUtils;
@@ -31,27 +31,19 @@ import org.apache.commons.lang3.ObjectUt
* Unit test for Tokenizer.
*
*/
-public class StrTokenizerTest extends TestCase {
+public class StrTokenizerTest {
private static final String CSV_SIMPLE_FIXTURE = "A,b,c";
private static final String TSV_SIMPLE_FIXTURE = "A\tb\tc";
- /**
- * JUnit constructor.
- *
- * @param name
- */
- public StrTokenizerTest(String name) {
- super(name);
- }
-
private void checkClone(StrTokenizer tokenizer) {
assertFalse(StrTokenizer.getCSVInstance() == tokenizer);
assertFalse(StrTokenizer.getTSVInstance() == tokenizer);
}
// -----------------------------------------------------------------------
+ @Test
public void test1() {
String input = "a;b;c;\"d;\"\"e\";f; ; ; ";
@@ -72,6 +64,7 @@ public class StrTokenizerTest extends Te
}
+ @Test
public void test2() {
String input = "a;b;c ;\"d;\"\"e\";f; ; ;";
@@ -92,6 +85,7 @@ public class StrTokenizerTest extends Te
}
+ @Test
public void test3() {
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
@@ -112,6 +106,7 @@ public class StrTokenizerTest extends Te
}
+ @Test
public void test4() {
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
@@ -132,6 +127,7 @@ public class StrTokenizerTest extends Te
}
+ @Test
public void test5() {
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
@@ -153,6 +149,7 @@ public class StrTokenizerTest extends Te
}
+ @Test
public void test6() {
String input = "a;b; c;\"d;\"\"e\";f; ; ;";
@@ -188,6 +185,7 @@ public class StrTokenizerTest extends Te
}
+ @Test
public void test7() {
String input = "a b c \"d e\" f ";
@@ -208,6 +206,7 @@ public class StrTokenizerTest extends Te
}
+ @Test
public void test8() {
String input = "a b c \"d e\" f ";
@@ -228,6 +227,7 @@ public class StrTokenizerTest extends Te
}
+ @Test
public void testBasic1() {
String input = "a b c";
StrTokenizer tok = new StrTokenizer(input);
@@ -237,6 +237,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasic2() {
String input = "a \nb\fc";
StrTokenizer tok = new StrTokenizer(input);
@@ -246,6 +247,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasic3() {
String input = "a \nb\u0001\fc";
StrTokenizer tok = new StrTokenizer(input);
@@ -255,6 +257,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasic4() {
String input = "a \"b\" c";
StrTokenizer tok = new StrTokenizer(input);
@@ -264,6 +267,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasic5() {
String input = "a:b':c";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -273,6 +277,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicDelim1() {
String input = "a:b:c";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -282,6 +287,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicDelim2() {
String input = "a:b:c";
StrTokenizer tok = new StrTokenizer(input, ',');
@@ -289,6 +295,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicEmpty1() {
String input = "a b c";
StrTokenizer tok = new StrTokenizer(input);
@@ -300,6 +307,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicEmpty2() {
String input = "a b c";
StrTokenizer tok = new StrTokenizer(input);
@@ -312,6 +320,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted1() {
String input = "a 'b' c";
StrTokenizer tok = new StrTokenizer(input, ' ', '\'');
@@ -321,6 +330,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted2() {
String input = "a:'b':";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -332,6 +342,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted3() {
String input = "a:'b''c'";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -342,6 +353,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted4() {
String input = "a: 'b' 'c' :d";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -354,6 +366,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted5() {
String input = "a: 'b'x'c' :d";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -366,6 +379,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted6() {
String input = "a:'b'\"c':d";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -375,6 +389,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuoted7() {
String input = "a:\"There's a reason here\":b";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -385,6 +400,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicQuotedTrimmed1() {
String input = "a: 'b' :";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -397,6 +413,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicTrimmed1() {
String input = "a: b : ";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -409,6 +426,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicTrimmed2() {
String input = "a: b :";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -421,6 +439,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicIgnoreTrimmed1() {
String input = "a: bIGNOREc : ";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -434,6 +453,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicIgnoreTrimmed2() {
String input = "IGNOREaIGNORE: IGNORE bIGNOREc IGNORE : IGNORE ";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -447,6 +467,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicIgnoreTrimmed3() {
String input = "IGNOREaIGNORE: IGNORE bIGNOREc IGNORE : IGNORE ";
StrTokenizer tok = new StrTokenizer(input, ':');
@@ -459,6 +480,7 @@ public class StrTokenizerTest extends Te
assertEquals(false, tok.hasNext());
}
+ @Test
public void testBasicIgnoreTrimmed4() {
String input = "IGNOREaIGNORE: IGNORE 'bIGNOREc'IGNORE'd' IGNORE : IGNORE ";
StrTokenizer tok = new StrTokenizer(input, ':', '\'');
@@ -473,6 +495,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testListArray() {
String input = "a b c";
StrTokenizer tok = new StrTokenizer(input);
@@ -484,20 +507,23 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
- public void testCSV(String data) {
+ private void testCSV(String data) {
this.testXSVAbc(StrTokenizer.getCSVInstance(data));
this.testXSVAbc(StrTokenizer.getCSVInstance(data.toCharArray()));
}
+ @Test
public void testCSVEmpty() {
this.testEmpty(StrTokenizer.getCSVInstance());
this.testEmpty(StrTokenizer.getCSVInstance(""));
}
+ @Test
public void testCSVSimple() {
this.testCSV(CSV_SIMPLE_FIXTURE);
}
+ @Test
public void testCSVSimpleNeedsTrim() {
this.testCSV(" " + CSV_SIMPLE_FIXTURE);
this.testCSV(" \n\t " + CSV_SIMPLE_FIXTURE);
@@ -516,6 +542,7 @@ public class StrTokenizerTest extends Te
} catch (NoSuchElementException ex) {}
}
+ @Test
public void testGetContent() {
String input = "a b c \"d e\" f ";
StrTokenizer tok = new StrTokenizer(input);
@@ -529,6 +556,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testChaining() {
StrTokenizer tok = new StrTokenizer();
assertEquals(tok, tok.reset());
@@ -550,6 +578,7 @@ public class StrTokenizerTest extends Te
* Tests that the {@link StrTokenizer#clone()} clone method catches {@link CloneNotSupportedException} and returns
* <code>null</code>.
*/
+ @Test
public void testCloneNotSupportedException() {
Object notCloned = new StrTokenizer() {
@Override
@@ -560,6 +589,7 @@ public class StrTokenizerTest extends Te
assertNull(notCloned);
}
+ @Test
public void testCloneNull() {
StrTokenizer tokenizer = new StrTokenizer((char[]) null);
// Start sanity check
@@ -573,6 +603,7 @@ public class StrTokenizerTest extends Te
assertEquals(null, clonedTokenizer.nextToken());
}
+ @Test
public void testCloneReset() {
char[] input = new char[]{'a'};
StrTokenizer tokenizer = new StrTokenizer(input);
@@ -589,6 +620,7 @@ public class StrTokenizerTest extends Te
}
// -----------------------------------------------------------------------
+ @Test
public void testConstructor_String() {
StrTokenizer tok = new StrTokenizer("a b");
assertEquals("a", tok.next());
@@ -603,6 +635,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_String_char() {
StrTokenizer tok = new StrTokenizer("a b", ' ');
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
@@ -618,6 +651,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_String_char_char() {
StrTokenizer tok = new StrTokenizer("a b", ' ', '"');
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
@@ -634,6 +668,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_charArray() {
StrTokenizer tok = new StrTokenizer("a b".toCharArray());
assertEquals("a", tok.next());
@@ -648,6 +683,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_charArray_char() {
StrTokenizer tok = new StrTokenizer("a b".toCharArray(), ' ');
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
@@ -663,6 +699,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor_charArray_char_char() {
StrTokenizer tok = new StrTokenizer("a b".toCharArray(), ' ', '"');
assertEquals(1, tok.getDelimiterMatcher().isMatch(" ".toCharArray(), 0, 0, 1));
@@ -679,6 +716,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testReset() {
StrTokenizer tok = new StrTokenizer("a b c");
assertEquals("a", tok.next());
@@ -694,6 +732,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testReset_String() {
StrTokenizer tok = new StrTokenizer("x x x");
tok.reset("d e");
@@ -706,6 +745,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testReset_charArray() {
StrTokenizer tok = new StrTokenizer("x x x");
@@ -719,11 +759,13 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testTSV() {
this.testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE));
this.testXSVAbc(StrTokenizer.getTSVInstance(TSV_SIMPLE_FIXTURE.toCharArray()));
}
+ @Test
public void testTSVEmpty() {
this.testEmpty(StrTokenizer.getCSVInstance());
this.testEmpty(StrTokenizer.getCSVInstance(""));
@@ -754,6 +796,7 @@ public class StrTokenizerTest extends Te
assertEquals(3, tokenizer.size());
}
+ @Test
public void testIteration() {
StrTokenizer tkn = new StrTokenizer("a b c");
assertEquals(false, tkn.hasPrevious());
@@ -796,6 +839,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testTokenizeSubclassInputChange() {
StrTokenizer tkn = new StrTokenizer("a b c d e") {
@Override
@@ -808,6 +852,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testTokenizeSubclassOutputChange() {
StrTokenizer tkn = new StrTokenizer("a b c") {
@Override
@@ -823,6 +868,7 @@ public class StrTokenizerTest extends Te
}
//-----------------------------------------------------------------------
+ @Test
public void testToString() {
StrTokenizer tkn = new StrTokenizer("a b c d e");
assertEquals("StrTokenizer[not tokenized yet]", tkn.toString());
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java Tue Sep 18 21:07:42 2012
@@ -16,23 +16,23 @@
*/
package org.apache.commons.lang3.text;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests for WordUtils class.
*
* @version $Id$
*/
-public class WordUtilsTest extends TestCase {
-
- public WordUtilsTest(String name) {
- super(name);
- }
+public class WordUtilsTest {
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new WordUtils());
Constructor<?>[] cons = WordUtils.class.getDeclaredConstructors();
@@ -43,6 +43,7 @@ public class WordUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testWrap_StringInt() {
assertEquals(null, WordUtils.wrap(null, 20));
assertEquals(null, WordUtils.wrap(null, -1));
@@ -70,6 +71,7 @@ public class WordUtilsTest extends TestC
assertEquals(expected, WordUtils.wrap(input, 20));
}
+ @Test
public void testWrap_StringIntStringBoolean() {
assertEquals(null, WordUtils.wrap(null, 20, "\n", false));
assertEquals(null, WordUtils.wrap(null, 20, "\n", true));
@@ -149,6 +151,7 @@ public class WordUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testCapitalize_String() {
assertEquals(null, WordUtils.capitalize(null));
assertEquals("", WordUtils.capitalize(""));
@@ -162,6 +165,7 @@ public class WordUtilsTest extends TestC
assertEquals("I AM HERE 123", WordUtils.capitalize("I AM HERE 123") );
}
+ @Test
public void testCapitalizeWithDelimiters_String() {
assertEquals(null, WordUtils.capitalize(null, null));
assertEquals("", WordUtils.capitalize("", new char[0]));
@@ -179,6 +183,7 @@ public class WordUtilsTest extends TestC
assertEquals("I Am.fine", WordUtils.capitalize("i am.fine", null) );
}
+ @Test
public void testCapitalizeFully_String() {
assertEquals(null, WordUtils.capitalizeFully(null));
assertEquals("", WordUtils.capitalizeFully(""));
@@ -192,6 +197,7 @@ public class WordUtilsTest extends TestC
assertEquals("I Am Here 123", WordUtils.capitalizeFully("I AM HERE 123") );
}
+ @Test
public void testCapitalizeFullyWithDelimiters_String() {
assertEquals(null, WordUtils.capitalizeFully(null, null));
assertEquals("", WordUtils.capitalizeFully("", new char[0]));
@@ -209,6 +215,7 @@ public class WordUtilsTest extends TestC
assertEquals("I Am.fine", WordUtils.capitalizeFully("i am.fine", null) );
}
+ @Test
public void testUncapitalize_String() {
assertEquals(null, WordUtils.uncapitalize(null));
assertEquals("", WordUtils.uncapitalize(""));
@@ -222,6 +229,7 @@ public class WordUtilsTest extends TestC
assertEquals("i aM hERE 123", WordUtils.uncapitalize("I AM HERE 123") );
}
+ @Test
public void testUncapitalizeWithDelimiters_String() {
assertEquals(null, WordUtils.uncapitalize(null, null));
assertEquals("", WordUtils.uncapitalize("", new char[0]));
@@ -240,6 +248,7 @@ public class WordUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testInitials_String() {
assertEquals(null, WordUtils.initials(null));
assertEquals("", WordUtils.initials(""));
@@ -254,6 +263,7 @@ public class WordUtilsTest extends TestC
}
// -----------------------------------------------------------------------
+ @Test
public void testInitials_String_charArray() {
char[] array = null;
assertEquals(null, WordUtils.initials(null, array));
@@ -335,6 +345,7 @@ public class WordUtilsTest extends TestC
}
// -----------------------------------------------------------------------
+ @Test
public void testSwapCase_String() {
assertEquals(null, WordUtils.swapCase(null));
assertEquals("", WordUtils.swapCase(""));
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/EntityArraysTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/EntityArraysTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/EntityArraysTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/EntityArraysTest.java Tue Sep 18 21:07:42 2012
@@ -17,22 +17,26 @@
package org.apache.commons.lang3.text.translate;
+import static org.junit.Assert.assertTrue;
+
import java.util.HashSet;
import java.util.Set;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.EntityArrays}.
* @version $Id$
*/
-public class EntityArraysTest extends TestCase {
+public class EntityArraysTest {
+ @Test
public void testConstructorExists() {
new EntityArrays();
}
// LANG-659 - check arrays for duplicate entries
+ @Test
public void testHTML40_EXTENDED_ESCAPE(){
Set<String> col0 = new HashSet<String>();
Set<String> col1 = new HashSet<String>();
@@ -44,6 +48,7 @@ public class EntityArraysTest extends Te
}
// LANG-658 - check arrays for duplicate entries
+ @Test
public void testISO8859_1_ESCAPE(){
Set<String> col0 = new HashSet<String>();
Set<String> col1 = new HashSet<String>();
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/LookupTranslatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/LookupTranslatorTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/LookupTranslatorTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/LookupTranslatorTest.java Tue Sep 18 21:07:42 2012
@@ -17,17 +17,20 @@
package org.apache.commons.lang3.text.translate;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
import java.io.StringWriter;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.LookupTranslator}.
* @version $Id$
*/
-public class LookupTranslatorTest extends TestCase {
+public class LookupTranslatorTest {
+ @Test
public void testBasicLookup() throws IOException {
LookupTranslator lt = new LookupTranslator(new CharSequence[][] { { "one", "two" } });
StringWriter out = new StringWriter();
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityEscaperTest.java Tue Sep 18 21:07:42 2012
@@ -17,14 +17,17 @@
package org.apache.commons.lang3.text.translate;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityEscaper}.
* @version $Id$
*/
-public class NumericEntityEscaperTest extends TestCase {
+public class NumericEntityEscaperTest {
+ @Test
public void testBelow() {
NumericEntityEscaper nee = NumericEntityEscaper.below('F');
@@ -33,6 +36,7 @@ public class NumericEntityEscaperTest ex
assertEquals("Failed to escape numeric entities via the below method", "ADFGZ", result);
}
+ @Test
public void testBetween() {
NumericEntityEscaper nee = NumericEntityEscaper.between('F', 'L');
@@ -41,6 +45,7 @@ public class NumericEntityEscaperTest ex
assertEquals("Failed to escape numeric entities via the between method", "ADFGZ", result);
}
+ @Test
public void testAbove() {
NumericEntityEscaper nee = NumericEntityEscaper.above('F');
@@ -50,6 +55,7 @@ public class NumericEntityEscaperTest ex
}
// See LANG-617
+ @Test
public void testSupplementary() {
NumericEntityEscaper nee = new NumericEntityEscaper();
String input = "\uD803\uDC22";
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/NumericEntityUnescaperTest.java Tue Sep 18 21:07:42 2012
@@ -17,14 +17,18 @@
package org.apache.commons.lang3.text.translate;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.NumericEntityUnescaper}.
* @version $Id$
*/
-public class NumericEntityUnescaperTest extends TestCase {
+public class NumericEntityUnescaperTest {
+ @Test
public void testSupplementaryUnescaping() {
NumericEntityUnescaper neu = new NumericEntityUnescaper();
String input = "𐰢";
@@ -34,6 +38,7 @@ public class NumericEntityUnescaperTest
assertEquals("Failed to unescape numeric entities supplementary characters", expected, result);
}
+ @Test
public void testOutOfBounds() {
NumericEntityUnescaper neu = new NumericEntityUnescaper();
@@ -43,6 +48,7 @@ public class NumericEntityUnescaperTest
assertEquals("Failed to ignore when last character is &", "Test &#X", neu.translate("Test &#X"));
}
+ @Test
public void testUnfinishedEntity() {
// parse it
NumericEntityUnescaper neu = new NumericEntityUnescaper(NumericEntityUnescaper.OPTION.semiColonOptional);
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/OctalUnescaperTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/OctalUnescaperTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/OctalUnescaperTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/OctalUnescaperTest.java Tue Sep 18 21:07:42 2012
@@ -17,14 +17,16 @@
package org.apache.commons.lang3.text.translate;
-import junit.framework.TestCase;
+import org.junit.Test;
+import static org.junit.Assert.*;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.OctalUnescaper}.
* @version $Id: OctalUnescaperTest.java 979392 2010-07-26 18:09:52Z mbenson $
*/
-public class OctalUnescaperTest extends TestCase {
+public class OctalUnescaperTest {
+ @Test
public void testBetween() {
OctalUnescaper oue = new OctalUnescaper(); //.between("1", "377");
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeEscaperTest.java Tue Sep 18 21:07:42 2012
@@ -17,14 +17,17 @@
package org.apache.commons.lang3.text.translate;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}.
* @version $Id$
*/
-public class UnicodeEscaperTest extends TestCase {
+public class UnicodeEscaperTest {
+ @Test
public void testBelow() {
UnicodeEscaper ue = UnicodeEscaper.below('F');
@@ -33,6 +36,7 @@ public class UnicodeEscaperTest extends
assertEquals("Failed to escape Unicode characters via the below method", "\\u0041\\u0044FGZ", result);
}
+ @Test
public void testBetween() {
UnicodeEscaper ue = UnicodeEscaper.between('F', 'L');
@@ -41,6 +45,7 @@ public class UnicodeEscaperTest extends
assertEquals("Failed to escape Unicode characters via the between method", "AD\\u0046\\u0047Z", result);
}
+ @Test
public void testAbove() {
UnicodeEscaper ue = UnicodeEscaper.above('F');
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeUnescaperTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeUnescaperTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeUnescaperTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/text/translate/UnicodeUnescaperTest.java Tue Sep 18 21:07:42 2012
@@ -17,15 +17,19 @@
package org.apache.commons.lang3.text.translate;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
/**
* Unit tests for {@link org.apache.commons.lang3.text.translate.UnicodeEscaper}.
* @version $Id$
*/
-public class UnicodeUnescaperTest extends TestCase {
+public class UnicodeUnescaperTest {
// Requested in LANG-507
+ @Test
public void testUPlus() {
UnicodeUnescaper uu = new UnicodeUnescaper();
@@ -33,6 +37,7 @@ public class UnicodeUnescaperTest extend
assertEquals("Failed to unescape Unicode characters with 'u+' notation", "G", uu.translate(input));
}
+ @Test
public void testUuuuu() {
UnicodeUnescaper uu = new UnicodeUnescaper();
@@ -41,6 +46,7 @@ public class UnicodeUnescaperTest extend
assertEquals("Failed to unescape Unicode characters with many 'u' characters", "G", result);
}
+ @Test
public void testLessThanFour() {
UnicodeUnescaper uu = new UnicodeUnescaper();
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java Tue Sep 18 21:07:42 2012
@@ -16,25 +16,22 @@
*/
package org.apache.commons.lang3.time;
+import org.junit.Test;
+import static org.junit.Assert.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
-import junit.framework.TestCase;
-
/**
* TestCase for DateFormatUtils.
*
*/
-public class DateFormatUtilsTest extends TestCase {
-
- public DateFormatUtilsTest(String s) {
- super(s);
- }
+public class DateFormatUtilsTest {
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new DateFormatUtils());
Constructor<?>[] cons = DateFormatUtils.class.getDeclaredConstructors();
@@ -45,6 +42,7 @@ public class DateFormatUtilsTest extends
}
//-----------------------------------------------------------------------
+ @Test
public void testFormat() {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(2005,0,1,12,0,0);
@@ -68,6 +66,7 @@ public class DateFormatUtilsTest extends
}
//-----------------------------------------------------------------------
+ @Test
public void testFormatCalendar() {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(2005,0,1,12,0,0);
@@ -90,6 +89,7 @@ public class DateFormatUtilsTest extends
assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH", Locale.US));
}
+ @Test
public void testFormatUTC() {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
c.set(2005,0,1,12,0,0);
@@ -102,6 +102,7 @@ public class DateFormatUtilsTest extends
assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime().getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(), Locale.US));
}
+ @Test
public void testDateTimeISO(){
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar cal = Calendar.getInstance(timeZone);
@@ -125,6 +126,7 @@ public class DateFormatUtilsTest extends
assertEquals("2002-02-23T09:11:12-03:00", text);
}
+ @Test
public void testDateISO(){
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar cal = Calendar.getInstance(timeZone);
@@ -148,6 +150,7 @@ public class DateFormatUtilsTest extends
assertEquals("2002-02-23-03:00", text);
}
+ @Test
public void testTimeISO(){
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar cal = Calendar.getInstance(timeZone);
@@ -171,6 +174,7 @@ public class DateFormatUtilsTest extends
assertEquals("T10:11:12-03:00", text);
}
+ @Test
public void testTimeNoTISO(){
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar cal = Calendar.getInstance(timeZone);
@@ -194,6 +198,7 @@ public class DateFormatUtilsTest extends
assertEquals("10:11:12-03:00", text);
}
+ @Test
public void testSMTP(){
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar cal = Calendar.getInstance(timeZone);
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsFragmentTest.java Tue Sep 18 21:07:42 2012
@@ -16,12 +16,13 @@
*/
package org.apache.commons.lang3.time;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import java.util.Calendar;
import java.util.Date;
-import junit.framework.TestCase;
-
-public class DateUtilsFragmentTest extends TestCase {
+public class DateUtilsFragmentTest {
private static final int months = 7; // second final prime before 12
private static final int days = 23; // second final prime before 31 (and valid)
@@ -33,14 +34,16 @@ public class DateUtilsFragmentTest exten
private Date aDate;
private Calendar aCalendar;
- @Override
- protected void setUp() {
+
+ @Before
+ public void setUp() {
aCalendar = Calendar.getInstance();
aCalendar.set(2005, months, days, hours, minutes, seconds);
aCalendar.set(Calendar.MILLISECOND, millis);
aDate = aCalendar.getTime();
}
+ @Test
public void testNullDate() {
try {
DateUtils.getFragmentInMilliseconds((Date) null, Calendar.MILLISECOND);
@@ -68,6 +71,7 @@ public class DateUtilsFragmentTest exten
} catch(IllegalArgumentException iae) {}
}
+ @Test
public void testNullCalendar() {
try {
DateUtils.getFragmentInMilliseconds((Calendar) null, Calendar.MILLISECOND);
@@ -95,6 +99,7 @@ public class DateUtilsFragmentTest exten
} catch(IllegalArgumentException iae) {}
}
+ @Test
public void testInvalidFragmentWithDate() {
try {
DateUtils.getFragmentInMilliseconds(aDate, 0);
@@ -122,6 +127,7 @@ public class DateUtilsFragmentTest exten
} catch(IllegalArgumentException iae) {}
}
+ @Test
public void testInvalidFragmentWithCalendar() {
try {
DateUtils.getFragmentInMilliseconds(aCalendar, 0);
@@ -149,6 +155,7 @@ public class DateUtilsFragmentTest exten
} catch(IllegalArgumentException iae) {}
}
+ @Test
public void testMillisecondFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInMilliseconds(aDate, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInSeconds(aDate, Calendar.MILLISECOND));
@@ -157,6 +164,7 @@ public class DateUtilsFragmentTest exten
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.MILLISECOND));
}
+ @Test
public void testMillisecondFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MILLISECOND));
assertEquals(0, DateUtils.getFragmentInSeconds(aCalendar, Calendar.MILLISECOND));
@@ -165,6 +173,7 @@ public class DateUtilsFragmentTest exten
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.MILLISECOND));
}
+ @Test
public void testSecondFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInSeconds(aDate, Calendar.SECOND));
assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.SECOND));
@@ -172,6 +181,7 @@ public class DateUtilsFragmentTest exten
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.SECOND));
}
+ @Test
public void testSecondFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInSeconds(aCalendar, Calendar.SECOND));
assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.SECOND));
@@ -179,51 +189,61 @@ public class DateUtilsFragmentTest exten
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.SECOND));
}
+ @Test
public void testMinuteFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInMinutes(aDate, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.MINUTE));
}
+ @Test
public void testMinuteFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInMinutes(aCalendar, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.MINUTE));
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.MINUTE));
}
+ @Test
public void testHourOfDayFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInHours(aDate, Calendar.HOUR_OF_DAY));
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.HOUR_OF_DAY));
}
+ @Test
public void testHourOfDayFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInHours(aCalendar, Calendar.HOUR_OF_DAY));
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.HOUR_OF_DAY));
}
+ @Test
public void testDayOfYearFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.DAY_OF_YEAR));
}
+ @Test
public void testDayOfYearFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.DAY_OF_YEAR));
}
+ @Test
public void testDateFragmentInLargerUnitWithDate() {
assertEquals(0, DateUtils.getFragmentInDays(aDate, Calendar.DATE));
}
+ @Test
public void testDateFragmentInLargerUnitWithCalendar() {
assertEquals(0, DateUtils.getFragmentInDays(aCalendar, Calendar.DATE));
}
//Calendar.SECOND as useful fragment
+ @Test
public void testMillisecondsOfSecondWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.SECOND);
assertEquals(millis, testResult);
}
+ @Test
public void testMillisecondsOfSecondWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.SECOND);
assertEquals(millis, testResult);
@@ -232,21 +252,25 @@ public class DateUtilsFragmentTest exten
//Calendar.MINUTE as useful fragment
+ @Test
public void testMillisecondsOfMinuteWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MINUTE);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult);
}
+ @Test
public void testMillisecondsOfMinuteWithCalender() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MINUTE);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND), testResult);
}
+ @Test
public void testSecondsofMinuteWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MINUTE);
assertEquals(seconds, testResult);
}
+ @Test
public void testSecondsofMinuteWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MINUTE);
assertEquals(seconds, testResult);
@@ -255,16 +279,19 @@ public class DateUtilsFragmentTest exten
//Calendar.HOUR_OF_DAY as useful fragment
+ @Test
public void testMillisecondsOfHourWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.HOUR_OF_DAY);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult);
}
+ @Test
public void testMillisecondsOfHourWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE), testResult);
}
+ @Test
public void testSecondsofHourWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.HOUR_OF_DAY);
assertEquals(
@@ -274,6 +301,7 @@ public class DateUtilsFragmentTest exten
testResult);
}
+ @Test
public void testSecondsofHourWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals(
@@ -283,17 +311,20 @@ public class DateUtilsFragmentTest exten
testResult);
}
+ @Test
public void testMinutesOfHourWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.HOUR_OF_DAY);
assertEquals(minutes, testResult);
}
+ @Test
public void testMinutesOfHourWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.HOUR_OF_DAY);
assertEquals(minutes, testResult);
}
//Calendar.DATE and Calendar.DAY_OF_YEAR as useful fragment
+ @Test
public void testMillisecondsOfDayWithDate() {
long testresult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.DATE);
long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR);
@@ -302,6 +333,7 @@ public class DateUtilsFragmentTest exten
assertEquals(expectedValue, testresult);
}
+ @Test
public void testMillisecondsOfDayWithCalendar() {
long testresult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.DATE);
long expectedValue = millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR);
@@ -310,6 +342,7 @@ public class DateUtilsFragmentTest exten
assertEquals(expectedValue, testresult);
}
+ @Test
public void testSecondsOfDayWithDate() {
long testresult = DateUtils.getFragmentInSeconds(aDate, Calendar.DATE);
long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND;
@@ -318,6 +351,7 @@ public class DateUtilsFragmentTest exten
assertEquals(expectedValue, testresult);
}
+ @Test
public void testSecondsOfDayWithCalendar() {
long testresult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.DATE);
long expectedValue = seconds + ((minutes * DateUtils.MILLIS_PER_MINUTE) + (hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_SECOND;
@@ -326,6 +360,7 @@ public class DateUtilsFragmentTest exten
assertEquals(expectedValue, testresult);
}
+ @Test
public void testMinutesOfDayWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.DATE);
long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE;
@@ -334,6 +369,7 @@ public class DateUtilsFragmentTest exten
assertEquals(expectedValue,testResult);
}
+ @Test
public void testMinutesOfDayWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.DATE);
long expectedValue = minutes + ((hours * DateUtils.MILLIS_PER_HOUR))/ DateUtils.MILLIS_PER_MINUTE;
@@ -342,6 +378,7 @@ public class DateUtilsFragmentTest exten
assertEquals(expectedValue, testResult);
}
+ @Test
public void testHoursOfDayWithDate() {
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.DATE);
long expectedValue = hours;
@@ -350,6 +387,7 @@ public class DateUtilsFragmentTest exten
assertEquals(expectedValue,testResult);
}
+ @Test
public void testHoursOfDayWithCalendar() {
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.DATE);
long expectedValue = hours;
@@ -360,6 +398,7 @@ public class DateUtilsFragmentTest exten
//Calendar.MONTH as useful fragment
+ @Test
public void testMillisecondsOfMonthWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.MONTH);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
@@ -367,6 +406,7 @@ public class DateUtilsFragmentTest exten
testResult);
}
+ @Test
public void testMillisecondsOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.MONTH);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
@@ -374,6 +414,7 @@ public class DateUtilsFragmentTest exten
testResult);
}
+ @Test
public void testSecondsOfMonthWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.MONTH);
assertEquals(
@@ -384,6 +425,7 @@ testResult);
testResult);
}
+ @Test
public void testSecondsOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.MONTH);
assertEquals(
@@ -394,6 +436,7 @@ testResult);
testResult);
}
+ @Test
public void testMinutesOfMonthWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.MONTH);
assertEquals(minutes
@@ -402,6 +445,7 @@ testResult);
testResult);
}
+ @Test
public void testMinutesOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.MONTH);
assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + (days * DateUtils.MILLIS_PER_DAY))
@@ -409,6 +453,7 @@ testResult);
testResult);
}
+ @Test
public void testHoursOfMonthWithDate() {
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.MONTH);
assertEquals(hours + ((days * DateUtils.MILLIS_PER_DAY))
@@ -416,6 +461,7 @@ testResult);
testResult);
}
+ @Test
public void testHoursOfMonthWithCalendar() {
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.MONTH);
assertEquals( hours +((days * DateUtils.MILLIS_PER_DAY))
@@ -424,6 +470,7 @@ testResult);
}
//Calendar.YEAR as useful fragment
+ @Test
public void testMillisecondsOfYearWithDate() {
long testResult = DateUtils.getFragmentInMilliseconds(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance();
@@ -433,6 +480,7 @@ testResult);
testResult);
}
+ @Test
public void testMillisecondsOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInMilliseconds(aCalendar, Calendar.YEAR);
assertEquals(millis + (seconds * DateUtils.MILLIS_PER_SECOND) + (minutes * DateUtils.MILLIS_PER_MINUTE)
@@ -440,6 +488,7 @@ testResult);
testResult);
}
+ @Test
public void testSecondsOfYearWithDate() {
long testResult = DateUtils.getFragmentInSeconds(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance();
@@ -452,6 +501,7 @@ testResult);
testResult);
}
+ @Test
public void testSecondsOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInSeconds(aCalendar, Calendar.YEAR);
assertEquals(
@@ -462,6 +512,7 @@ testResult);
testResult);
}
+ @Test
public void testMinutesOfYearWithDate() {
long testResult = DateUtils.getFragmentInMinutes(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance();
@@ -472,6 +523,7 @@ testResult);
testResult);
}
+ @Test
public void testMinutesOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInMinutes(aCalendar, Calendar.YEAR);
assertEquals( minutes +((hours * DateUtils.MILLIS_PER_HOUR) + (aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
@@ -479,6 +531,7 @@ testResult);
testResult);
}
+ @Test
public void testHoursOfYearWithDate() {
long testResult = DateUtils.getFragmentInHours(aDate, Calendar.YEAR);
Calendar cal = Calendar.getInstance();
@@ -488,6 +541,7 @@ testResult);
testResult);
}
+ @Test
public void testHoursOfYearWithCalendar() {
long testResult = DateUtils.getFragmentInHours(aCalendar, Calendar.YEAR);
assertEquals( hours +((aCalendar.get(Calendar.DAY_OF_YEAR) * DateUtils.MILLIS_PER_DAY))
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsRoundingTest.java Tue Sep 18 21:07:42 2012
@@ -16,14 +16,15 @@
*/
package org.apache.commons.lang3.time;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
-import junit.framework.TestCase;
-
/**
* These Unit-tests will check all possible extremes when using some rounding-methods of DateUtils.
* The extremes are tested at the switch-point in milliseconds
@@ -37,7 +38,7 @@ import junit.framework.TestCase;
* @since 3.0
* @version $Id$
*/
-public class DateUtilsRoundingTest extends TestCase {
+public class DateUtilsRoundingTest {
DateFormat dateTimeParser;
@@ -53,9 +54,10 @@ public class DateUtilsRoundingTest exten
Calendar januaryOneCalendar;
FastDateFormat fdf = DateFormatUtils.ISO_DATETIME_FORMAT;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+
+ @Before
+ public void setUp() throws Exception {
+
dateTimeParser = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS", Locale.ENGLISH);
targetYearDate = dateTimeParser.parse("January 1, 2007 0:00:00.000");
@@ -79,6 +81,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundYear() throws Exception {
final int calendarField = Calendar.YEAR;
Date roundedUpDate = dateTimeParser.parse("January 1, 2008 0:00:00.000");
@@ -95,6 +98,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundMonth() throws Exception {
final int calendarField = Calendar.MONTH;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -138,6 +142,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundSemiMonth() throws Exception {
final int calendarField = DateUtils.SEMI_MONTH;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -205,6 +210,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundDate() throws Exception {
final int calendarField = Calendar.DATE;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -229,6 +235,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundDayOfMonth() throws Exception {
final int calendarField = Calendar.DAY_OF_MONTH;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -253,6 +260,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundAmPm() throws Exception {
final int calendarField = Calendar.AM_PM;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -284,6 +292,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundHourOfDay() throws Exception {
final int calendarField = Calendar.HOUR_OF_DAY;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -308,6 +317,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundHour() throws Exception {
final int calendarField = Calendar.HOUR;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -332,6 +342,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundMinute() throws Exception {
final int calendarField = Calendar.MINUTE;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -356,6 +367,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundSecond() throws Exception {
final int calendarField = Calendar.SECOND;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -380,6 +392,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testRoundMilliSecond() throws Exception {
final int calendarField = Calendar.MILLISECOND;
Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
@@ -400,6 +413,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateYear() throws Exception {
final int calendarField = Calendar.YEAR;
Date lastTruncateDate = dateTimeParser.parse("December 31, 2007 23:59:59.999");
@@ -412,6 +426,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateMonth() throws Exception {
final int calendarField = Calendar.MONTH;
Date truncatedDate = dateTimeParser.parse("March 1, 2008 0:00:00.000");
@@ -426,6 +441,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateSemiMonth() throws Exception {
final int calendarField = DateUtils.SEMI_MONTH;
Date truncatedDate, lastTruncateDate;
@@ -478,6 +494,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateDate() throws Exception {
final int calendarField = Calendar.DATE;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
@@ -490,6 +507,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateDayOfMonth() throws Exception {
final int calendarField = Calendar.DAY_OF_MONTH;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
@@ -503,6 +521,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateAmPm() throws Exception {
final int calendarField = Calendar.AM_PM;
@@ -521,6 +540,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateHour() throws Exception {
final int calendarField = Calendar.HOUR;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:59:59.999");
@@ -533,6 +553,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateHourOfDay() throws Exception {
final int calendarField = Calendar.HOUR_OF_DAY;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:59:59.999");
@@ -545,6 +566,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateMinute() throws Exception {
final int calendarField = Calendar.MINUTE;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:15:59.999");
@@ -557,6 +579,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateSecond() throws Exception {
final int calendarField = Calendar.SECOND;
Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 8:15:14.999");
@@ -569,6 +592,7 @@ public class DateUtilsRoundingTest exten
* @throws Exception
* @since 3.0
*/
+ @Test
public void testTruncateMilliSecond() throws Exception {
final int calendarField = Calendar.MILLISECOND;
baseTruncateTest(targetMilliSecondDate, targetMilliSecondDate, calendarField);
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java Tue Sep 18 21:07:42 2012
@@ -16,6 +16,9 @@
*/
package org.apache.commons.lang3.time;
+import org.junit.Test;
+import org.junit.Before;
+import static org.junit.Assert.*;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_4;
import java.lang.reflect.Constructor;
@@ -32,15 +35,13 @@ import java.util.NoSuchElementException;
import java.util.TimeZone;
import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
import org.apache.commons.lang3.SystemUtils;
/**
* Unit tests {@link org.apache.commons.lang3.time.DateUtils}.
*
*/
-public class DateUtilsTest extends TestCase {
+public class DateUtilsTest {
private static final long MILLIS_TEST;
static {
@@ -80,13 +81,10 @@ public class DateUtilsTest extends TestC
TimeZone zone = null;
TimeZone defaultZone = null;
- public DateUtilsTest(String name) {
- super(name);
- }
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
+
dateParser = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
dateTimeParser = new SimpleDateFormat("MMM dd, yyyy H:mm:ss.SSS", Locale.ENGLISH);
@@ -139,6 +137,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new DateUtils());
Constructor<?>[] cons = DateUtils.class.getDeclaredConstructors();
@@ -149,6 +148,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testIsSameDay_Date() {
Date date1 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
Date date2 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
@@ -166,6 +166,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testIsSameDay_Cal() {
GregorianCalendar cal1 = new GregorianCalendar(2004, 6, 9, 13, 45);
GregorianCalendar cal2 = new GregorianCalendar(2004, 6, 9, 13, 45);
@@ -183,6 +184,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testIsSameInstant_Date() {
Date date1 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
Date date2 = new GregorianCalendar(2004, 6, 9, 13, 45).getTime();
@@ -200,6 +202,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testIsSameInstant_Cal() {
GregorianCalendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("GMT+1"));
GregorianCalendar cal2 = new GregorianCalendar(TimeZone.getTimeZone("GMT-1"));
@@ -218,6 +221,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testIsSameLocalTime_Cal() {
GregorianCalendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("GMT+1"));
GregorianCalendar cal2 = new GregorianCalendar(TimeZone.getTimeZone("GMT-1"));
@@ -244,6 +248,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testParseDate() throws Exception {
GregorianCalendar cal = new GregorianCalendar(1972, 11, 3);
String dateStr = "1972-12-03";
@@ -281,6 +286,7 @@ public class DateUtilsTest extends TestC
} catch (ParseException ex) {}
}
// LANG-486
+ @Test
public void testParseDateWithLeniency() throws Exception {
GregorianCalendar cal = new GregorianCalendar(1998, 6, 30);
String dateStr = "02 942, 1996";
@@ -296,6 +302,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testAddYears() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addYears(base, 0);
@@ -315,6 +322,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testAddMonths() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addMonths(base, 0);
@@ -334,6 +342,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testAddWeeks() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addWeeks(base, 0);
@@ -353,6 +362,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testAddDays() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addDays(base, 0);
@@ -372,6 +382,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testAddHours() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addHours(base, 0);
@@ -391,6 +402,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testAddMinutes() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addMinutes(base, 0);
@@ -410,6 +422,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testAddSeconds() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addSeconds(base, 0);
@@ -429,6 +442,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testAddMilliseconds() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.addMilliseconds(base, 0);
@@ -448,6 +462,7 @@ public class DateUtilsTest extends TestC
}
// -----------------------------------------------------------------------
+ @Test
public void testSetYears() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setYears(base, 2000);
@@ -467,6 +482,7 @@ public class DateUtilsTest extends TestC
}
// -----------------------------------------------------------------------
+ @Test
public void testSetMonths() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setMonths(base, 5);
@@ -488,6 +504,7 @@ public class DateUtilsTest extends TestC
}
// -----------------------------------------------------------------------
+ @Test
public void testSetDays() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setDays(base, 1);
@@ -509,6 +526,7 @@ public class DateUtilsTest extends TestC
}
// -----------------------------------------------------------------------
+ @Test
public void testSetHours() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setHours(base, 0);
@@ -530,6 +548,7 @@ public class DateUtilsTest extends TestC
}
// -----------------------------------------------------------------------
+ @Test
public void testSetMinutes() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setMinutes(base, 0);
@@ -551,6 +570,7 @@ public class DateUtilsTest extends TestC
}
// -----------------------------------------------------------------------
+ @Test
public void testSetSeconds() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setSeconds(base, 0);
@@ -572,6 +592,7 @@ public class DateUtilsTest extends TestC
}
// -----------------------------------------------------------------------
+ @Test
public void testSetMilliseconds() throws Exception {
Date base = new Date(MILLIS_TEST);
Date result = DateUtils.setMilliseconds(base, 0);
@@ -606,6 +627,7 @@ public class DateUtilsTest extends TestC
}
//-----------------------------------------------------------------------
+ @Test
public void testToCalendar() {
assertEquals("Failed to convert to a Calendar and back", date1, DateUtils.toCalendar(date1).getTime());
try {
@@ -620,6 +642,7 @@ public class DateUtilsTest extends TestC
/**
* Tests various values with the round method
*/
+ @Test
public void testRound() throws Exception {
// tests for public static Date round(Date date, int field)
assertEquals("round year-1 failed",
@@ -843,6 +866,7 @@ public class DateUtilsTest extends TestC
* Tests the Changes Made by LANG-346 to the DateUtils.modify() private method invoked
* by DateUtils.round().
*/
+ @Test
public void testRoundLang346() throws Exception
{
TimeZone.setDefault(defaultZone);
@@ -905,6 +929,7 @@ public class DateUtilsTest extends TestC
/**
* Tests various values with the trunc method
*/
+ @Test
public void testTruncate() throws Exception {
// tests public static Date truncate(Date date, int field)
assertEquals("truncate year-1 failed",
@@ -1098,6 +1123,7 @@ public class DateUtilsTest extends TestC
*
* see http://issues.apache.org/jira/browse/LANG-59
*/
+ @Test
public void testTruncateLang59() throws Exception {
if (!SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) {
this.warn("WARNING: Test for LANG-59 not run since the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION);
@@ -1173,6 +1199,7 @@ public class DateUtilsTest extends TestC
}
// http://issues.apache.org/jira/browse/LANG-530
+ @Test
public void testLang530() throws ParseException {
Date d = new Date();
String isoDateStr = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(d);
@@ -1184,6 +1211,7 @@ public class DateUtilsTest extends TestC
/**
* Tests various values with the ceiling method
*/
+ @Test
public void testCeil() throws Exception {
// test javadoc
assertEquals("ceiling javadoc-1 failed",
@@ -1433,6 +1461,7 @@ public class DateUtilsTest extends TestC
/**
* Tests the iterator exceptions
*/
+ @Test
public void testIteratorEx() throws Exception {
try {
DateUtils.iterator(Calendar.getInstance(), -9999);
@@ -1458,6 +1487,7 @@ public class DateUtilsTest extends TestC
/**
* Tests the calendar iterator for week ranges
*/
+ @Test
public void testWeekIterator() throws Exception {
Calendar now = Calendar.getInstance();
for (int i = 0; i< 7; i++) {
@@ -1504,6 +1534,7 @@ public class DateUtilsTest extends TestC
/**
* Tests the calendar iterator for month-based ranges
*/
+ @Test
public void testMonthIterator() throws Exception {
Iterator<?> it = DateUtils.iterator(date1, DateUtils.RANGE_MONTH_SUNDAY);
assertWeekIterator(it,
@@ -1556,12 +1587,12 @@ public class DateUtilsTest extends TestC
*/
private static void assertWeekIterator(Iterator<?> it, Calendar start, Calendar end) {
Calendar cal = (Calendar) it.next();
- assertEquals("", start, cal, 0);
+ assertCalendarsEquals("", start, cal, 0);
Calendar last = null;
int count = 1;
while (it.hasNext()) {
//Check this is just a date (no time component)
- assertEquals("", cal, DateUtils.truncate(cal, Calendar.DATE), 0);
+ assertCalendarsEquals("", cal, DateUtils.truncate(cal, Calendar.DATE), 0);
last = cal;
cal = (Calendar) it.next();
@@ -1569,19 +1600,19 @@ public class DateUtilsTest extends TestC
//Check that this is one day more than the last date
last.add(Calendar.DATE, 1);
- assertEquals("", last, cal, 0);
+ assertCalendarsEquals("", last, cal, 0);
}
if (count % 7 != 0) {
throw new AssertionFailedError("There were " + count + " days in this iterator");
}
- assertEquals("", end, cal, 0);
+ assertCalendarsEquals("", end, cal, 0);
}
/**
* Used to check that Calendar objects are close enough
* delta is in milliseconds
*/
- private static void assertEquals(String message, Calendar cal1, Calendar cal2, long delta) {
+ private static void assertCalendarsEquals(String message, Calendar cal1, Calendar cal2, long delta) {
if (Math.abs(cal1.getTime().getTime() - cal2.getTime().getTime()) > delta) {
throw new AssertionFailedError(
message + " expected " + cal1.getTime() + " but got " + cal2.getTime());
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/DurationFormatUtilsTest.java Tue Sep 18 21:07:42 2012
@@ -17,24 +17,21 @@
package org.apache.commons.lang3.time;
+import org.junit.Test;
+import static org.junit.Assert.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Calendar;
import java.util.TimeZone;
-import junit.framework.TestCase;
-
/**
* TestCase for DurationFormatUtils.
*
*/
-public class DurationFormatUtilsTest extends TestCase {
-
- public DurationFormatUtilsTest(String s) {
- super(s);
- }
+public class DurationFormatUtilsTest {
// -----------------------------------------------------------------------
+ @Test
public void testConstructor() {
assertNotNull(new DurationFormatUtils());
Constructor<?>[] cons = DurationFormatUtils.class.getDeclaredConstructors();
@@ -45,6 +42,7 @@ public class DurationFormatUtilsTest ext
}
// -----------------------------------------------------------------------
+ @Test
public void testFormatDurationWords() {
String text = null;
@@ -132,6 +130,7 @@ public class DurationFormatUtilsTest ext
/**
* Tests that "1 <unit>s" gets converted to "1 <unit>" but that "11 <unit>s" is left alone.
*/
+ @Test
public void testFormatDurationPluralWords() {
long oneSecond = 1000;
long oneMinute = oneSecond * 60;
@@ -174,6 +173,7 @@ public class DurationFormatUtilsTest ext
assertEquals("1 day 1 hour 1 minute 1 second", text);
}
+ @Test
public void testFormatDurationHMS() {
long time = 0;
assertEquals("0:00:00.000", DurationFormatUtils.formatDurationHMS(time));
@@ -203,6 +203,7 @@ public class DurationFormatUtilsTest ext
assertEquals("1:02:12.789", DurationFormatUtils.formatDurationHMS(time));
}
+ @Test
public void testFormatDurationISO() {
assertEquals("P0Y0M0DT0H0M0.000S", DurationFormatUtils.formatDurationISO(0L));
assertEquals("P0Y0M0DT0H0M0.001S", DurationFormatUtils.formatDurationISO(1L));
@@ -211,6 +212,7 @@ public class DurationFormatUtilsTest ext
assertEquals("P0Y0M0DT0H1M15.321S", DurationFormatUtils.formatDurationISO(75321L));
}
+ @Test
public void testFormatDuration() {
long duration = 0;
assertEquals("0", DurationFormatUtils.formatDuration(duration, "y"));
@@ -248,6 +250,7 @@ public class DurationFormatUtilsTest ext
assertEquals("0 0 " + days, DurationFormatUtils.formatDuration(duration, "y M d"));
}
+ @Test
public void testFormatPeriodISO() {
TimeZone timeZone = TimeZone.getTimeZone("GMT-3");
Calendar base = Calendar.getInstance(timeZone);
@@ -275,6 +278,7 @@ public class DurationFormatUtilsTest ext
// assertEquals("P1Y2M3DT10H30M", text);
}
+ @Test
public void testFormatPeriod() {
Calendar cal1970 = Calendar.getInstance();
cal1970.set(1970, 0, 1, 0, 0, 0);
@@ -328,6 +332,7 @@ public class DurationFormatUtilsTest ext
assertEquals("048", DurationFormatUtils.formatPeriod(time1970, time, "MMM"));
}
+ @Test
public void testLexx() {
// tests each constant
assertArrayEquals(new DurationFormatUtils.Token[]{
@@ -381,18 +386,21 @@ public class DurationFormatUtilsTest ext
// http://issues.apache.org/bugzilla/show_bug.cgi?id=38401
+ @Test
public void testBugzilla38401() {
assertEqualDuration( "0000/00/30 16:00:00 000", new int[] { 2006, 0, 26, 18, 47, 34 },
new int[] { 2006, 1, 26, 10, 47, 34 }, "yyyy/MM/dd HH:mm:ss SSS");
}
// https://issues.apache.org/jira/browse/LANG-281
+ @Test
public void testJiraLang281() {
assertEqualDuration( "09", new int[] { 2005, 11, 31, 0, 0, 0 },
new int[] { 2006, 9, 6, 0, 0, 0 }, "MM");
}
// Testing the under a day range in DurationFormatUtils.formatPeriod
+ @Test
public void testLowDurations() {
for(int hr=0; hr < 24; hr++) {
for(int min=0; min < 60; min++) {
@@ -408,6 +416,7 @@ public class DurationFormatUtilsTest ext
}
// Attempting to test edge cases in DurationFormatUtils.formatPeriod
+ @Test
public void testEdgeDurations() {
assertEqualDuration( "01", new int[] { 2006, 0, 15, 0, 0, 0 },
new int[] { 2006, 2, 10, 0, 0, 0 }, "MM");
@@ -497,6 +506,7 @@ public class DurationFormatUtilsTest ext
}
+ @Test
public void testDurationsByBruteForce() {
bruteForce(2006, 0, 1, "d", Calendar.DAY_OF_MONTH);
bruteForce(2006, 0, 2, "d", Calendar.DAY_OF_MONTH);
Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java?rev=1387361&r1=1387360&r2=1387361&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java (original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java Tue Sep 18 21:07:42 2012
@@ -16,21 +16,22 @@
*/
package org.apache.commons.lang3.time;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import junit.framework.Assert;
-import junit.framework.TestCase;
+
+import org.junit.Test;
/**
* TestCase for StopWatch.
*
* @version $Id$
*/
-public class StopWatchTest extends TestCase {
-
- public StopWatchTest(String s) {
- super(s);
- }
+public class StopWatchTest {
//-----------------------------------------------------------------------
+ @Test
public void testStopWatchSimple(){
StopWatch watch = new StopWatch();
watch.start();
@@ -46,6 +47,7 @@ public class StopWatchTest extends TestC
assertEquals(0, watch.getTime());
}
+ @Test
public void testStopWatchSimpleGet(){
StopWatch watch = new StopWatch();
assertEquals(0, watch.getTime());
@@ -56,6 +58,7 @@ public class StopWatchTest extends TestC
assertTrue(watch.getTime() < 2000);
}
+ @Test
public void testStopWatchSplit(){
StopWatch watch = new StopWatch();
watch.start();
@@ -77,6 +80,7 @@ public class StopWatchTest extends TestC
assertTrue(totalTime < 1900);
}
+ @Test
public void testStopWatchSuspend(){
StopWatch watch = new StopWatch();
watch.start();
@@ -95,6 +99,7 @@ public class StopWatchTest extends TestC
assertTrue(totalTime < 1300);
}
+ @Test
public void testLang315() {
StopWatch watch = new StopWatch();
watch.start();
@@ -108,6 +113,7 @@ public class StopWatchTest extends TestC
}
// test bad states
+ @Test
public void testBadStates() {
StopWatch watch = new StopWatch();
try {
@@ -192,6 +198,7 @@ public class StopWatchTest extends TestC
}
}
+ @Test
public void testGetStartTime() {
long beforeStopWatch = System.currentTimeMillis();
StopWatch watch = new StopWatch();