You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by rd...@apache.org on 2012/05/13 19:22:22 UTC

svn commit: r1337943 [2/2] - in /creadur/main/trunk: apache-rat-core/src/test/java/org/apache/rat/ apache-rat-core/src/test/java/org/apache/rat/analysis/ apache-rat-core/src/test/java/org/apache/rat/analysis/generation/ apache-rat-core/src/test/java/or...

Modified: creadur/main/trunk/apache-rat-core/src/test/java/org/apache/rat/report/xml/writer/impl/base/XmlWriterTest.java
URL: http://svn.apache.org/viewvc/creadur/main/trunk/apache-rat-core/src/test/java/org/apache/rat/report/xml/writer/impl/base/XmlWriterTest.java?rev=1337943&r1=1337942&r2=1337943&view=diff
==============================================================================
--- creadur/main/trunk/apache-rat-core/src/test/java/org/apache/rat/report/xml/writer/impl/base/XmlWriterTest.java (original)
+++ creadur/main/trunk/apache-rat-core/src/test/java/org/apache/rat/report/xml/writer/impl/base/XmlWriterTest.java Sun May 13 17:22:20 2012
@@ -18,30 +18,33 @@
  */ 
 package org.apache.rat.report.xml.writer.impl.base;
 
-import java.io.StringWriter;
-
-import junit.framework.TestCase;
 import org.apache.rat.report.xml.writer.InvalidXmlException;
 import org.apache.rat.report.xml.writer.OperationNotAllowedException;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.StringWriter;
 
-public class XmlWriterTest extends TestCase {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class XmlWriterTest {
 
     private static final char[] ZERO_CHAR = {(char)0};
     
     XmlWriter writer;
     StringWriter out;
     
-    protected void setUp() throws Exception {
-        super.setUp();
+    @Before
+    public void setUp() throws Exception {
         out = new StringWriter();
         writer = new XmlWriter(out);
     }
 
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }
-
-    public void testReturnValues() throws Exception {
+    @Test
+    public void returnValues() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("XmlWriters should always return themselves", 
@@ -52,7 +55,8 @@ public class XmlWriterTest extends TestC
                 writer, writer.closeElement());
     }
 
-    public void testOpenElement() throws Exception {
+    @Test
+    public void openElement() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -67,7 +71,8 @@ public class XmlWriterTest extends TestC
         assertEquals("Gamma tag started", "<alpha><beta/><gamma", out.toString());
     }
     
-    public void testInvalidElementName() throws Exception {
+    @Test
+    public void invalidElementName() throws Exception {
         assertTrue("All strings ok", isValidElementName("alpha"));
         assertTrue("Strings and digits ok", isValidElementName("alpha77"));
         assertFalse("Must no start with digit", isValidElementName("5alpha77"));
@@ -93,8 +98,9 @@ public class XmlWriterTest extends TestC
         }
         return result;
     }
-    
-    public void testCallOpenElementAfterLastElementClosed() throws Exception {
+
+    @Test
+    public void callOpenElementAfterLastElementClosed() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -108,8 +114,9 @@ public class XmlWriterTest extends TestC
             // Cannot open new elements once the first element has been closed
         }
     }    
-    
-    public void testCallCloseElementAfterLastElementClosed() throws Exception {
+
+    @Test
+    public void callCloseElementAfterLastElementClosed() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -123,9 +130,9 @@ public class XmlWriterTest extends TestC
             // Cannot open new elements once the first element has been closed
         }
     }
-    
-    
-    public void testCloseFirstElement() throws Exception {
+
+    @Test
+    public void closeFirstElement() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -134,7 +141,8 @@ public class XmlWriterTest extends TestC
         assertEquals("Element alpha is closed", "<alpha/>", out.toString());
     }
     
-    public void testCloseElementWithContent() throws Exception {
+    @Test
+    public void closeElementWithContent() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -155,7 +163,8 @@ public class XmlWriterTest extends TestC
         }
     }
     
