From 4c1e7b21a5042b60172ce3502bf7aa6099ad5399 Mon Sep 17 00:00:00 2001 From: Robert Scholte Date: Fri, 21 Dec 2018 13:16:55 +0100 Subject: [PATCH] Use Junit4 annotations --- .../plexus/util/CollectionUtilsTest.java | 12 +- .../plexus/util/DirectoryScannerTest.java | 21 ++ .../plexus/util/DirectoryWalkerTest.java | 8 +- .../plexus/util/FileBasedTestCase.java | 4 +- .../codehaus/plexus/util/FileUtilsTest.java | 99 +++++++-- .../org/codehaus/plexus/util/IOUtilTest.java | 36 ++- .../util/InterpolationFilterReaderTest.java | 16 +- .../LineOrientedInterpolatingReaderTest.java | 33 +-- .../plexus/util/MatchPatternTest.java | 8 +- .../plexus/util/MatchPatternsTest.java | 9 +- .../java/org/codehaus/plexus/util/OsTest.java | 10 +- .../codehaus/plexus/util/PathToolTest.java | 10 +- .../org/codehaus/plexus/util/PerfTest.java | 8 +- .../plexus/util/ReflectionUtilsTest.java | 16 +- .../plexus/util/SelectorUtilsTest.java | 15 +- .../codehaus/plexus/util/StringUtilsTest.java | 28 ++- .../codehaus/plexus/util/SweeperPoolTest.java | 47 ++-- .../plexus/util/cli/CommandLineUtilsTest.java | 13 +- .../plexus/util/cli/CommandlineTest.java | 209 ++++++++---------- .../plexus/util/cli/DefaultConsumerTest.java | 25 +-- .../util/cli/EnhancedStringTokenizerTest.java | 29 +-- .../plexus/util/cli/StreamPumperTest.java | 32 +-- .../util/cli/shell/BourneShellTest.java | 19 +- .../util/dag/CycleDetectedExceptionTest.java | 6 +- .../plexus/util/dag/CycleDetectorTest.java | 10 +- .../org/codehaus/plexus/util/dag/DAGTest.java | 9 +- .../util/dag/TopologicalSorterTest.java | 6 +- .../codehaus/plexus/util/dag/VertexTest.java | 6 +- .../ReflectionValueExtractorTest.java | 96 ++++---- .../plexus/util/reflection/ReflectorTest.java | 14 +- .../util/xml/PrettyPrintXMLWriterTest.java | 44 ++-- .../plexus/util/xml/XmlStreamWriterTest.java | 17 +- .../codehaus/plexus/util/xml/XmlUtilTest.java | 25 +-- .../plexus/util/xml/XmlWriterUtilTest.java | 37 +++- .../plexus/util/xml/Xpp3DomBuilderTest.java | 22 +- .../codehaus/plexus/util/xml/Xpp3DomTest.java | 25 ++- .../plexus/util/xml/Xpp3DomUtilsTest.java | 7 +- .../plexus/util/xml/Xpp3DomWriterTest.java | 7 +- .../plexus/util/xml/pull/MXParserTest.java | 14 +- 39 files changed, 625 insertions(+), 427 deletions(-) diff --git a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java index 8071251d..225c1bb0 100644 --- a/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/CollectionUtilsTest.java @@ -16,17 +16,21 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Properties; -import junit.framework.TestCase; +import org.junit.Test; public class CollectionUtilsTest - extends TestCase { + @Test public void testMergeMaps() { Map dominantMap = new HashMap(); @@ -63,6 +67,7 @@ public void testMergeMaps() } @SuppressWarnings( "unchecked" ) + @Test public void testMergeMapArray() { // Test empty array of Maps @@ -114,6 +119,7 @@ public void testMergeMapArray() assertEquals( "ccc", result5.get( "c" ) ); } + @Test public void testMavenPropertiesLoading() { // Mimic MavenSession properties loading. Properties listed @@ -170,6 +176,7 @@ public void testMavenPropertiesLoading() assertEquals( mavenRepoRemote, (String) result.get( "maven.repo.remote" ) ); } + @Test public void testIteratorToListWithAPopulatedList() { List original = new ArrayList(); @@ -189,6 +196,7 @@ public void testIteratorToListWithAPopulatedList() assertEquals( "tre", copy.get( 2 ) ); } + @Test public void testIteratorToListWithAEmptyList() { List original = new ArrayList(); diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java index 5726c2fe..16377510 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java @@ -16,6 +16,11 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.io.IOException; import java.net.URI; @@ -25,6 +30,8 @@ import java.util.Arrays; import java.util.List; +import org.junit.Test; + /** * Base class for testcases doing tests with files. * @@ -35,6 +42,7 @@ public class DirectoryScannerTest { private static String testDir = getTestDirectory().getPath(); + @Test public void testCrossPlatformIncludesString() throws IOException, URISyntaxException { @@ -59,6 +67,7 @@ public void testCrossPlatformIncludesString() assertEquals( 1, files.length ); } + @Test public void testCrossPlatformExcludesString() throws IOException, URISyntaxException { @@ -110,6 +119,7 @@ private void createTestFiles() this.createFile( new File( testDir + "/scanner5.dat" ), 0 ); } + @Test public void testGeneral() throws IOException { @@ -127,6 +137,7 @@ public void testGeneral() } + @Test public void testIncludesExcludesWithWhiteSpaces() throws IOException { @@ -144,6 +155,7 @@ public void testIncludesExcludesWithWhiteSpaces() assertTrue( "5 not found.", fileNames.contains( new File( "scanner5.dat" ) ) ); } + @Test public void testFollowSymlinksFalse() { DirectoryScanner ds = new DirectoryScanner(); @@ -175,6 +187,7 @@ private void assertAlwaysIncluded( List included ) assertTrue( included.contains( "symLinkToFileOnTheOutside" ) ); } + @Test public void testFollowSymlinks() { DirectoryScanner ds = new DirectoryScanner(); @@ -211,6 +224,7 @@ private void createTestDirectories() + File.separator + "file1.dat" ), 0 ); } + @Test public void testDirectoriesWithHyphens() throws IOException { @@ -229,6 +243,7 @@ public void testDirectoriesWithHyphens() assertEquals( "Wrong number of results.", 3, files.length ); } + @Test public void testAntExcludesOverrideIncludes() throws IOException { @@ -263,6 +278,7 @@ public void testAntExcludesOverrideIncludes() assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths ); } + @Test public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() throws IOException { @@ -298,6 +314,7 @@ public void testAntExcludesOverrideIncludesWithExplicitAntPrefix() assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths ); } + @Test public void testRegexIncludeWithExcludedPrefixDirs() throws IOException { @@ -328,6 +345,7 @@ public void testRegexIncludeWithExcludedPrefixDirs() assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths ); } + @Test public void testRegexExcludeWithNegativeLookahead() throws IOException { @@ -366,6 +384,7 @@ public void testRegexExcludeWithNegativeLookahead() assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths ); } + @Test public void testRegexWithSlashInsideCharacterClass() throws IOException { @@ -405,6 +424,7 @@ public void testRegexWithSlashInsideCharacterClass() assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths ); } + @Test public void testIsSymbolicLink() throws IOException { @@ -422,6 +442,7 @@ public void testIsSymbolicLink() assertFalse( ds.isSymbolicLink( directory, "aRegularDir" ) ); } + @Test public void testIsParentSymbolicLink() throws IOException { diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java index d71ea89f..5ccdb9bc 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryWalkerTest.java @@ -16,13 +16,17 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.File; -import junit.framework.TestCase; +import org.junit.Test; public class DirectoryWalkerTest - extends TestCase { + @Test public void testDirectoryWalk() { DirectoryWalker walker = new DirectoryWalker(); diff --git a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java index 9adc79a7..1be701d8 100644 --- a/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java +++ b/src/test/java/org/codehaus/plexus/util/FileBasedTestCase.java @@ -16,6 +16,8 @@ * limitations under the License. */ +import static org.junit.Assert.assertTrue; + import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -30,7 +32,6 @@ import java.util.Arrays; import junit.framework.AssertionFailedError; -import junit.framework.TestCase; /** * Base class for testcases doing tests with files. @@ -38,7 +39,6 @@ * @author Jeremias Maerki */ public abstract class FileBasedTestCase - extends TestCase { private static File testDir; diff --git a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java index 51087306..f29dd418 100644 --- a/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/FileUtilsTest.java @@ -16,6 +16,13 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -29,6 +36,11 @@ import java.net.URL; import java.util.Properties; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + /** * This is used to test FileUtils for correctness. * @@ -40,6 +52,9 @@ public final class FileUtilsTest extends FileBasedTestCase { + @Rule + public TestName name = new TestName(); + // Test data /** @@ -65,10 +80,8 @@ public FileUtilsTest() testFile2Size = (int) testFile2.length(); } - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() + @Before + public void setUp() throws Exception { getTestDirectory().mkdirs(); @@ -82,6 +95,7 @@ protected void setUp() // byteCountToDisplaySize + @Test public void testByteCountToDisplaySize() { assertEquals( FileUtils.byteCountToDisplaySize( 0 ), "0 bytes" ); @@ -92,6 +106,7 @@ public void testByteCountToDisplaySize() // waitFor + @Test public void testWaitFor() { FileUtils.waitFor( "", -1 ); @@ -99,6 +114,7 @@ public void testWaitFor() FileUtils.waitFor( "", 2 ); } + @Test public void testToFile() throws Exception { @@ -108,6 +124,7 @@ public void testToFile() assertEquals( "name #%20?{}[]<>.txt", file.getName() ); } + @Test public void testToFileBadProtocol() throws Exception { @@ -116,6 +133,7 @@ public void testToFileBadProtocol() assertNull( file ); } + @Test public void testToFileNull() throws Exception { @@ -124,6 +142,7 @@ public void testToFileNull() } // Hacked to sanity by Trygve + @Test public void testToURLs() throws Exception { @@ -140,6 +159,7 @@ public void testToURLs() } } + @Test public void testGetFilesFromExtension() { // TODO I'm not sure what is supposed to happen here @@ -160,6 +180,7 @@ public void testGetFilesFromExtension() // mkdir + @Test public void testMkdir() { final File dir = new File( getTestDirectory(), "testdir" ); @@ -184,11 +205,12 @@ public void testMkdir() // contentEquals + @Test public void testContentEquals() throws Exception { // Non-existent files - final File file = new File( getTestDirectory(), getName() ); + final File file = new File( getTestDirectory(), name.getMethodName() ); assertTrue( FileUtils.contentEquals( file, file ) ); // TODO Should comparing 2 directories throw an Exception instead of returning false? @@ -196,11 +218,11 @@ public void testContentEquals() assertTrue( !FileUtils.contentEquals( getTestDirectory(), getTestDirectory() ) ); // Different files - final File objFile1 = new File( getTestDirectory(), getName() + ".object" ); + final File objFile1 = new File( getTestDirectory(), name.getMethodName() + ".object" ); objFile1.deleteOnExit(); FileUtils.copyURLToFile( getClass().getResource( "/java/lang/Object.class" ), objFile1 ); - final File objFile2 = new File( getTestDirectory(), getName() + ".collection" ); + final File objFile2 = new File( getTestDirectory(), name.getMethodName() + ".collection" ); objFile2.deleteOnExit(); FileUtils.copyURLToFile( getClass().getResource( "/java/util/Collection.class" ), objFile2 ); @@ -213,27 +235,32 @@ public void testContentEquals() // removePath + @Test public void testRemovePath() { - final String fileName = FileUtils.removePath( new File( getTestDirectory(), getName() ).getAbsolutePath() ); - assertEquals( getName(), fileName ); + final String fileName = + FileUtils.removePath( new File( getTestDirectory(), name.getMethodName() ).getAbsolutePath() ); + assertEquals( name.getMethodName(), fileName ); } // getPath + @Test public void testGetPath() { - final String fileName = FileUtils.getPath( new File( getTestDirectory(), getName() ).getAbsolutePath() ); + final String fileName = + FileUtils.getPath( new File( getTestDirectory(), name.getMethodName() ).getAbsolutePath() ); assertEquals( getTestDirectory().getAbsolutePath(), fileName ); } // copyURLToFile + @Test public void testCopyURLToFile() throws Exception { // Creates file - final File file = new File( getTestDirectory(), getName() ); + final File file = new File( getTestDirectory(), name.getMethodName() ); file.deleteOnExit(); // Loads resource @@ -255,6 +282,7 @@ public void testCopyURLToFile() // catPath + @Test public void testCatPath() { // TODO StringIndexOutOfBoundsException thrown if file doesn't contain slash. @@ -267,6 +295,7 @@ public void testCatPath() // forceMkdir + @Test public void testForceMkdir() throws Exception { @@ -274,7 +303,7 @@ public void testForceMkdir() FileUtils.forceMkdir( getTestDirectory() ); // Creates test file - final File testFile = new File( getTestDirectory(), getName() ); + final File testFile = new File( getTestDirectory(), name.getMethodName() ); testFile.deleteOnExit(); testFile.createNewFile(); assertTrue( "Test file does not exist.", testFile.exists() ); @@ -313,10 +342,11 @@ public void testForceMkdir() // sizeOfDirectory + @Test public void testSizeOfDirectory() throws Exception { - final File file = new File( getTestDirectory(), getName() ); + final File file = new File( getTestDirectory(), name.getMethodName() ); // Non-existent file try @@ -358,6 +388,7 @@ public void XtestIsFileNewer() } // copyFile + @Test public void testCopyFile1() throws Exception { @@ -367,6 +398,7 @@ public void testCopyFile1() assertTrue( "Check Full copy", destination.length() == testFile1Size ); } + @Test public void testCopyFile2() throws Exception { @@ -381,6 +413,7 @@ public void testCopyFile2() * * @throws Exception */ + @Test public void testCopyFile3() throws Exception { @@ -397,6 +430,7 @@ public void testCopyFile3() // copyFileIfModified + @Test public void testCopyIfModifiedWhenSourceIsNewer() throws Exception { @@ -419,6 +453,7 @@ public void testCopyIfModifiedWhenSourceIsNewer() FileUtils.copyFileIfModified( source, destination ) ); } + @Test public void testCopyIfModifiedWhenSourceIsOlder() throws Exception { @@ -439,6 +474,7 @@ public void testCopyIfModifiedWhenSourceIsOlder() assertFalse( "Source file should not have been copied.", FileUtils.copyFileIfModified( source, destination ) ); } + @Test public void testCopyIfModifiedWhenSourceHasZeroDate() throws Exception { @@ -458,6 +494,7 @@ public void testCopyIfModifiedWhenSourceHasZeroDate() // forceDelete + @Test public void testForceDeleteAFile1() throws Exception { @@ -468,6 +505,7 @@ public void testForceDeleteAFile1() assertTrue( "Check No Exist", !destination.exists() ); } + @Test public void testForceDeleteAFile2() throws Exception { @@ -480,6 +518,7 @@ public void testForceDeleteAFile2() // copyFileToDirectory + @Test public void testCopyFile1ToDir() throws Exception { @@ -494,6 +533,7 @@ public void testCopyFile1ToDir() assertTrue( "Check Full copy", destination.length() == testFile1Size ); } + @Test public void testCopyFile2ToDir() throws Exception { @@ -510,6 +550,7 @@ public void testCopyFile2ToDir() // copyFileToDirectoryIfModified + @Test public void testCopyFile1ToDirIfModified() throws Exception { @@ -535,6 +576,7 @@ public void testCopyFile1ToDirIfModified() assertTrue( "Timestamp was changed", timestamp == target.lastModified() ); } + @Test public void testCopyFile2ToDirIfModified() throws Exception { @@ -562,6 +604,7 @@ public void testCopyFile2ToDirIfModified() // forceDelete + @Test public void testForceDeleteDir() throws Exception { @@ -571,6 +614,7 @@ public void testForceDeleteDir() // resolveFile + @Test public void testResolveFileDotDot() throws Exception { @@ -578,6 +622,7 @@ public void testResolveFileDotDot() assertEquals( "Check .. operator", file, getTestDirectory().getParentFile() ); } + @Test public void testResolveFileDot() throws Exception { @@ -587,6 +632,7 @@ public void testResolveFileDot() // normalize + @Test public void testNormalize() throws Exception { @@ -625,6 +671,7 @@ private String replaceAll( String text, String lookFor, String replaceWith ) * Test the FileUtils implementation. */ // Used to exist as IOTestCase class + @Test public void testFileUtils() throws Exception { @@ -662,6 +709,7 @@ public void testFileUtils() } + @Test public void testGetExtension() { final String[][] tests = @@ -675,6 +723,7 @@ public void testGetExtension() } } + @Test public void testGetExtensionWithPaths() { // Since the utilities are based on the separator for the platform @@ -694,6 +743,7 @@ public void testGetExtensionWithPaths() } } + @Test public void testRemoveExtension() { final String[][] tests = { { "filename.ext", "filename" }, { "first.second.third.ext", "first.second.third" }, @@ -707,6 +757,7 @@ public void testRemoveExtension() } /* TODO: Reenable this test */ + @Test public void testRemoveExtensionWithPaths() { // Since the utilities are based on the separator for the platform @@ -731,6 +782,7 @@ public void testRemoveExtensionWithPaths() } } + @Test public void testCopyDirectoryStructureWithAEmptyDirectoryStructure() throws Exception { @@ -747,6 +799,7 @@ public void testCopyDirectoryStructureWithAEmptyDirectoryStructure() FileUtils.copyDirectoryStructure( from, to ); } + @Test public void testCopyDirectoryStructureWithAPopulatedStructure() throws Exception { @@ -806,6 +859,7 @@ public void testCopyDirectoryStructureWithAPopulatedStructure() checkFile( f2_1, new File( to, "2/2_1/2_1.txt" ) ); } + @Test public void testCopyDirectoryStructureIfModified() throws Exception { @@ -885,6 +939,7 @@ public void testCopyDirectoryStructureIfModified() } + @Test public void testCopyDirectoryStructureToSelf() throws Exception { @@ -926,6 +981,7 @@ public void testCopyDirectoryStructureToSelf() } } + @Test public void testFilteredFileCopy() throws Exception { @@ -957,6 +1013,7 @@ public Reader getReader( Reader reader ) compareFile.delete(); } + @Test public void testFilteredWithoutFilterAndOlderFile() throws Exception { @@ -986,6 +1043,7 @@ public void testFilteredWithoutFilterAndOlderFile() } + @Test public void testFilteredWithoutFilterAndOlderFileAndOverwrite() throws Exception { @@ -1015,6 +1073,7 @@ public void testFilteredWithoutFilterAndOlderFileAndOverwrite() } + @Test public void testFileRead() throws IOException { @@ -1043,6 +1102,7 @@ public void testFileRead() testFile.delete(); } + @Test public void testFileReadWithEncoding() throws IOException { @@ -1067,6 +1127,7 @@ public void testFileReadWithEncoding() testFile.delete(); } + @Test public void testFileAppend() throws IOException { @@ -1091,6 +1152,7 @@ public void testFileAppend() testFile.delete(); } + @Test public void testFileAppendWithEncoding() throws IOException { @@ -1116,6 +1178,7 @@ public void testFileAppendWithEncoding() testFile.delete(); } + @Test public void testFileWrite() throws IOException { @@ -1128,6 +1191,7 @@ public void testFileWrite() testFile.delete(); } + @Test public void testFileWriteWithEncoding() throws IOException { @@ -1149,6 +1213,7 @@ public void testFileWriteWithEncoding() * @see Sun bug id=6182812 * @see Sun bug id=6481955 */ + @Test public void testDeleteLongPathOnWindows() throws Exception { @@ -1186,6 +1251,7 @@ public void testDeleteLongPathOnWindows() } // Test for bug PLXUTILS-10 + @Test public void testCopyFileOnSameFile() throws IOException { @@ -1202,6 +1268,7 @@ public void testCopyFileOnSameFile() assertTrue( theFile.length() > 0 ); } + @Test public void testExtensions() throws Exception { @@ -1221,6 +1288,7 @@ public void testExtensions() } } + @Test public void testIsValidWindowsFileName() throws Exception { @@ -1246,6 +1314,7 @@ public void testIsValidWindowsFileName() } } + @Test public void testDeleteDirectoryWithValidFileSymlink() throws Exception { @@ -1267,6 +1336,7 @@ public void testDeleteDirectoryWithValidFileSymlink() assertTrue( "Failed to delete test directory", !getTestDirectory().exists() ); } + @Test public void testDeleteDirectoryWithValidDirSymlink() throws Exception { @@ -1288,6 +1358,7 @@ public void testDeleteDirectoryWithValidDirSymlink() assertTrue( "Failed to delete test directory", !getTestDirectory().exists() ); } + @Test public void testDeleteDirectoryWithDanglingSymlink() throws Exception { @@ -1308,6 +1379,7 @@ public void testDeleteDirectoryWithDanglingSymlink() assertTrue( "Failed to delete test directory", !getTestDirectory().exists() ); } + @Test public void testcopyDirectoryLayoutWithExcludesIncludes() throws Exception { @@ -1349,6 +1421,7 @@ public void testcopyDirectoryLayoutWithExcludesIncludes() * * @throws Exception if any */ + @Test public void testCreateTempFile() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java index e6ec723a..c99384c1 100644 --- a/src/test/java/org/codehaus/plexus/util/IOUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/IOUtilTest.java @@ -16,6 +16,10 @@ * limitations under the License. */ +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; @@ -31,8 +35,8 @@ import java.io.Writer; import java.util.Arrays; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; /** * This is used to test IOUtil for correctness. The following checks are performed: @@ -48,7 +52,6 @@ * @author Jeff Turner */ public final class IOUtilTest - extends TestCase { /* * Note: this is not particularly beautiful code. A better way to check for flush and close status would be to @@ -62,6 +65,7 @@ public final class IOUtilTest private File testFile; + @Before public void setUp() { try @@ -88,11 +92,6 @@ public void tearDown() testDirectory.delete(); } - public IOUtilTest( String name ) - { - super( name ); - } - private void createFile( File file, long size ) throws IOException { @@ -156,6 +155,7 @@ private void assertEqualContent( byte[] b0, File file ) is.close(); } + @Test public void testInputStreamToOutputStream() throws Exception { @@ -174,6 +174,7 @@ public void testInputStreamToOutputStream() deleteFile( destination ); } + @Test public void testInputStreamToWriter() throws Exception { @@ -193,6 +194,7 @@ public void testInputStreamToWriter() deleteFile( destination ); } + @Test public void testInputStreamToString() throws Exception { @@ -204,6 +206,7 @@ public void testInputStreamToString() fin.close(); } + @Test public void testReaderToOutputStream() throws Exception { @@ -225,6 +228,7 @@ public void testReaderToOutputStream() deleteFile( destination ); } + @Test public void testReaderToWriter() throws Exception { @@ -241,6 +245,7 @@ public void testReaderToWriter() deleteFile( destination ); } + @Test public void testReaderToString() throws Exception { @@ -251,6 +256,7 @@ public void testReaderToString() fin.close(); } + @Test public void testStringToOutputStream() throws Exception { @@ -274,6 +280,7 @@ public void testStringToOutputStream() deleteFile( destination ); } + @Test public void testStringToWriter() throws Exception { @@ -293,6 +300,7 @@ public void testStringToWriter() deleteFile( destination ); } + @Test public void testInputStreamToByteArray() throws Exception { @@ -305,6 +313,7 @@ public void testInputStreamToByteArray() fin.close(); } + @Test public void testStringToByteArray() throws Exception { @@ -318,6 +327,7 @@ public void testStringToByteArray() fin.close(); } + @Test public void testByteArrayToWriter() throws Exception { @@ -336,6 +346,7 @@ public void testByteArrayToWriter() deleteFile( destination ); } + @Test public void testByteArrayToString() throws Exception { @@ -347,6 +358,7 @@ public void testByteArrayToString() fin.close(); } + @Test public void testByteArrayToOutputStream() throws Exception { @@ -372,6 +384,7 @@ public void testByteArrayToOutputStream() // Test closeXXX() // ---------------------------------------------------------------------- + @Test public void testCloseInputStream() throws Exception { @@ -384,6 +397,7 @@ public void testCloseInputStream() assertTrue( inputStream.closed ); } + @Test public void testCloseOutputStream() throws Exception { @@ -396,6 +410,7 @@ public void testCloseOutputStream() assertTrue( outputStream.closed ); } + @Test public void testCloseReader() throws Exception { @@ -408,6 +423,7 @@ public void testCloseReader() assertTrue( reader.closed ); } + @Test public void testCloseWriter() throws Exception { @@ -522,7 +538,7 @@ private void checkWrite( OutputStream output ) } catch ( Throwable t ) { - throw new AssertionFailedError( "The copy() method closed the stream " + "when it shouldn't have. " + throw new Exception( "The copy() method closed the stream " + "when it shouldn't have. " + t.getMessage() ); } } @@ -536,7 +552,7 @@ private void checkWrite( Writer output ) } catch ( Throwable t ) { - throw new AssertionFailedError( "The copy() method closed the stream " + "when it shouldn't have. " + throw new Exception( "The copy() method closed the stream " + "when it shouldn't have. " + t.getMessage() ); } } diff --git a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java index 26803960..f68eb400 100644 --- a/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/InterpolationFilterReaderTest.java @@ -16,19 +16,21 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; + import java.io.StringReader; import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; +import org.junit.Test; public class InterpolationFilterReaderTest - extends TestCase { /* * Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader. * kenneyw@15-04-2005 fixed the bug. */ + @Test public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws Exception { @@ -43,6 +45,7 @@ public void testShouldNotInterpolateExpressionAtEndOfDataWithInvalidEndToken() /* * kenneyw@14-04-2005 Added test to check above fix. */ + @Test public void testShouldNotInterpolateExpressionWithMissingEndToken() throws Exception { @@ -54,6 +57,7 @@ public void testShouldNotInterpolateExpressionWithMissingEndToken() assertEquals( "This is a ${test, really", interpolate( testStr, m ) ); } + @Test public void testShouldNotInterpolateWithMalformedStartToken() throws Exception { @@ -65,6 +69,7 @@ public void testShouldNotInterpolateWithMalformedStartToken() assertEquals( "This is a $!test} again", interpolate( foo, m ) ); } + @Test public void testShouldNotInterpolateWithMalformedEndToken() throws Exception { @@ -76,6 +81,7 @@ public void testShouldNotInterpolateWithMalformedEndToken() assertEquals( "This is a ${test!} again", interpolate( foo, m, "${", "$}" ) ); } + @Test public void testInterpolationWithMulticharDelimiters() throws Exception { @@ -87,6 +93,7 @@ public void testInterpolationWithMulticharDelimiters() assertEquals( "This is a testValue again", interpolate( foo, m, "${", "$}" ) ); } + @Test public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { @@ -99,6 +106,7 @@ public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() assertEquals( "jason is an asshole. ${not.interpolated}", interpolate( foo, m ) ); } + @Test public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception { @@ -111,6 +119,7 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() assertEquals( "jason is an asshole", interpolate( foo, m ) ); } + @Test public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception { @@ -123,6 +132,7 @@ public void testInterpolationWithSpecifiedBoundaryTokens() assertEquals( "jason is an asshole. @not.interpolated@ baby @foo@. @bar@", interpolate( foo, m, "@", "@" ) ); } + @Test public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { @@ -135,6 +145,7 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValue assertEquals( "jason is an @foobarred@", interpolate( foo, m, "@", "@" ) ); } + @Test public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { @@ -147,6 +158,7 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtE assertEquals( "jason is an asshole", interpolate( foo, m, "@", "@" ) ); } + @Test public void testInterpolationWithSpecifiedBoundaryTokensAndAdditionalTokenCharacter() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java index a29afe1f..346f1e88 100644 --- a/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java +++ b/src/test/java/org/codehaus/plexus/util/LineOrientedInterpolatingReaderTest.java @@ -16,6 +16,8 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; + import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; @@ -24,39 +26,18 @@ import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; +import org.junit.Test; /** * Generated by JUnitDoclet, a tool provided by ObjectFab GmbH under LGPL. Please see www.junitdoclet.org, www.gnu.org * and www.objectfab.de for informations about the tool, the licence and the authors. */ public class LineOrientedInterpolatingReaderTest - extends TestCase { - public LineOrientedInterpolatingReaderTest( String name ) - { - super( name ); - } - - /** - * The JUnit setup method - */ - protected void setUp() - throws Exception - { - } - - /** - * The teardown method for JUnit - */ - protected void tearDown() - throws Exception - { - } - /* * Added and commented by jdcasey@03-Feb-2005 because it is a bug in the InterpolationFilterReader. */ + @Test public void testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() throws IOException { @@ -71,6 +52,7 @@ public void testShouldInterpolateExpressionAtEndOfDataWithInvalidEndToken() assertEquals( "This is a ${test", result ); } + @Test public void testDefaultInterpolationWithNonInterpolatedValueAtEnd() throws Exception { @@ -95,6 +77,7 @@ private Map getStandardMap() return m; } + @Test public void testDefaultInterpolationWithEscapedExpression() throws Exception { @@ -111,6 +94,7 @@ public void testDefaultInterpolationWithEscapedExpression() assertEquals( "jason is an asshole. ${noun} value", bar ); } + @Test public void testDefaultInterpolationWithInterpolatedValueAtEnd() throws Exception { @@ -127,6 +111,7 @@ public void testDefaultInterpolationWithInterpolatedValueAtEnd() assertEquals( "jason is an asshole", bar ); } + @Test public void testInterpolationWithSpecifiedBoundaryTokens() throws Exception { @@ -144,6 +129,7 @@ public void testInterpolationWithSpecifiedBoundaryTokens() assertEquals( "jason is an asshole. @not.interpolated@ baby @foo@. @bar@", bar ); } + @Test public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValueAtEnd() throws Exception { @@ -161,6 +147,7 @@ public void testInterpolationWithSpecifiedBoundaryTokensWithNonInterpolatedValue assertEquals( "jason is an @foobarred@", bar ); } + @Test public void testInterpolationWithSpecifiedBoundaryTokensWithInterpolatedValueAtEnd() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java index bb3de466..38deb81e 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternTest.java @@ -1,4 +1,5 @@ package org.codehaus.plexus.util; + /* * Copyright The Codehaus Foundation. * @@ -15,19 +16,20 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; /** * @author Kristian Rosenvold */ public class MatchPatternTest - extends TestCase { + @Test public void testMatchPath() throws Exception { MatchPattern mp = MatchPattern.fromString( "ABC*" ); assertTrue( mp.matchPath( "ABCD", true ) ); - } } diff --git a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java index b75b5b54..d4e51566 100644 --- a/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java +++ b/src/test/java/org/codehaus/plexus/util/MatchPatternsTest.java @@ -1,4 +1,5 @@ package org.codehaus.plexus.util; + /* * Copyright The Codehaus Foundation. * @@ -15,11 +16,14 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; public class MatchPatternsTest - extends TestCase { + @Test public void testMatches() throws Exception { @@ -27,6 +31,5 @@ public void testMatches() assertTrue( from.matches( "ABCDE", true ) ); assertTrue( from.matches( "CDEF", true ) ); assertFalse( from.matches( "XYZ", true ) ); - } } diff --git a/src/test/java/org/codehaus/plexus/util/OsTest.java b/src/test/java/org/codehaus/plexus/util/OsTest.java index 6a706b25..363df35b 100644 --- a/src/test/java/org/codehaus/plexus/util/OsTest.java +++ b/src/test/java/org/codehaus/plexus/util/OsTest.java @@ -16,21 +16,26 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.util.Iterator; -import junit.framework.TestCase; +import org.junit.Test; /** * Test Case for Os */ public class OsTest - extends TestCase { + @Test public void testUndefinedFamily() { assertFalse( Os.isFamily( "bogus family" ) ); } + @Test public void testOs() { Iterator iter = Os.getValidFamilies().iterator(); @@ -74,6 +79,7 @@ public void testOs() assertFalse( Os.isOs( currentFamily, Os.OS_NAME, Os.OS_ARCH, "myversion" ) ); } + @Test public void testValidList() { assertTrue( Os.isValidFamily( "dos" ) ); diff --git a/src/test/java/org/codehaus/plexus/util/PathToolTest.java b/src/test/java/org/codehaus/plexus/util/PathToolTest.java index 8367c7e8..e7f01ba8 100644 --- a/src/test/java/org/codehaus/plexus/util/PathToolTest.java +++ b/src/test/java/org/codehaus/plexus/util/PathToolTest.java @@ -16,18 +16,20 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * @author Vincent Siveton * @version $Id$ */ public class PathToolTest - extends TestCase { /** * @throws Exception */ + @Test public void testGetRelativePath() throws Exception { @@ -42,6 +44,7 @@ public void testGetRelativePath() /** * @throws Exception */ + @Test public void testGetDirectoryComponent() throws Exception { @@ -54,6 +57,7 @@ public void testGetDirectoryComponent() /** * @throws Exception */ + @Test public void testCalculateLink() throws Exception { @@ -71,6 +75,7 @@ public void testCalculateLink() /** * @throws Exception */ + @Test public void testGetRelativeWebPath() throws Exception { @@ -88,6 +93,7 @@ public void testGetRelativeWebPath() /** * @throws Exception */ + @Test public void testGetRelativeFilePath() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/PerfTest.java b/src/test/java/org/codehaus/plexus/util/PerfTest.java index 1a219175..a443fd95 100644 --- a/src/test/java/org/codehaus/plexus/util/PerfTest.java +++ b/src/test/java/org/codehaus/plexus/util/PerfTest.java @@ -1,7 +1,5 @@ package org.codehaus.plexus.util; -import junit.framework.TestCase; - /* * Copyright 2011 The Codehaus Foundation. * @@ -18,14 +16,15 @@ * limitations under the License. */ +import org.junit.Test; + public class PerfTest - extends TestCase { - String src = "012345578901234556789012345678901234456789012345678901234567890"; private final int oops = 100; + @Test public void testSubString() { StringBuilder res = new StringBuilder(); @@ -41,6 +40,7 @@ public void testSubString() System.out.println( "i = " + i ); } + @Test public void testResDir() { StringBuilder res = new StringBuilder(); diff --git a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java index fe812a62..767c72e8 100644 --- a/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/ReflectionUtilsTest.java @@ -16,9 +16,12 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import java.util.Map; + +import org.junit.Test; + import java.util.HashMap; /** @@ -29,22 +32,17 @@ * @see org.codehaus.plexus.util.ReflectionUtils */ public final class ReflectionUtilsTest - extends TestCase { public ReflectionUtilsTestClass testClass = new ReflectionUtilsTestClass(); - protected void setUp() - throws Exception - { - - } - + @Test public void testSimpleVariableAccess() throws IllegalAccessException { assertEquals( "woohoo", (String) ReflectionUtils.getValueIncludingSuperclasses( "myString", testClass ) ); } + @Test public void testComplexVariableAccess() throws IllegalAccessException { @@ -57,6 +55,7 @@ public void testComplexVariableAccess() } + @Test public void testSuperClassVariableAccess() throws IllegalAccessException { @@ -64,6 +63,7 @@ public void testSuperClassVariableAccess() (String) ReflectionUtils.getValueIncludingSuperclasses( "mySuperString", testClass ) ); } + @Test public void testSettingVariableValue() throws IllegalAccessException { diff --git a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java index f007d324..194c45b4 100644 --- a/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/SelectorUtilsTest.java @@ -1,9 +1,5 @@ package org.codehaus.plexus.util; -import java.io.File; - -import junit.framework.TestCase; - /* * Copyright The Codehaus Foundation. * @@ -20,9 +16,16 @@ * limitations under the License. */ +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; + +import org.junit.Test; + public class SelectorUtilsTest - extends TestCase { + @Test public void testMatchPath_DefaultFileSeparator() { String separator = File.separator; @@ -38,6 +41,7 @@ public void testMatchPath_DefaultFileSeparator() assertTrue( SelectorUtils.matchPath( "*" + separator + "a.txt", "b" + separator + "a.txt" ) ); } + @Test public void testMatchPath_UnixFileSeparator() { String separator = "/"; @@ -55,6 +59,7 @@ public void testMatchPath_UnixFileSeparator() assertTrue( SelectorUtils.matchPath( "*" + separator + "a.txt", "b" + separator + "a.txt", separator, false ) ); } + @Test public void testMatchPath_WindowsFileSeparator() { String separator = "\\"; diff --git a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java index 732acf5c..42f1a75b 100644 --- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java @@ -16,10 +16,14 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.util.Arrays; import java.util.Locale; -import junit.framework.TestCase; +import org.junit.Test; /** * Test string utils. @@ -28,9 +32,9 @@ * @version $Id$ */ public class StringUtilsTest - extends TestCase { + @Test public void testIsEmpty() { assertEquals( true, StringUtils.isEmpty( null ) ); @@ -40,6 +44,7 @@ public void testIsEmpty() assertEquals( false, StringUtils.isEmpty( " foo " ) ); } + @Test public void testIsNotEmpty() { assertEquals( false, StringUtils.isNotEmpty( null ) ); @@ -49,6 +54,7 @@ public void testIsNotEmpty() assertEquals( true, StringUtils.isNotEmpty( " foo " ) ); } + @Test public void testIsBlank() { assertEquals( true, StringUtils.isBlank( null ) ); @@ -58,6 +64,7 @@ public void testIsBlank() assertEquals( false, StringUtils.isBlank( " foo " ) ); } + @Test public void testIsNotBlank() { assertEquals( false, StringUtils.isNotBlank( null ) ); @@ -67,12 +74,14 @@ public void testIsNotBlank() assertEquals( true, StringUtils.isNotBlank( " foo " ) ); } + @Test public void testCapitalizeFirstLetter() { assertEquals( "Id", StringUtils.capitalizeFirstLetter( "id" ) ); assertEquals( "Id", StringUtils.capitalizeFirstLetter( "Id" ) ); } + @Test public void testCapitalizeFirstLetterTurkish() { Locale l = Locale.getDefault(); @@ -82,12 +91,14 @@ public void testCapitalizeFirstLetterTurkish() Locale.setDefault( l ); } + @Test public void testLowerCaseFirstLetter() { assertEquals( "id", StringUtils.lowercaseFirstLetter( "id" ) ); assertEquals( "id", StringUtils.lowercaseFirstLetter( "Id" ) ); } + @Test public void testLowerCaseFirstLetterTurkish() { Locale l = Locale.getDefault(); @@ -97,12 +108,14 @@ public void testLowerCaseFirstLetterTurkish() Locale.setDefault( l ); } + @Test public void testRemoveAndHump() { assertEquals( "Id", StringUtils.removeAndHump( "id", "-" ) ); assertEquals( "SomeId", StringUtils.removeAndHump( "some-id", "-" ) ); } + @Test public void testRemoveAndHumpTurkish() { Locale l = Locale.getDefault(); @@ -112,6 +125,7 @@ public void testRemoveAndHumpTurkish() Locale.setDefault( l ); } + @Test public void testQuote_EscapeEmbeddedSingleQuotes() { String src = "This \'is a\' test"; @@ -123,6 +137,7 @@ public void testQuote_EscapeEmbeddedSingleQuotes() assertEquals( check, result ); } + @Test public void testQuote_EscapeEmbeddedSingleQuotesWithPattern() { String src = "This \'is a\' test"; @@ -134,6 +149,7 @@ public void testQuote_EscapeEmbeddedSingleQuotesWithPattern() assertEquals( check, result ); } + @Test public void testQuote_EscapeEmbeddedDoubleQuotesAndSpaces() { String src = "This \"is a\" test"; @@ -145,6 +161,7 @@ public void testQuote_EscapeEmbeddedDoubleQuotesAndSpaces() assertEquals( check, result ); } + @Test public void testQuote_DontQuoteIfUnneeded() { String src = "ThisIsATest"; @@ -155,6 +172,7 @@ public void testQuote_DontQuoteIfUnneeded() assertEquals( src, result ); } + @Test public void testQuote_WrapWithSingleQuotes() { String src = "This is a test"; @@ -166,6 +184,7 @@ public void testQuote_WrapWithSingleQuotes() assertEquals( check, result ); } + @Test public void testQuote_PreserveExistingQuotes() { String src = "\'This is a test\'"; @@ -176,6 +195,7 @@ public void testQuote_PreserveExistingQuotes() assertEquals( src, result ); } + @Test public void testQuote_WrapExistingQuotesWhenForceIsTrue() { String src = "\'This is a test\'"; @@ -187,6 +207,7 @@ public void testQuote_WrapExistingQuotesWhenForceIsTrue() assertEquals( check, result ); } + @Test public void testQuote_ShortVersion_SingleQuotesPreserved() { String src = "\'This is a test\'"; @@ -196,6 +217,7 @@ public void testQuote_ShortVersion_SingleQuotesPreserved() assertEquals( src, result ); } + @Test public void testSplit() { String[] tokens; @@ -225,6 +247,7 @@ public void testSplit() assertEquals( Arrays.asList( new String[] { "this", "is", "a", "test", "really" } ), Arrays.asList( tokens ) ); } + @Test public void testRemoveDuplicateWhitespace() throws Exception { @@ -239,6 +262,7 @@ public void testRemoveDuplicateWhitespace() } + @Test public void testUnifyLineSeparators() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java index 68e2884d..9dd1a41f 100644 --- a/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java +++ b/src/test/java/org/codehaus/plexus/util/SweeperPoolTest.java @@ -16,10 +16,19 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.Vector; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + /** * Created on 21/06/2003 * @@ -27,7 +36,6 @@ * @version $Revision$ */ public class SweeperPoolTest - extends TestCase { /** The pool under test */ TestObjectPool pool; @@ -45,27 +53,10 @@ public class SweeperPoolTest Object o6; - /** - * Constructor - */ - public SweeperPoolTest() - { - super(); - } - - /** - * Constructor - * - * @param arg0 - */ - public SweeperPoolTest( String arg0 ) - { - super( arg0 ); - } - /** * Test the pool limits it's size, and disposes unneeded objects correctly */ + @Test public void testMaxSize() { int sweepInterval = 0; @@ -98,6 +89,7 @@ public void testMaxSize() } + @Test public void testSweepAndTrim1() { // test trigger @@ -129,32 +121,25 @@ public void testSweepAndTrim1() } - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() + @Before + public void setUp() throws Exception { - o1 = new Object(); o2 = new Object(); o3 = new Object(); o4 = new Object(); o5 = new Object(); o6 = new Object(); - super.setUp(); } - /** - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() + @After + public void tearDown() throws Exception { pool.dispose(); assertTrue( pool.isDisposed() ); pool = null; - super.tearDown(); } diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java index 6e333870..ae4b3e19 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandLineUtilsTest.java @@ -16,18 +16,22 @@ * limitations under the License. */ -import junit.framework.TestCase; -import org.codehaus.plexus.util.Os; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import java.util.Arrays; import java.util.Locale; import java.util.Properties; +import org.codehaus.plexus.util.Os; +import org.junit.Test; + @SuppressWarnings( { "JavaDoc", "deprecation" } ) public class CommandLineUtilsTest - extends TestCase { + @Test public void testQuoteArguments() { try @@ -59,6 +63,7 @@ public void testQuoteArguments() /** * Tests that case-insensitive environment variables are normalized to upper case. */ + @Test public void testGetSystemEnvVarsCaseInsensitive() throws Exception { @@ -73,6 +78,7 @@ public void testGetSystemEnvVarsCaseInsensitive() /** * Tests that environment variables on Windows are normalized to upper case. Does nothing on Unix platforms. */ + @Test public void testGetSystemEnvVarsWindows() throws Exception { @@ -91,6 +97,7 @@ public void testGetSystemEnvVarsWindows() /** * Tests the splitting of a command line into distinct arguments. */ + @Test public void testTranslateCommandline() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java index 841219af..28ec8297 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/CommandlineTest.java @@ -16,36 +16,32 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; + import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.shell.BourneShell; import org.codehaus.plexus.util.cli.shell.CmdShell; import org.codehaus.plexus.util.cli.shell.Shell; - -import java.io.*; +import org.junit.Before; +import org.junit.Test; public class CommandlineTest - extends TestCase { private String baseDir; - /** - * @param testName - */ - public CommandlineTest( final String testName ) - { - super( testName ); - } - - /* - * @see TestCase#setUp() - */ + @Before public void setUp() throws Exception { - super.setUp(); baseDir = System.getProperty( "basedir" ); if ( baseDir == null ) @@ -54,143 +50,104 @@ public void setUp() } } + @Test public void testCommandlineWithoutCommandInConstructor() { - try - { - Commandline cmd = new Commandline( new Shell() ); - cmd.setWorkingDirectory( baseDir ); - cmd.createArgument().setValue( "cd" ); - cmd.createArgument().setValue( "." ); + Commandline cmd = new Commandline( new Shell() ); + cmd.setWorkingDirectory( baseDir ); + cmd.createArgument().setValue( "cd" ); + cmd.createArgument().setValue( "." ); - // NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result. - assertEquals( "cd .", cmd.toString() ); - } - catch ( Exception e ) - { - fail( e.getMessage() ); - } + // NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result. + assertEquals( "cd .", cmd.toString() ); } + @Test public void testCommandlineWithCommandInConstructor() { - try - { - Commandline cmd = new Commandline( "cd .", new Shell() ); - cmd.setWorkingDirectory( baseDir ); + Commandline cmd = new Commandline( "cd .", new Shell() ); + cmd.setWorkingDirectory( baseDir ); - // NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result. - assertEquals( "cd .", cmd.toString() ); - } - catch ( Exception e ) - { - fail( e.getMessage() ); - } + // NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result. + assertEquals( "cd .", cmd.toString() ); } + @Test public void testExecuteBinaryOnPath() + throws Exception { - try - { - // Maven startup script on PATH is required for this test - Commandline cmd = new Commandline(); - cmd.setWorkingDirectory( baseDir ); - cmd.setExecutable( "mvn" ); - assertEquals( "mvn", cmd.getShell().getOriginalExecutable() ); - cmd.createArg().setValue( "-version" ); - Process process = cmd.execute(); - String out = IOUtil.toString( process.getInputStream() ); - assertTrue( out.contains( "Apache Maven" ) ); - assertTrue( out.contains( "Maven home:" ) ); - assertTrue( out.contains( "Java version:" ) ); - } - catch ( Exception e ) - { - fail( "Maven startup script seems not on the PATH: " + e.getMessage() ); - } + // Maven startup script on PATH is required for this test + Commandline cmd = new Commandline(); + cmd.setWorkingDirectory( baseDir ); + cmd.setExecutable( "mvn" ); + assertEquals( "mvn", cmd.getShell().getOriginalExecutable() ); + cmd.createArg().setValue( "-version" ); + Process process = cmd.execute(); + String out = IOUtil.toString( process.getInputStream() ); + assertTrue( out.contains( "Apache Maven" ) ); + assertTrue( out.contains( "Maven home:" ) ); + assertTrue( out.contains( "Java version:" ) ); } + @Test public void testExecute() + throws Exception { - try - { - // allow it to detect the proper shell here. - Commandline cmd = new Commandline(); - cmd.setWorkingDirectory( baseDir ); - cmd.setExecutable( "echo" ); - assertEquals( "echo", cmd.getShell().getOriginalExecutable() ); - cmd.createArgument().setValue( "Hello" ); + // allow it to detect the proper shell here. + Commandline cmd = new Commandline(); + cmd.setWorkingDirectory( baseDir ); + cmd.setExecutable( "echo" ); + assertEquals( "echo", cmd.getShell().getOriginalExecutable() ); + cmd.createArgument().setValue( "Hello" ); - Process process = cmd.execute(); - assertEquals( "Hello", IOUtil.toString( process.getInputStream() ).trim() ); - } - catch ( Exception e ) - { - fail( e.getMessage() ); - } + Process process = cmd.execute(); + assertEquals( "Hello", IOUtil.toString( process.getInputStream() ).trim() ); } + @Test public void testSetLine() { - try - { - Commandline cmd = new Commandline( new Shell() ); - cmd.setWorkingDirectory( baseDir ); - cmd.setExecutable( "echo" ); - cmd.createArgument().setLine( null ); - cmd.createArgument().setLine( "Hello" ); - - // NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result. - assertEquals( "echo Hello", cmd.toString() ); - } - catch ( Exception e ) - { - fail( e.getMessage() ); - } + Commandline cmd = new Commandline( new Shell() ); + cmd.setWorkingDirectory( baseDir ); + cmd.setExecutable( "echo" ); + cmd.createArgument().setLine( null ); + cmd.createArgument().setLine( "Hello" ); + + // NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result. + assertEquals( "echo Hello", cmd.toString() ); } + @Test public void testCreateCommandInReverseOrder() { - try - { - Commandline cmd = new Commandline( new Shell() ); - cmd.setWorkingDirectory( baseDir ); - cmd.createArgument().setValue( "." ); - cmd.createArgument( true ).setValue( "cd" ); + Commandline cmd = new Commandline( new Shell() ); + cmd.setWorkingDirectory( baseDir ); + cmd.createArgument().setValue( "." ); + cmd.createArgument( true ).setValue( "cd" ); - // NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result. - assertEquals( "cd .", cmd.toString() ); - } - catch ( Exception e ) - { - fail( e.getMessage() ); - } + // NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result. + assertEquals( "cd .", cmd.toString() ); } + @Test public void testSetFile() { - try + Commandline cmd = new Commandline( new Shell() ); + cmd.setWorkingDirectory( baseDir ); + cmd.createArgument().setValue( "more" ); + File f = new File( "test.txt" ); + cmd.createArgument().setFile( f ); + String fileName = f.getAbsolutePath(); + if ( fileName.contains( " " ) ) { - Commandline cmd = new Commandline( new Shell() ); - cmd.setWorkingDirectory( baseDir ); - cmd.createArgument().setValue( "more" ); - File f = new File( "test.txt" ); - cmd.createArgument().setFile( f ); - String fileName = f.getAbsolutePath(); - if ( fileName.contains( " " ) ) - { - fileName = "\"" + fileName + "\""; - } - - // NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result. - assertEquals( "more " + fileName, cmd.toString() ); - } - catch ( Exception e ) - { - fail( e.getMessage() ); + fileName = "\"" + fileName + "\""; } + + // NOTE: cmd.toString() uses CommandLineUtils.toString( String[] ), which *quotes* the result. + assertEquals( "more " + fileName, cmd.toString() ); } + @Test public void testGetShellCommandLineWindows() throws Exception { @@ -209,6 +166,7 @@ public void testGetShellCommandLineWindows() assertEquals( expectedShellCmd, shellCommandline[3] ); } + @Test public void testGetShellCommandLineWindowsWithSeveralQuotes() throws Exception { @@ -233,6 +191,7 @@ public void testGetShellCommandLineWindowsWithSeveralQuotes() * * @throws Exception */ + @Test public void testGetShellCommandLineBash() throws Exception { @@ -259,6 +218,7 @@ public void testGetShellCommandLineBash() * * @throws Exception */ + @Test public void testGetShellCommandLineBash_WithWorkingDirectory() throws Exception { @@ -288,6 +248,7 @@ public void testGetShellCommandLineBash_WithWorkingDirectory() * * @throws Exception */ + @Test public void testGetShellCommandLineBash_WithSingleQuotedArg() throws Exception { @@ -309,6 +270,7 @@ public void testGetShellCommandLineBash_WithSingleQuotedArg() assertEquals( expectedShellCmd, shellCommandline[2] ); } + @Test public void testGetShellCommandLineNonWindows() throws Exception { @@ -332,6 +294,7 @@ public void testGetShellCommandLineNonWindows() } } + @Test public void testEnvironment() throws Exception { @@ -340,6 +303,7 @@ public void testEnvironment() assertEquals( "name=value", cmd.getEnvironmentVariables()[0] ); } + @Test public void testEnvironmentWitOverrideSystemEnvironment() throws Exception { @@ -364,6 +328,7 @@ public void testEnvironmentWitOverrideSystemEnvironment() * * @throws Exception */ + @Test public void testQuotedPathWithSingleApostrophe() throws Exception { @@ -379,6 +344,7 @@ public void testQuotedPathWithSingleApostrophe() * * @throws Exception */ + @Test public void testPathWithShellExpansionStrings() throws Exception { @@ -391,6 +357,7 @@ public void testPathWithShellExpansionStrings() * * @throws Exception */ + @Test public void testQuotedPathWithQuotationMark() throws Exception { @@ -413,6 +380,7 @@ public void testQuotedPathWithQuotationMark() * * @throws Exception */ + @Test public void testQuotedPathWithQuotationMarkAndApostrophe() throws Exception { @@ -434,6 +402,7 @@ public void testQuotedPathWithQuotationMarkAndApostrophe() * * @throws Exception */ + @Test public void testOnlyQuotedPath() throws Exception { @@ -464,6 +433,7 @@ public void testOnlyQuotedPath() createAndCallScript( dir, javaBinStr + " -version" ); } + @Test public void testDollarSignInArgumentPath() throws Exception { @@ -498,6 +468,7 @@ public void testDollarSignInArgumentPath() executeCommandLine( cmd ); } + @Test public void testTimeOutException() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java b/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java index 50766092..4c8d9931 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/DefaultConsumerTest.java @@ -16,32 +16,13 @@ * limitations under the License. */ -import java.io.IOException; - -import junit.framework.TestCase; +import org.junit.Test; public class DefaultConsumerTest - extends TestCase { - /** - * @param testName - */ - public DefaultConsumerTest( String testName ) - { - super( testName ); - } - - /* - * @see TestCase#setUp() - */ - public void setUp() - throws Exception - { - super.setUp(); - } - + @Test public void testConsumeLine() - throws IOException + throws Exception { DefaultConsumer cons = new DefaultConsumer(); cons.consumeLine( "Test DefaultConsumer consumeLine" ); diff --git a/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java b/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java index 3c4f6396..c9ce9ebd 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/EnhancedStringTokenizerTest.java @@ -16,28 +16,14 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.Test; public class EnhancedStringTokenizerTest - extends TestCase { - /** - * @param testName - */ - public EnhancedStringTokenizerTest( final String testName ) - { - super( testName ); - } - - /* - * @see TestCase#setUp() - */ - public void setUp() - throws Exception - { - super.setUp(); - } - + @Test public void test1() { EnhancedStringTokenizer est = new EnhancedStringTokenizer( "this is a test string" ); @@ -50,6 +36,7 @@ public void test1() assertEquals( "this is a test string ", sb.toString() ); } + @Test public void test2() { EnhancedStringTokenizer est = new EnhancedStringTokenizer( "1,,,3,,4", "," ); @@ -61,6 +48,7 @@ public void test2() assertEquals( "Token 6", "4", est.nextToken() ); } + @Test public void test3() { EnhancedStringTokenizer est = new EnhancedStringTokenizer( "1,,,3,,4", ",", true ); @@ -77,6 +65,7 @@ public void test3() assertEquals( "Token 11", "4", est.nextToken() ); } + @Test public void testMultipleDelim() { EnhancedStringTokenizer est = new EnhancedStringTokenizer( "1 2|3|4", " |", true ); @@ -90,6 +79,7 @@ public void testMultipleDelim() assertEquals( "est.hasMoreTokens()", false, est.hasMoreTokens() ); } + @Test public void testEmptyString() { EnhancedStringTokenizer est = new EnhancedStringTokenizer( "" ); @@ -104,6 +94,7 @@ public void testEmptyString() } } + @Test public void testSimpleString() { EnhancedStringTokenizer est = new EnhancedStringTokenizer( "a " ); diff --git a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java index a682c215..a00e156c 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/StreamPumperTest.java @@ -52,7 +52,9 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -62,32 +64,16 @@ import java.util.ArrayList; import java.util.List; +import org.junit.Test; + /** * @author Paul Julius */ public class StreamPumperTest - extends TestCase { - private String lineSeparator; - - /** - * @param testName - */ - public StreamPumperTest( String testName ) - { - super( testName ); - } - - /* - * @see TestCase#setUp() - */ - public void setUp() - throws Exception - { - super.setUp(); - lineSeparator = System.getProperty( "line.separator" ); - } + private String lineSeparator = System.lineSeparator(); + @Test public void testPumping() { String line1 = "line1"; @@ -104,6 +90,7 @@ public void testPumping() assertTrue( consumer.wasLineConsumed( line2, 1000 ) ); } + @Test public void testPumpingWithPrintWriter() { String inputString = "This a test string"; @@ -118,6 +105,7 @@ public void testPumpingWithPrintWriter() pumper.close(); } + @Test public void testPumperReadsInputStreamUntilEndEvenIfConsumerFails() { // the number of bytes generated should surely exceed the read buffer used by the pumper @@ -233,6 +221,7 @@ public void consumeLine( String line ) } } + @Test public void testEnabled() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( "AB\nCE\nEF".getBytes() ); @@ -242,6 +231,7 @@ public void testEnabled() assertEquals( 3, streamConsumer.lines.size() ); } + @Test public void testDisabled() { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( "AB\nCE\nEF".getBytes() ); diff --git a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java index 3a147cf3..95b70b5b 100644 --- a/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java +++ b/src/test/java/org/codehaus/plexus/util/cli/shell/BourneShellTest.java @@ -1,5 +1,6 @@ package org.codehaus.plexus.util.cli.shell; + /* * Copyright The Codehaus Foundation. * @@ -16,15 +17,17 @@ * limitations under the License. */ -import junit.framework.TestCase; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.cli.Commandline; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.List; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.cli.Commandline; +import org.junit.Test; + public class BourneShellTest - extends TestCase { protected Shell newShell() @@ -32,6 +35,7 @@ protected Shell newShell() return new BourneShell(); } + @Test public void testQuoteWorkingDirectoryAndExecutable() { Shell sh = newShell(); @@ -44,6 +48,7 @@ public void testQuoteWorkingDirectoryAndExecutable() assertEquals( "/bin/sh -c cd '/usr/local/bin' && 'chmod'", executable ); } + @Test public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() { Shell sh = newShell(); @@ -56,6 +61,7 @@ public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes() assertEquals( "/bin/sh -c cd '/usr/local/'\"'\"'something else'\"'\"'' && 'chmod'", executable ); } + @Test public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_BackslashFileSep() { Shell sh = newShell(); @@ -68,6 +74,7 @@ public void testQuoteWorkingDirectoryAndExecutable_WDPathWithSingleQuotes_Backsl assertEquals( "/bin/sh -c cd '\\usr\\local\\\'\"'\"'something else'\"'\"'' && 'chmod'", executable ); } + @Test public void testPreserveSingleQuotesOnArgument() { Shell sh = newShell(); @@ -84,6 +91,7 @@ public void testPreserveSingleQuotesOnArgument() assertTrue( cli.endsWith( "''\"'\"'some arg with spaces'\"'\"''" ) ); } + @Test public void testAddSingleQuotesOnArgumentWithSpaces() { Shell sh = newShell(); @@ -100,6 +108,7 @@ public void testAddSingleQuotesOnArgumentWithSpaces() assertTrue( cli.endsWith( "\'" + args[0] + "\'" ) ); } + @Test public void testEscapeSingleQuotesOnArgument() { Shell sh = newShell(); @@ -117,6 +126,7 @@ public void testEscapeSingleQuotesOnArgument() shellCommandLine.get( shellCommandLine.size() - 1 ) ); } + @Test public void testArgumentsWithsemicolon() { @@ -173,6 +183,7 @@ public void testArgumentsWithsemicolon() assertEquals( "\"--password ;password\"", lines[3] ); } + @Test public void testBourneShellQuotingCharacters() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java index b18fe806..4d0c9ad9 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectedExceptionTest.java @@ -16,18 +16,20 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; +import org.junit.Test; + /** * @author Jason van Zyl * @version $Id$ */ public class CycleDetectedExceptionTest - extends TestCase { + @Test public void testException() { final List cycle = new ArrayList(); diff --git a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java index 9173ebba..df52fe0e 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/CycleDetectorTest.java @@ -16,18 +16,24 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.List; +import org.junit.Test; + /** * @author Michal Maczka * @version $Id$ */ public class CycleDetectorTest - extends TestCase { + @Test public void testCycyleDetection() { // No cycle diff --git a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java index 0b5f1538..0ff1269c 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/DAGTest.java @@ -16,19 +16,23 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; import java.util.Set; +import org.junit.Test; + /** * @author Michal Maczka * @version $Id$ */ public class DAGTest - extends TestCase { + @Test public void testDAG() throws CycleDetectedException { @@ -131,6 +135,7 @@ public void testDAG() assertTrue( d.getParentLabels().contains( "c" ) ); } + @Test public void testGetPredecessors() throws CycleDetectedException { diff --git a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java index fded5ee2..67afbbeb 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/TopologicalSorterTest.java @@ -16,18 +16,20 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.List; +import org.junit.Test; + /** * @author Michal Maczka * @version $Id$ */ public class TopologicalSorterTest - extends TestCase { + @Test public void testDfs() throws CycleDetectedException { diff --git a/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java b/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java index b7c135dc..0044795b 100644 --- a/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java +++ b/src/test/java/org/codehaus/plexus/util/dag/VertexTest.java @@ -16,15 +16,17 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * @author Michal Maczka * @version $Id$ */ public class VertexTest - extends TestCase { + @Test public void testVertex() { diff --git a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java index 9c34bd38..39b3f9fa 100644 --- a/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java +++ b/src/test/java/org/codehaus/plexus/util/introspection/ReflectionValueExtractorTest.java @@ -1,5 +1,6 @@ package org.codehaus.plexus.util.introspection; + /* * Copyright The Codehaus Foundation. * @@ -16,30 +17,32 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; -import junit.framework.Assert; -import junit.framework.TestCase; import org.apache.maven.plugin.testing.stubs.MavenProjectStub; +import org.junit.Before; +import org.junit.Test; /** * @author Jason van Zyl * @version $Id$ */ public class ReflectionValueExtractorTest - extends TestCase { private Project project; - protected void setUp() + @Before + public void setUp() throws Exception { - super.setUp(); - Dependency dependency1 = new Dependency(); dependency1.setArtifactId( "dep1" ); Dependency dependency2 = new Dependency(); @@ -63,6 +66,7 @@ protected void setUp() project.addArtifact( new Artifact( "g2", "a2", "v2", "e2", "c2" ) ); } + @Test public void testValueExtraction() throws Exception { @@ -92,9 +96,9 @@ public void testValueExtraction() List dependencies = (List) ReflectionValueExtractor.evaluate( "project.dependencies", project ); - Assert.assertNotNull( dependencies ); + assertNotNull( dependencies ); - Assert.assertEquals( 2, dependencies.size() ); + assertEquals( 2, dependencies.size() ); // ---------------------------------------------------------------------- // Dependencies - using index notation @@ -103,38 +107,38 @@ public void testValueExtraction() // List Dependency dependency = (Dependency) ReflectionValueExtractor.evaluate( "project.dependencies[0]", project ); - Assert.assertNotNull( dependency ); + assertNotNull( dependency ); - Assert.assertTrue( "dep1".equals( dependency.getArtifactId() ) ); + assertTrue( "dep1".equals( dependency.getArtifactId() ) ); String artifactId = (String) ReflectionValueExtractor.evaluate( "project.dependencies[1].artifactId", project ); - Assert.assertTrue( "dep2".equals( artifactId ) ); + assertTrue( "dep2".equals( artifactId ) ); // Array dependency = (Dependency) ReflectionValueExtractor.evaluate( "project.dependenciesAsArray[0]", project ); - Assert.assertNotNull( dependency ); + assertNotNull( dependency ); - Assert.assertTrue( "dep1".equals( dependency.getArtifactId() ) ); + assertTrue( "dep1".equals( dependency.getArtifactId() ) ); artifactId = (String) ReflectionValueExtractor.evaluate( "project.dependenciesAsArray[1].artifactId", project ); - Assert.assertTrue( "dep2".equals( artifactId ) ); + assertTrue( "dep2".equals( artifactId ) ); // Map dependency = (Dependency) ReflectionValueExtractor.evaluate( "project.dependenciesAsMap(dep1)", project ); - Assert.assertNotNull( dependency ); + assertNotNull( dependency ); - Assert.assertTrue( "dep1".equals( dependency.getArtifactId() ) ); + assertTrue( "dep1".equals( dependency.getArtifactId() ) ); artifactId = (String) ReflectionValueExtractor.evaluate( "project.dependenciesAsMap(dep2).artifactId", project ); - Assert.assertTrue( "dep2".equals( artifactId ) ); + assertTrue( "dep2".equals( artifactId ) ); // ---------------------------------------------------------------------- // Build @@ -142,26 +146,29 @@ public void testValueExtraction() Build build = (Build) ReflectionValueExtractor.evaluate( "project.build", project ); - Assert.assertNotNull( build ); + assertNotNull( build ); } + @Test public void testValueExtractorWithAInvalidExpression() throws Exception { - Assert.assertNull( ReflectionValueExtractor.evaluate( "project.foo", project ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "project.dependencies[10]", project ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "project.dependencies[0].foo", project ) ); + assertNull( ReflectionValueExtractor.evaluate( "project.foo", project ) ); + assertNull( ReflectionValueExtractor.evaluate( "project.dependencies[10]", project ) ); + assertNull( ReflectionValueExtractor.evaluate( "project.dependencies[0].foo", project ) ); } + @Test public void testMappedDottedKey() throws Exception { Map map = new HashMap(); map.put( "a.b", "a.b-value" ); - Assert.assertEquals( "a.b-value", ReflectionValueExtractor.evaluate( "h.value(a.b)", new ValueHolder( map ) ) ); + assertEquals( "a.b-value", ReflectionValueExtractor.evaluate( "h.value(a.b)", new ValueHolder( map ) ) ); } + @Test public void testIndexedMapped() throws Exception { @@ -170,9 +177,10 @@ public void testIndexedMapped() List list = new ArrayList(); list.add( map ); - Assert.assertEquals( "a-value", ReflectionValueExtractor.evaluate( "h.value[0](a)", new ValueHolder( list ) ) ); + assertEquals( "a-value", ReflectionValueExtractor.evaluate( "h.value[0](a)", new ValueHolder( list ) ) ); } + @Test public void testMappedIndexed() throws Exception { @@ -180,31 +188,35 @@ public void testMappedIndexed() list.add( "a-value" ); Map map = new HashMap(); map.put( "a", list ); - Assert.assertEquals( "a-value", ReflectionValueExtractor.evaluate( "h.value(a)[0]", new ValueHolder( map ) ) ); + assertEquals( "a-value", ReflectionValueExtractor.evaluate( "h.value(a)[0]", new ValueHolder( map ) ) ); } + @Test public void testMappedMissingDot() throws Exception { Map map = new HashMap(); map.put( "a", new ValueHolder( "a-value" ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value(a)value", new ValueHolder( map ) ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value(a)value", new ValueHolder( map ) ) ); } + @Test public void testIndexedMissingDot() throws Exception { List list = new ArrayList(); list.add( new ValueHolder( "a-value" ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value[0]value", new ValueHolder( list ) ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value[0]value", new ValueHolder( list ) ) ); } + @Test public void testDotDot() throws Exception { - Assert.assertNull( ReflectionValueExtractor.evaluate( "h..value", new ValueHolder( "value" ) ) ); + assertNull( ReflectionValueExtractor.evaluate( "h..value", new ValueHolder( "value" ) ) ); } + @Test public void testBadIndexedSyntax() throws Exception { @@ -212,14 +224,15 @@ public void testBadIndexedSyntax() list.add( "a-value" ); Object value = new ValueHolder( list ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value[", value ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value[]", value ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value[a]", value ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value[0", value ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value[0)", value ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value[-1]", value ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value[", value ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value[]", value ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value[a]", value ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value[0", value ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value[0)", value ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value[-1]", value ) ); } + @Test public void testBadMappedSyntax() throws Exception { @@ -227,12 +240,13 @@ public void testBadMappedSyntax() map.put( "a", "a-value" ); Object value = new ValueHolder( map ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value(", value ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value()", value ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value(a", value ) ); - Assert.assertNull( ReflectionValueExtractor.evaluate( "h.value(a]", value ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value(", value ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value()", value ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value(a", value ) ); + assertNull( ReflectionValueExtractor.evaluate( "h.value(a]", value ) ); } + @Test public void testIllegalIndexedType() throws Exception { @@ -246,6 +260,7 @@ public void testIllegalIndexedType() } } + @Test public void testIllegalMappedType() throws Exception { @@ -259,12 +274,14 @@ public void testIllegalMappedType() } } + @Test public void testTrimRootToken() throws Exception { - Assert.assertNull( ReflectionValueExtractor.evaluate( "project", project, true ) ); + assertNull( ReflectionValueExtractor.evaluate( "project", project, true ) ); } + @Test public void testArtifactMap() throws Exception { @@ -526,6 +543,7 @@ public Object getValue() } } + @Test public void testRootPropertyRegression() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java index 841800a4..c8f1c4aa 100644 --- a/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java +++ b/src/test/java/org/codehaus/plexus/util/reflection/ReflectorTest.java @@ -16,24 +16,25 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; /** * @author Jörg Schaible * @version $Id$ */ public class ReflectorTest - extends TestCase { private Project project; private Reflector reflector; - protected void setUp() + @Before + public void setUp() throws Exception { - super.setUp(); - project = new Project(); project.setModelVersion( "1.0.0" ); project.setVersion( "42" ); @@ -41,18 +42,21 @@ protected void setUp() reflector = new Reflector(); } + @Test public void testObjectPropertyFromName() throws Exception { assertEquals( "1.0.0", reflector.getObjectProperty( project, "modelVersion" ) ); } + @Test public void testObjectPropertyFromBean() throws Exception { assertEquals( "Foo", reflector.getObjectProperty( project, "name" ) ); } + @Test public void testObjectPropertyFromField() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java index 23f37894..128d004f 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/PrettyPrintXMLWriterTest.java @@ -16,6 +16,10 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -26,8 +30,9 @@ import javax.swing.text.html.HTML.Tag; import org.codehaus.plexus.util.StringUtils; - -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * Test of {@link PrettyPrintXMLWriter} @@ -37,27 +42,20 @@ * @version $Id$ */ public class PrettyPrintXMLWriterTest - extends TestCase { StringWriter w; PrettyPrintXMLWriter writer; - /** {@inheritDoc} */ - protected void setUp() - throws Exception + @Before + public void setUp() { - super.setUp(); - initWriter(); } - /** {@inheritDoc} */ - protected void tearDown() - throws Exception + @After + public void tearDown() { - super.tearDown(); - writer = null; w = null; } @@ -68,6 +66,7 @@ private void initWriter() writer = new PrettyPrintXMLWriter( w ); } + @Test public void testDefaultPrettyPrintXMLWriter() { writer.startElement( Tag.HTML.toString() ); @@ -81,6 +80,7 @@ public void testDefaultPrettyPrintXMLWriter() assertEquals( expectedResult( PrettyPrintXMLWriter.LS ), w.toString() ); } + @Test public void testPrettyPrintXMLWriterWithGivenLineSeparator() { writer.setLineSeparator( "\n" ); @@ -96,6 +96,7 @@ public void testPrettyPrintXMLWriterWithGivenLineSeparator() assertEquals( expectedResult( "\n" ), w.toString() ); } + @Test public void testPrettyPrintXMLWriterWithGivenLineIndenter() { writer.setLineIndenter( " " ); @@ -111,6 +112,7 @@ public void testPrettyPrintXMLWriterWithGivenLineIndenter() assertEquals( expectedResult( " ", PrettyPrintXMLWriter.LS ), w.toString() ); } + @Test public void testEscapeXmlAttribute() { // Windows @@ -134,6 +136,7 @@ public void testEscapeXmlAttribute() assertEquals( "
", w.toString() ); } + @Test public void testendElementAlreadyClosed() { try @@ -151,19 +154,14 @@ public void testendElementAlreadyClosed() } /** - * Issue #51: https://github.com/codehaus-plexus/plexus-utils/issues/51 - * - * Purpose: test if concatenation string optimization bug is present. - * - * Target environment: Java 7 (u79 and u80 verified) running on Windows. - * - * Detection strategy: Tries to build a big XML file (~750MB size) and with - * many nested tags to force the JVM to trigger the concatenation string - * optimization bug that throws a NoSuchElementException when calling - * endElement() method. + * Issue #51: https://github.com/codehaus-plexus/plexus-utils/issues/51 Purpose: test if concatenation string + * optimization bug is present. Target environment: Java 7 (u79 and u80 verified) running on Windows. Detection + * strategy: Tries to build a big XML file (~750MB size) and with many nested tags to force the JVM to trigger the + * concatenation string optimization bug that throws a NoSuchElementException when calling endElement() method. * * @throws IOException if an I/O error occurs */ + @Test public void testIssue51DetectJava7ConcatenationBug() throws IOException { diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java index f6ba1f90..f87ab7d3 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlStreamWriterTest.java @@ -1,5 +1,7 @@ package org.codehaus.plexus.util.xml; +import static org.junit.Assert.assertEquals; + /* * Copyright The Codehaus Foundation. * @@ -19,10 +21,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; -import junit.framework.TestCase; +import org.junit.Test; public class XmlStreamWriterTest - extends TestCase { /** french */ private static final String TEXT_LATIN1 = "eacute: \u00E9"; @@ -71,6 +72,7 @@ private static void checkXmlWriter( String text, String encoding ) checkXmlContent( xml, effectiveEncoding ); } + @Test public void testNoXmlHeader() throws IOException { @@ -78,6 +80,7 @@ public void testNoXmlHeader() checkXmlContent( xml, "UTF-8" ); } + @Test public void testEmpty() throws IOException { @@ -91,60 +94,70 @@ public void testEmpty() writer.close(); } + @Test public void testDefaultEncoding() throws IOException { checkXmlWriter( TEXT_UNICODE, null ); } + @Test public void testUTF8Encoding() throws IOException { checkXmlWriter( TEXT_UNICODE, "UTF-8" ); } + @Test public void testUTF16Encoding() throws IOException { checkXmlWriter( TEXT_UNICODE, "UTF-16" ); } + @Test public void testUTF16BEEncoding() throws IOException { checkXmlWriter( TEXT_UNICODE, "UTF-16BE" ); } + @Test public void testUTF16LEEncoding() throws IOException { checkXmlWriter( TEXT_UNICODE, "UTF-16LE" ); } + @Test public void testLatin1Encoding() throws IOException { checkXmlWriter( TEXT_LATIN1, "ISO-8859-1" ); } + @Test public void testLatin7Encoding() throws IOException { checkXmlWriter( TEXT_LATIN7, "ISO-8859-7" ); } + @Test public void testLatin15Encoding() throws IOException { checkXmlWriter( TEXT_LATIN15, "ISO-8859-15" ); } + @Test public void testEUC_JPEncoding() throws IOException { checkXmlWriter( TEXT_EUC_JP, "EUC-JP" ); } + @Test public void testEBCDICEncoding() throws IOException { diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java index eac61719..25ee91ae 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlUtilTest.java @@ -16,6 +16,9 @@ * limitations under the License. */ +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -26,12 +29,11 @@ import java.io.StringWriter; import java.io.Writer; -import junit.framework.TestCase; - import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; +import org.junit.Test; /** * Test the {@link XmlUtil} class. @@ -40,7 +42,6 @@ * @version $Id$ */ public class XmlUtilTest - extends TestCase { private String basedir; @@ -65,20 +66,7 @@ private File getTestOutputFile( String relPath ) return file; } - /** {@inheritDoc} */ - protected void setUp() - throws Exception - { - super.setUp(); - } - - /** {@inheritDoc} */ - protected void tearDown() - throws Exception - { - super.tearDown(); - } - + @Test public void testPrettyFormatInputStreamOutputStream() throws Exception { @@ -104,6 +92,7 @@ public void testPrettyFormatInputStreamOutputStream() } } + @Test public void testPrettyFormatReaderWriter() throws Exception { @@ -130,6 +119,7 @@ public void testPrettyFormatReaderWriter() } } + @Test public void testPrettyFormatString() throws Exception { @@ -160,6 +150,7 @@ public void testPrettyFormatString() assertTrue( countEOL < StringUtils.countMatches( writer.toString(), XmlUtil.DEFAULT_LINE_SEPARATOR ) ); } + @Test public void testPrettyFormatReaderWriter2() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java index bb29b157..6c4fe638 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/XmlWriterUtilTest.java @@ -16,21 +16,24 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.io.Writer; -import junit.framework.TestCase; - import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.WriterFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; /** * @author Vincent Siveton * @version $Id$ */ public class XmlWriterUtilTest - extends TestCase { private OutputStream output; @@ -38,23 +41,19 @@ public class XmlWriterUtilTest private XMLWriter xmlWriter; - /** {@inheritDoc} */ - protected void setUp() + @Before + public void setUp() throws Exception { - super.setUp(); - output = new ByteArrayOutputStream(); writer = WriterFactory.newXmlWriter( output ); xmlWriter = new PrettyPrintXMLWriter( writer ); } - /** {@inheritDoc} */ - protected void tearDown() + @After + public void tearDown() throws Exception { - super.tearDown(); - xmlWriter = null; writer = null; output = null; @@ -66,6 +65,7 @@ protected void tearDown() * * @throws Exception if any */ + @Test public void testWriteLineBreakXMLWriter() throws Exception { @@ -80,6 +80,7 @@ public void testWriteLineBreakXMLWriter() * * @throws Exception if any */ + @Test public void testWriteLineBreakXMLWriterInt() throws Exception { @@ -94,6 +95,7 @@ public void testWriteLineBreakXMLWriterInt() * * @throws Exception if any */ + @Test public void testWriteLineBreakXMLWriterIntInt() throws Exception { @@ -111,6 +113,7 @@ public void testWriteLineBreakXMLWriterIntInt() * * @throws Exception if any */ + @Test public void testWriteLineBreakXMLWriterIntIntInt() throws Exception { @@ -126,6 +129,7 @@ public void testWriteLineBreakXMLWriterIntIntInt() * * @throws Exception if any */ + @Test public void testWriteCommentLineBreakXMLWriter() throws Exception { @@ -143,6 +147,7 @@ public void testWriteCommentLineBreakXMLWriter() * * @throws Exception if any */ + @Test public void testWriteCommentLineBreakXMLWriterInt() throws Exception { @@ -164,6 +169,7 @@ public void testWriteCommentLineBreakXMLWriterInt() * * @throws Exception if any */ + @Test public void testWriteCommentXMLWriterString() throws Exception { @@ -204,6 +210,7 @@ public void testWriteCommentXMLWriterString() * * @throws Exception if any */ + @Test public void testWriteCommentXMLWriterStringInt() throws Exception { @@ -239,6 +246,7 @@ public void testWriteCommentXMLWriterStringInt() * * @throws Exception if any */ + @Test public void testWriteCommentXMLWriterStringIntInt() throws Exception { @@ -274,6 +282,7 @@ public void testWriteCommentXMLWriterStringIntInt() * * @throws Exception if any */ + @Test public void testWriteCommentXMLWriterStringIntIntInt() throws Exception { @@ -305,6 +314,7 @@ public void testWriteCommentXMLWriterStringIntIntInt() * * @throws Exception if any */ + @Test public void testWriteCommentTextXMLWriterStringInt() throws Exception { @@ -347,6 +357,7 @@ public void testWriteCommentTextXMLWriterStringInt() * * @throws Exception if any */ + @Test public void testWriteCommentTextXMLWriterStringIntInt() throws Exception { @@ -372,6 +383,7 @@ public void testWriteCommentTextXMLWriterStringIntInt() * * @throws Exception if any */ + @Test public void testWriteCommentTextXMLWriterStringIntIntInt() throws Exception { @@ -397,6 +409,7 @@ public void testWriteCommentTextXMLWriterStringIntIntInt() * * @throws Exception if any */ + @Test public void testWriteCommentNull() throws Exception { @@ -413,6 +426,7 @@ public void testWriteCommentNull() * * @throws Exception if any */ + @Test public void testWriteCommentShort() throws Exception { @@ -429,6 +443,7 @@ public void testWriteCommentShort() * * @throws Exception if any */ + @Test public void testWriteCommentLong() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java index 76b0ec5d..302443c2 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomBuilderTest.java @@ -16,15 +16,19 @@ * limitations under the License. */ -import junit.framework.TestCase; -import org.codehaus.plexus.util.xml.pull.MXParser; -import org.codehaus.plexus.util.xml.pull.XmlPullParser; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import org.codehaus.plexus.util.xml.pull.MXParser; +import org.codehaus.plexus.util.xml.pull.XmlPullParser; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.junit.Test; + /** * Test the Xpp3DomBuilder. * @@ -32,11 +36,10 @@ * @version $Id$ */ public class Xpp3DomBuilderTest - extends TestCase { + private static final String LS = System.lineSeparator(); - private static final String LS = System.getProperty( "line.separator" ); - + @Test public void testBuildFromReader() throws Exception { @@ -49,6 +52,7 @@ public void testBuildFromReader() assertEquals( "check DOMs match", expectedDom, dom ); } + @Test public void testBuildTrimming() throws Exception { @@ -63,6 +67,7 @@ public void testBuildTrimming() assertEquals( "test with trimming off", " element1\n ", dom.getChild( "el1" ).getValue() ); } + @Test public void testBuildFromXpp3Dom() throws Exception { @@ -120,6 +125,7 @@ else if ( "root".equals( rawName ) ) /** * Test we get an error from the parser, and don't hit the IllegalStateException. */ + @Test public void testUnclosedXml() { String domString = "" + createDomString(); @@ -139,6 +145,7 @@ public void testUnclosedXml() } } + @Test public void testEscapingInContent() throws IOException, XmlPullParserException { @@ -153,6 +160,7 @@ public void testEscapingInContent() assertEquals( "Compare stringified DOMs", getExpectedString(), w.toString() ); } + @Test public void testEscapingInAttributes() throws IOException, XmlPullParserException { diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java index 4c94a203..dd06f7b1 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomTest.java @@ -16,18 +16,23 @@ * limitations under the License. */ -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; import java.io.IOException; import java.io.StringReader; import java.util.HashMap; -import junit.framework.TestCase; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.junit.Test; public class Xpp3DomTest - extends TestCase { - + @Test public void testShouldPerformAppendAtFirstSubElementLevel() { // create the dominant DOM @@ -53,6 +58,7 @@ public void testShouldPerformAppendAtFirstSubElementLevel() assertEquals( 2, result.getChildren( "topsub1" ).length ); } + @Test public void testShouldOverrideAppendAndDeepMerge() { // create the dominant DOM @@ -78,6 +84,7 @@ public void testShouldOverrideAppendAndDeepMerge() assertEquals( 1, result.getChildren( "topsub1" ).length ); } + @Test public void testShouldPerformSelfOverrideAtTopLevel() { // create the dominant DOM @@ -98,6 +105,7 @@ public void testShouldPerformSelfOverrideAtTopLevel() assertNull( result.getValue() ); } + @Test public void testShouldMergeValuesAtTopLevelByDefault() { // create the dominant DOM @@ -118,6 +126,7 @@ public void testShouldMergeValuesAtTopLevelByDefault() assertEquals( result.getValue(), t2.getValue() ); } + @Test public void testShouldMergeValuesAtTopLevel() { // create the dominant DOM @@ -138,6 +147,7 @@ public void testShouldMergeValuesAtTopLevel() assertEquals( result.getValue(), t2.getValue() ); } + @Test public void testNullAttributeNameOrValue() { Xpp3Dom t1 = new Xpp3Dom( "top" ); @@ -161,6 +171,7 @@ public void testNullAttributeNameOrValue() t1.toString(); } + @Test public void testEquals() { Xpp3Dom dom = new Xpp3Dom( "top" ); @@ -170,6 +181,7 @@ public void testEquals() assertFalse( dom.equals( new Xpp3Dom( (String) null ) ) ); } + @Test public void testEqualsIsNullSafe() throws XmlPullParserException, IOException { @@ -196,6 +208,7 @@ public void testEqualsIsNullSafe() } } + @Test public void testShouldOverwritePluginConfigurationSubItemsByDefault() throws XmlPullParserException, IOException { @@ -214,6 +227,7 @@ public void testShouldOverwritePluginConfigurationSubItemsByDefault() assertEquals( "three", item.getValue() ); } + @Test public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() throws XmlPullParserException, IOException { @@ -236,6 +250,7 @@ public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() assertEquals( "three", item[2].getValue() ); } + @Test public void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty() throws Exception { @@ -253,6 +268,7 @@ public void testShouldNotChangeUponMergeWithItselfWhenFirstOrLastSubItemIsEmpty( assertEquals( null, items.getChild( 2 ).getValue() ); } + @Test public void testShouldCopyRecessiveChildrenNotPresentInTarget() throws Exception { @@ -270,6 +286,7 @@ public void testShouldCopyRecessiveChildrenNotPresentInTarget() assertNotSame( result.getChild( "bar" ), recessiveConfig.getChild( "bar" ) ); } + @Test public void testDupeChildren() throws IOException, XmlPullParserException { diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java index 5be4fa85..f41f2641 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java @@ -16,14 +16,15 @@ * limitations under the License. */ +import static org.junit.Assert.assertEquals; + import java.io.StringReader; -import junit.framework.TestCase; +import org.junit.Test; public class Xpp3DomUtilsTest - extends TestCase { - + @Test public void testCombineId() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java index 81ea5951..c218e4c7 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomWriterTest.java @@ -16,18 +16,20 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import java.io.StringWriter; +import org.junit.Test; + /** * @author Edwin Punzalan */ public class Xpp3DomWriterTest - extends TestCase { private static final String LS = System.getProperty( "line.separator" ); + @Test public void testWriter() { StringWriter writer = new StringWriter(); @@ -37,6 +39,7 @@ public void testWriter() assertEquals( "Check if output matches", createExpectedXML( true ), writer.toString() ); } + @Test public void testWriterNoEscape() { StringWriter writer = new StringWriter(); diff --git a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java index 5df8a972..a50b4507 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/pull/MXParserTest.java @@ -16,18 +16,20 @@ * limitations under the License. */ -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; import java.io.IOException; import java.io.StringReader; +import org.junit.Test; + /** * @author Trygve Laugstøl * @version $Id$ */ public class MXParserTest - extends TestCase { + @Test public void testHexadecimalEntities() throws Exception { @@ -48,6 +50,7 @@ public void testHexadecimalEntities() assertEquals( XmlPullParser.END_TAG, parser.next() ); } + @Test public void testDecimalEntities() throws Exception { @@ -68,6 +71,7 @@ public void testDecimalEntities() assertEquals( XmlPullParser.END_TAG, parser.next() ); } + @Test public void testPredefinedEntities() throws Exception { @@ -88,6 +92,7 @@ public void testPredefinedEntities() assertEquals( XmlPullParser.END_TAG, parser.next() ); } + @Test public void testEntityReplacementMap() throws XmlPullParserException, IOException { @@ -103,6 +108,7 @@ public void testEntityReplacementMap() assertEquals( XmlPullParser.END_TAG, parser.next() ); } + @Test public void testCustomEntities() throws Exception { @@ -127,6 +133,7 @@ public void testCustomEntities() assertEquals( XmlPullParser.END_TAG, parser.next() ); } + @Test public void testUnicodeEntities() throws Exception { @@ -149,6 +156,7 @@ public void testUnicodeEntities() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + @Test public void testProcessingInstruction() throws Exception { @@ -163,6 +171,7 @@ public void testProcessingInstruction() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + @Test public void testSubsequentProcessingInstructionShort() throws Exception { @@ -184,6 +193,7 @@ public void testSubsequentProcessingInstructionShort() assertEquals( XmlPullParser.END_TAG, parser.nextToken() ); } + @Test public void testSubsequentProcessingInstructionMoreThan8k() throws Exception {