-    public void testCloseElementBeforeFirstElement() throws Exception {
+    @Test
+    public void closeElementBeforeFirstElement() throws Exception {
         try {
             writer.closeElement();
             fail("Cannot close elements before the first element has been closed");
@@ -164,7 +173,8 @@ public class XmlWriterTest extends TestC
         }
     }
     
-    public void testContentAfterElement() throws Exception {
+    @Test
+    public void contentAfterElement() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -190,9 +200,9 @@ public class XmlWriterTest extends TestC
             // Cannot open new elements once the first element has been closed
         }
     }
-    
 
-    public void testContentAfterLastElement() throws Exception {
+    @Test
+    public void contentAfterLastElement() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -207,7 +217,8 @@ public class XmlWriterTest extends TestC
         }
     }
     
-    public void testWriteContentBeforeFirstElement() throws Exception {
+    @Test
+    public void writeContentBeforeFirstElement() throws Exception {
         try {
             writer.content("Too early");
             fail("Cannot close elements before the first element has been closed");
@@ -216,7 +227,8 @@ public class XmlWriterTest extends TestC
         }
     }
     
-    public void testContentEscaping() throws Exception {
+    @Test
+    public void contentEscaping() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -232,7 +244,8 @@ public class XmlWriterTest extends TestC
 
     }
 
-    public void testAttributeAfterLastElement() throws Exception {
+    @Test
+    public void attributeAfterLastElement() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -247,7 +260,8 @@ public class XmlWriterTest extends TestC
         }
     }
     
-    public void testAttributeContentBeforeFirstElement() throws Exception {
+    @Test
+    public void attributeContentBeforeFirstElement() throws Exception {
         try {
             writer.attribute("foo", "bar");
             fail("Cannot close elements before the first element has been closed");
@@ -256,7 +270,8 @@ public class XmlWriterTest extends TestC
         }
     }
     
-    public void testInvalidAttributeName() throws Exception {
+    @Test
+    public void invalidAttributeName() throws Exception {
         writer.openElement("alpha");
         assertTrue("All strings ok", isValidAttributeName("alpha"));
         assertTrue("Strings and digits ok", isValidAttributeName("alpha77"));
@@ -277,7 +292,8 @@ public class XmlWriterTest extends TestC
         return result;
     }
     
-    public void testEscapeAttributeContent() throws Exception {
+    @Test
+    public void escapeAttributeContent() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -299,7 +315,8 @@ public class XmlWriterTest extends TestC
 
     }
     
-    public void testAttributeInContent() throws Exception {
+    @Test
+    public void attributeInContent() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -313,7 +330,8 @@ public class XmlWriterTest extends TestC
         }
     }
   
-    public void testOutOfRangeCharacter() throws Exception {
+    @Test
+    public void outOfRangeCharacter() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -323,7 +341,8 @@ public class XmlWriterTest extends TestC
         assertEquals("Replace illegal characters with question marks", "<alpha>?", out);
     }
     
-    public void testAttributeAfterElementClosed() throws Exception {
+    @Test
+    public void attributeAfterElementClosed() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -341,7 +360,8 @@ public class XmlWriterTest extends TestC
         }
     }
     
-    public void testCloseDocumentBeforeOpen() throws Exception {
+    @Test
+    public void closeDocumentBeforeOpen() throws Exception {
         try {
             writer.closeDocument();
             fail("Cannot close document before the first element has been opened");
@@ -350,7 +370,8 @@ public class XmlWriterTest extends TestC
         }
     }
     
-    public void testCloseDocumentAfterRootElementClosed() throws Exception {
+    @Test
+    public void closeDocumentAfterRootElementClosed() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -364,7 +385,8 @@ public class XmlWriterTest extends TestC
         }
     }   
     
-    public void testCloseSimpleDocument() throws Exception {
+    @Test
+    public void closeSimpleDocument() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -376,7 +398,8 @@ public class XmlWriterTest extends TestC
         assertEquals("Beta element started", "<alpha><beta/></alpha>", out.toString());
     }
     
-    public void testCloseComplexDocument() throws Exception {
+    @Test
+    public void closeComplexDocument() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -403,13 +426,15 @@ public class XmlWriterTest extends TestC
         assertEquals("Beta element started", "<alpha><beta name='value'/><beta name='value'><gamma/></beta></alpha>", out.toString());
     }
     
-    public void testWriteProlog() throws Exception {
+    @Test
+    public void writeProlog() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.startDocument());
         assertEquals("Prolog written", "<?xml version='1.0'?>", out.toString());
     }
     
-    public void testWriteAfterElement() throws Exception {
+    @Test
+    public void writeAfterElement() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());
@@ -421,7 +446,8 @@ public class XmlWriterTest extends TestC
         }
     }
     
-    public void testWritePrologTwo() throws Exception {
+    @Test
+    public void writePrologTwo() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.startDocument());
         assertEquals("Prolog written", "<?xml version='1.0'?>", out.toString());
@@ -433,7 +459,8 @@ public class XmlWriterTest extends TestC
         }
     }
     
-    public void testDuplicateAttributes() throws Exception {
+    @Test
+    public void duplicateAttributes() throws Exception {
         assertEquals("XmlWriters should always return themselves", 
                 writer, writer.openElement("alpha"));
         assertEquals("Alpha element started", "<alpha", out.toString());

Modified: creadur/main/trunk/apache-rat-core/src/test/java/org/apache/rat/walker/FileNameComparatorTest.java
URL: http://svn.apache.org/viewvc/creadur/main/trunk/apache-rat-core/src/test/java/org/apache/rat/walker/FileNameComparatorTest.java?rev=1337943&r1=1337942&r2=1337943&view=diff
==============================================================================
--- creadur/main/trunk/apache-rat-core/src/test/java/org/apache/rat/walker/FileNameComparatorTest.java (original)
+++ creadur/main/trunk/apache-rat-core/src/test/java/org/apache/rat/walker/FileNameComparatorTest.java Sun May 13 17:22:20 2012
@@ -18,26 +18,20 @@
  */ 
 package org.apache.rat.walker;
 
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
 import org.apache.rat.test.utils.Resources;
+import org.junit.Test;
 
-public class FileNameComparatorTest extends TestCase {
+import java.io.IOException;
 
-    FileNameComparator comparator;
-    
-    protected void setUp() throws Exception {
-        super.setUp();
-        comparator = new FileNameComparator();
-    }
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }
+public class FileNameComparatorTest {
 
-    public void testCompare() throws IOException {
+    @Test
+    public void compare() throws IOException {
+        FileNameComparator comparator = new FileNameComparator();
+        assertNotNull(comparator);
         final int compare = comparator.compare(Resources.getResourceFile("elements/LICENSE"), Resources.getResourceFile("elements/NOTICE"));
         assertTrue("LICENSE is before NOTICE", compare < 0);
     }

Modified: creadur/main/trunk/apache-rat-plugin/src/test/java/org/apache/rat/mp/RatCheckMojoTest.java
URL: http://svn.apache.org/viewvc/creadur/main/trunk/apache-rat-plugin/src/test/java/org/apache/rat/mp/RatCheckMojoTest.java?rev=1337943&r1=1337942&r2=1337943&view=diff
==============================================================================
--- creadur/main/trunk/apache-rat-plugin/src/test/java/org/apache/rat/mp/RatCheckMojoTest.java (original)
+++ creadur/main/trunk/apache-rat-plugin/src/test/java/org/apache/rat/mp/RatCheckMojoTest.java Sun May 13 17:22:20 2012
@@ -207,9 +207,8 @@ public class RatCheckMojoTest extends Ab
         else if ( pDir.isDirectory() )
         {
             final File[] files = pDir.listFiles();
-            for ( int i = 0;  i < files.length;  i++ )
-            {
-                remove( files[i] );
+            for (File file : files) {
+                remove(file);
             }
             if ( ! pDir.delete() )
             {
@@ -235,16 +234,15 @@ public class RatCheckMojoTest extends Ab
             scanner.setIncludes(new String[]{"*"});
             scanner.scan();
             final String[] dirs = scanner.getIncludedDirectories();
-            
-            for (int i = 0;  i < dirs.length;  i++) {
-                final String dir = dirs[i];
+
+            for (final String dir : dirs) {
                 if (!"".equals(dir)) {
-                    copy( new File(pSource, dir), new File(pTarget, dir));
+                    copy(new File(pSource, dir), new File(pTarget, dir));
                 }
             }
             final String[] files = scanner.getIncludedFiles();
-            for (int i = 0;  i < files.length;  i++) {
-                copy( new File(pSource, files[i]), new File(pTarget, files[i]));
+            for (String file : files) {
+                copy(new File(pSource, file), new File(pTarget, file));
             }
         }
         else if ( pSource.isFile() )
@@ -379,7 +377,7 @@ public class RatCheckMojoTest extends Ab
     public void testIt3() throws Exception {
         final RatCheckMojo mojo = (RatCheckMojo) newRatMojo( "it3", "check", true );
         setVariableValueToObject( mojo, "addLicenseHeaders", "true" );
-        setVariableValueToObject( mojo, "numUnapprovedLicenses", new Integer(1));
+        setVariableValueToObject( mojo, "numUnapprovedLicenses", Integer.valueOf(1));
         mojo.execute();
         final File ratTxtFile = getRatTxtFile( mojo );
         checkResult( ratTxtFile, 1, 1 );

Modified: creadur/main/trunk/apache-rat-tasks/src/test/java/org/apache/rat/anttasks/AbstractRatAntTaskTest.java
URL: http://svn.apache.org/viewvc/creadur/main/trunk/apache-rat-tasks/src/test/java/org/apache/rat/anttasks/AbstractRatAntTaskTest.java?rev=1337943&r1=1337942&r2=1337943&view=diff
==============================================================================
--- creadur/main/trunk/apache-rat-tasks/src/test/java/org/apache/rat/anttasks/AbstractRatAntTaskTest.java (original)
+++ creadur/main/trunk/apache-rat-tasks/src/test/java/org/apache/rat/anttasks/AbstractRatAntTaskTest.java Sun May 13 17:22:20 2012
@@ -16,16 +16,15 @@
 */
 package org.apache.rat.anttasks;
 
+import junit.framework.Assert;
+import org.apache.tools.ant.BuildFileTest;
+import org.apache.tools.ant.util.FileUtils;
+
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.regex.Pattern;
 
-import junit.framework.Assert;
-
-import org.apache.tools.ant.BuildFileTest;
-import org.apache.tools.ant.util.FileUtils;
-
 public abstract class AbstractRatAntTaskTest extends BuildFileTest {
 	private static final File tempDir = new File("target/anttasks");
 
@@ -47,7 +46,7 @@ public abstract class AbstractRatAntTask
 
 	protected void assertLogMatches(String pPattern) {
 		final String log = super.getLog();
-		Assert.assertTrue("Log doesn' match string: " + pPattern + ", got " + log,
+		Assert.assertTrue("Log doesn't match string: " + pPattern + ", got " + log,
 				isMatching(pPattern, log));
 	}
 
@@ -58,7 +57,7 @@ public abstract class AbstractRatAntTask
 	private String load(File pFile) throws IOException {
 		FileReader fr = new FileReader(pFile);
 		try {
-			final StringBuffer sb = new StringBuffer();
+			final StringBuilder sb = new StringBuilder();
 			char[] buffer = new char[1024];
 			for (;;) {
 				int res = fr.read(buffer);