| @@ -25,7 +25,8 @@ import org.apache.tools.ant.types.resources.FileResource; | |||
| import org.apache.tools.ant.types.resources.StringResource; | |||
| import org.junit.Test; | |||
| import static org.junit.Assert.assertTrue; | |||
| import static org.hamcrest.Matchers.instanceOf; | |||
| import static org.junit.Assert.assertThat; | |||
| /** | |||
| * Testing around the management of the project helpers | |||
| @@ -49,28 +50,20 @@ public class ProjectHelperRepositoryTest { | |||
| repo.registerProjectHelper(SomeHelper.class); | |||
| Resource r = new FileResource(new File("test.xml")); | |||
| ProjectHelper helper = repo.getProjectHelperForBuildFile(r); | |||
| assertTrue(helper instanceof ProjectHelper2); | |||
| helper = repo.getProjectHelperForAntlib(r); | |||
| assertTrue(helper instanceof ProjectHelper2); | |||
| assertThat(repo.getProjectHelperForBuildFile(r), instanceOf(ProjectHelper2.class)); | |||
| assertThat(repo.getProjectHelperForAntlib(r), instanceOf(ProjectHelper2.class)); | |||
| r = new FileResource(new File("test.myext")); | |||
| helper = repo.getProjectHelperForBuildFile(r); | |||
| assertTrue(helper instanceof SomeHelper); | |||
| helper = repo.getProjectHelperForAntlib(r); | |||
| assertTrue(helper instanceof SomeHelper); | |||
| assertThat(repo.getProjectHelperForBuildFile(r), instanceOf(SomeHelper.class)); | |||
| assertThat(repo.getProjectHelperForAntlib(r), instanceOf(SomeHelper.class)); | |||
| r = new StringResource("test.myext"); | |||
| helper = repo.getProjectHelperForBuildFile(r); | |||
| assertTrue(helper instanceof ProjectHelper2); | |||
| helper = repo.getProjectHelperForAntlib(r); | |||
| assertTrue(helper instanceof ProjectHelper2); | |||
| assertThat(repo.getProjectHelperForBuildFile(r), instanceOf(ProjectHelper2.class)); | |||
| assertThat(repo.getProjectHelperForAntlib(r), instanceOf(ProjectHelper2.class)); | |||
| r = new StringResource("test.other"); | |||
| helper = repo.getProjectHelperForBuildFile(r); | |||
| assertTrue(helper instanceof ProjectHelper2); | |||
| helper = repo.getProjectHelperForAntlib(r); | |||
| assertTrue(helper instanceof ProjectHelper2); | |||
| assertThat(repo.getProjectHelperForBuildFile(r), instanceOf(ProjectHelper2.class)); | |||
| assertThat(repo.getProjectHelperForAntlib(r), instanceOf(ProjectHelper2.class)); | |||
| } | |||
| @Test(expected = BuildException.class) | |||
| @@ -34,9 +34,11 @@ import org.junit.Test; | |||
| import org.junit.rules.ExpectedException; | |||
| import static org.hamcrest.Matchers.containsString; | |||
| import static org.hamcrest.Matchers.hasKey; | |||
| import static org.hamcrest.Matchers.hasValue; | |||
| import static org.hamcrest.Matchers.instanceOf; | |||
| import static org.hamcrest.Matchers.not; | |||
| 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.assertSame; | |||
| @@ -75,10 +77,10 @@ public class ProjectTest { | |||
| p.createDataType("dummy")); | |||
| Object o = p.createDataType("fileset"); | |||
| assertNotNull("fileset is a known type", o); | |||
| assertTrue("fileset creates FileSet", o instanceof FileSet); | |||
| assertTrue("PatternSet", | |||
| p.createDataType("patternset") instanceof PatternSet); | |||
| assertTrue("Path", p.createDataType("path") instanceof Path); | |||
| assertThat("fileset creates FileSet", o, instanceOf(FileSet.class)); | |||
| assertThat("PatternSet", p.createDataType("patternset"), | |||
| instanceOf(PatternSet.class)); | |||
| assertThat("Path", p.createDataType("path"), instanceOf(Path.class)); | |||
| } | |||
| /** | |||
| @@ -206,7 +208,7 @@ public class ProjectTest { | |||
| p.addTaskDefinition(dummyName, taskClass); | |||
| } finally { | |||
| mbl.assertEmpty(); | |||
| assertFalse(p.getTaskDefinitions().containsKey(dummyName)); | |||
| assertThat(p.getTaskDefinitions(), not(hasKey(dummyName))); | |||
| } | |||
| } | |||
| @@ -250,7 +252,7 @@ public class ProjectTest { | |||
| public void testInputHandler() { | |||
| InputHandler ih = p.getInputHandler(); | |||
| assertNotNull(ih); | |||
| assertTrue(ih instanceof DefaultInputHandler); | |||
| assertThat(ih, instanceOf(DefaultInputHandler.class)); | |||
| InputHandler pfih = new PropertyFileInputHandler(); | |||
| p.setInputHandler(pfih); | |||
| assertSame(pfih, p.getInputHandler()); | |||
| @@ -258,11 +260,11 @@ public class ProjectTest { | |||
| @Test | |||
| public void testTaskDefinitionContainsKey() { | |||
| assertTrue(p.getTaskDefinitions().containsKey("echo")); | |||
| assertThat(p.getTaskDefinitions(), hasKey("echo")); | |||
| } | |||
| @Test | |||
| public void testTaskDefinitionContains() { | |||
| public void testTaskDefinitionContainsValue() { | |||
| assertThat(p.getTaskDefinitions(), hasValue(org.apache.tools.ant.taskdefs.Echo.class)); | |||
| } | |||
| @@ -26,9 +26,10 @@ import org.junit.Test; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import static org.hamcrest.Matchers.instanceOf; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertTrue; | |||
| import static org.junit.Assert.assertNotNull; | |||
| import static org.junit.Assert.assertThat; | |||
| public class UnknownElementTest { | |||
| @@ -57,23 +58,30 @@ public class UnknownElementTest { | |||
| buildRule.getProject().addBuildListener(new BuildListener() { | |||
| public void buildStarted(BuildEvent event) { | |||
| } | |||
| public void buildFinished(BuildEvent event) { | |||
| } | |||
| public void targetStarted(BuildEvent event) { | |||
| } | |||
| public void targetFinished(BuildEvent event) { | |||
| } | |||
| public void taskStarted(BuildEvent event) { | |||
| assertTaskProperties(event.getTask()); | |||
| } | |||
| public void taskFinished(BuildEvent event) { | |||
| assertTaskProperties(event.getTask()); | |||
| } | |||
| public void messageLogged(BuildEvent event) { | |||
| } | |||
| private void assertTaskProperties(Task ue) { | |||
| assertNotNull(ue); | |||
| assertTrue(ue instanceof UnknownElement); | |||
| assertThat(ue, instanceOf(UnknownElement.class)); | |||
| Task t = ((UnknownElement) ue).getTask(); | |||
| assertNotNull(t); | |||
| assertEquals("org.apache.tools.ant.taskdefs.Echo", | |||
| @@ -85,9 +93,11 @@ public class UnknownElementTest { | |||
| public static class Child extends Task { | |||
| Parent parent; | |||
| public void injectParent(Parent parent) { | |||
| this.parent = parent; | |||
| } | |||
| public void execute() { | |||
| parent.fromChild(); | |||
| } | |||
| @@ -95,6 +105,7 @@ public class UnknownElementTest { | |||
| public static class Parent extends Task implements TaskContainer { | |||
| List<Task> children = new ArrayList<>(); | |||
| public void addTask(Task t) { | |||
| children.add(t); | |||
| } | |||
| @@ -173,7 +173,7 @@ public class AvailableTest { | |||
| @Test | |||
| public void test14() { | |||
| buildRule.executeTarget("test14"); | |||
| assertEquals(buildRule.getProject().getProperty("test"), null); | |||
| assertNull(buildRule.getProject().getProperty("test")); | |||
| } | |||
| /** | |||
| @@ -32,6 +32,7 @@ import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.types.Path; | |||
| import static org.hamcrest.Matchers.containsString; | |||
| import static org.hamcrest.Matchers.instanceOf; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertNotNull; | |||
| import static org.junit.Assert.assertNull; | |||
| @@ -75,8 +76,7 @@ public class JavacTest { | |||
| assertThat("name should contain \"javac\"", javac.getJavacExecutable(), containsString("javac")); | |||
| project.setProperty("build.compiler", "whatever"); | |||
| assertNull("no fork and not extJavac means no executable", | |||
| javac.getJavacExecutable()); | |||
| assertNull("no fork and not extJavac means no executable", javac.getJavacExecutable()); | |||
| String myJavac = "Slartibartfast"; | |||
| javac.setFork(true); | |||
| @@ -153,8 +153,7 @@ public class JavacTest { | |||
| String compiler = javac.getCompiler(); | |||
| assertNotNull(compiler); | |||
| if (System.getProperty("build.compiler") != null) { | |||
| assertEquals(System.getProperty("build.compiler"), | |||
| compiler); | |||
| assertEquals(System.getProperty("build.compiler"), compiler); | |||
| } else { | |||
| assertTrue("default value", | |||
| "javac1.1".equals(compiler) | |||
| @@ -200,17 +199,13 @@ public class JavacTest { | |||
| @Test | |||
| public void testCompilerAdapter() { | |||
| javac.setCompiler("javac1.4"); | |||
| javac.setDepend(true); | |||
| CompilerAdapter adapter = | |||
| CompilerAdapterFactory.getCompiler(javac.getCompiler(), javac); | |||
| assertTrue(adapter instanceof Javac13); | |||
| CompilerAdapter adapter = CompilerAdapterFactory.getCompiler(javac.getCompiler(), javac); | |||
| assertThat(adapter, instanceOf(Javac13.class)); | |||
| javac.setFork(true); | |||
| adapter = | |||
| CompilerAdapterFactory.getCompiler(javac.getCompiler(), javac); | |||
| assertTrue(adapter instanceof JavacExternal); | |||
| adapter = CompilerAdapterFactory.getCompiler(javac.getCompiler(), javac); | |||
| assertThat(adapter, instanceOf(JavacExternal.class)); | |||
| } | |||
| @Test | |||
| @@ -35,9 +35,10 @@ import org.apache.tools.zip.ZipExtraField; | |||
| import org.apache.tools.zip.ZipFile; | |||
| import org.junit.Test; | |||
| import static org.hamcrest.Matchers.instanceOf; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertNotNull; | |||
| import static org.junit.Assert.assertTrue; | |||
| import static org.junit.Assert.assertThat; | |||
| public class ZipExtraFieldTest { | |||
| @@ -97,10 +98,10 @@ public class ZipExtraFieldTest { | |||
| ZipEntry ze = zf.getEntry("x"); | |||
| assertNotNull(ze); | |||
| assertEquals(expectZip64 ? 2 : 1, ze.getExtraFields().length); | |||
| assertTrue(ze.getExtraFields()[0] instanceof JarMarker); | |||
| assertThat(ze.getExtraFields()[0], instanceOf(JarMarker.class)); | |||
| if (expectZip64) { | |||
| assertTrue(ze.getExtraFields()[1] | |||
| instanceof Zip64ExtendedInformationExtraField); | |||
| assertThat(ze.getExtraFields()[1], | |||
| instanceOf(Zip64ExtendedInformationExtraField.class)); | |||
| } | |||
| } finally { | |||
| ZipFile.closeQuietly(zf); | |||
| @@ -32,7 +32,10 @@ import org.junit.Rule; | |||
| import org.junit.Test; | |||
| import org.junit.rules.ExpectedException; | |||
| import static org.hamcrest.Matchers.instanceOf; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertNotEquals; | |||
| import static org.junit.Assert.assertThat; | |||
| import static org.junit.Assert.assertTrue; | |||
| /** | |||
| @@ -130,7 +133,7 @@ public class JspcTest { | |||
| protected void assertJavaFileCreated(String filename) { | |||
| File file = getOutputFile(filename); | |||
| assertTrue("file " + filename + " not found", file.exists()); | |||
| assertTrue("file " + filename + " is empty", file.length() > 0); | |||
| assertNotEquals("file " + filename + " is empty", 0, file.length()); | |||
| } | |||
| /** | |||
| @@ -151,10 +154,10 @@ public class JspcTest { | |||
| JspCompilerAdapter adapter = | |||
| JspCompilerAdapterFactory.getCompiler("jasper", null, null); | |||
| JspMangler mangler = adapter.createMangler(); | |||
| assertTrue(mangler instanceof JspNameMangler); | |||
| assertThat(mangler, instanceOf(JspNameMangler.class)); | |||
| adapter = JspCompilerAdapterFactory.getCompiler("jasper41", null, null); | |||
| mangler = adapter.createMangler(); | |||
| assertTrue(mangler instanceof Jasper41Mangler); | |||
| assertThat(mangler, instanceOf(Jasper41Mangler.class)); | |||
| } | |||
| @Test | |||
| @@ -19,7 +19,9 @@ | |||
| package org.apache.tools.ant.taskdefs.optional.depend; | |||
| import java.io.File; | |||
| import java.util.Arrays; | |||
| import java.util.Hashtable; | |||
| import java.util.stream.Collectors; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.BuildFileRule; | |||
| @@ -33,6 +35,7 @@ import org.junit.rules.ExpectedException; | |||
| import static org.hamcrest.Matchers.both; | |||
| import static org.hamcrest.Matchers.containsString; | |||
| import static org.hamcrest.Matchers.hasKey; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertThat; | |||
| import static org.junit.Assert.assertTrue; | |||
| @@ -71,12 +74,9 @@ public class DependTest { | |||
| buildRule.executeTarget("testdirect"); | |||
| Hashtable<String, String> files = getResultFiles(); | |||
| assertEquals("Depend did not leave correct number of files", 3, | |||
| files.size()); | |||
| assertTrue("Result did not contain A.class", | |||
| files.containsKey("A.class")); | |||
| assertTrue("Result did not contain D.class", | |||
| files.containsKey("D.class")); | |||
| assertEquals("Depend did not leave correct number of files", 3, files.size()); | |||
| assertThat("Result did not contain A.class", files, hasKey("A.class")); | |||
| assertThat("Result did not contain D.class", files, hasKey("D.class")); | |||
| } | |||
| /** | |||
| @@ -92,10 +92,8 @@ public class DependTest { | |||
| buildRule.executeTarget("testclosure"); | |||
| Hashtable<String, String> files = getResultFiles(); | |||
| assertTrue("Depend did not leave correct number of files", | |||
| files.size() <= 2); | |||
| assertTrue("Result did not contain D.class", | |||
| files.containsKey("D.class")); | |||
| assertTrue("Depend did not leave correct number of files", files.size() <= 2); | |||
| assertThat("Result did not contain D.class", files, hasKey("D.class")); | |||
| } | |||
| /** | |||
| @@ -110,8 +108,7 @@ public class DependTest { | |||
| FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); | |||
| buildRule.executeTarget("testinner"); | |||
| assertEquals("Depend did not leave correct number of files", 0, | |||
| getResultFiles().size()); | |||
| assertEquals("Depend did not leave correct number of files", 0, getResultFiles().size()); | |||
| } | |||
| /** | |||
| @@ -127,8 +124,7 @@ public class DependTest { | |||
| FileUtilities.rollbackTimestamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); | |||
| buildRule.executeTarget("testinnerinner"); | |||
| assertEquals("Depend did not leave correct number of files", 0, | |||
| getResultFiles().size()); | |||
| assertEquals("Depend did not leave correct number of files", 0, getResultFiles().size()); | |||
| } | |||
| /** | |||
| @@ -160,11 +156,8 @@ public class DependTest { | |||
| private Hashtable<String, String> getResultFiles() { | |||
| FileSet resultFileSet = buildRule.getProject().getReference(RESULT_FILESET); | |||
| DirectoryScanner scanner = resultFileSet.getDirectoryScanner(buildRule.getProject()); | |||
| Hashtable<String, String> files = new Hashtable<>(); | |||
| for (String scannedFile : scanner.getIncludedFiles()) { | |||
| files.put(scannedFile, scannedFile); | |||
| } | |||
| return files; | |||
| return Arrays.stream(scanner.getIncludedFiles()) | |||
| .collect(Collectors.toMap(file -> file, file -> file, (a, b) -> b, Hashtable::new)); | |||
| } | |||
| @@ -28,11 +28,11 @@ import java.io.File; | |||
| import static org.hamcrest.Matchers.containsString; | |||
| import static org.hamcrest.Matchers.endsWith; | |||
| import static org.hamcrest.Matchers.hasKey; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertNotNull; | |||
| import static org.junit.Assert.assertNull; | |||
| import static org.junit.Assert.assertThat; | |||
| import static org.junit.Assert.assertTrue; | |||
| /** | |||
| * JUnit testcases for org.apache.tools.ant.CommandlineJava | |||
| @@ -145,7 +145,7 @@ public class CommandlineJavaTest { | |||
| assertEquals(currentClasspath, newClasspath); | |||
| assertNotNull(System.getProperty("key")); | |||
| assertEquals("value", System.getProperty("key")); | |||
| assertTrue(System.getProperties().containsKey("java.class.path")); | |||
| assertThat(System.getProperties(), hasKey("java.class.path")); | |||
| assertNotNull(System.getProperty("key2")); | |||
| assertEquals("value2", System.getProperty("key2")); | |||
| } finally { | |||
| @@ -35,11 +35,11 @@ import org.junit.Test; | |||
| import org.junit.rules.ExpectedException; | |||
| import static org.hamcrest.Matchers.hasItem; | |||
| import static org.hamcrest.Matchers.instanceOf; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertNotNull; | |||
| import static org.junit.Assert.assertNull; | |||
| import static org.junit.Assert.assertThat; | |||
| import static org.junit.Assert.assertTrue; | |||
| /** | |||
| * JUnit testcases for org.apache.tools.ant.types.Mapper. | |||
| @@ -141,7 +141,7 @@ public class MapperTest { | |||
| m3.setFrom("*.java"); | |||
| m3.setTo("*.class"); | |||
| FileNameMapper fmm = m.getImplementation(); | |||
| assertTrue("should be glob", fmm instanceof GlobPatternMapper); | |||
| assertThat("should be glob", fmm, instanceOf(GlobPatternMapper.class)); | |||
| String[] result = fmm.mapFileName("a.java"); | |||
| assertEquals("a.java should match", 1, result.length); | |||
| assertEquals("a.class", result[0]); | |||
| @@ -19,18 +19,20 @@ | |||
| package org.apache.tools.ant.types.optional.depend; | |||
| import java.io.File; | |||
| import java.util.Arrays; | |||
| import java.util.Hashtable; | |||
| import java.util.stream.Collectors; | |||
| import org.apache.tools.ant.BuildFileRule; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.types.FileSet; | |||
| import org.junit.Before; | |||
| import org.junit.Rule; | |||
| import org.junit.Test; | |||
| import static org.hamcrest.Matchers.hasKey; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertTrue; | |||
| import static org.junit.Assert.assertThat; | |||
| /** | |||
| * Testcase for the Classfileset optional type. | |||
| @@ -53,25 +55,14 @@ public class ClassFileSetTest { | |||
| */ | |||
| @Test | |||
| public void testBasicSet() { | |||
| Project p = buildRule.getProject(); | |||
| buildRule.executeTarget("testbasicset"); | |||
| FileSet resultFileSet = p.getReference(RESULT_FILESET); | |||
| DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p); | |||
| String[] scannedFiles = scanner.getIncludedFiles(); | |||
| Hashtable<String, String> files = new Hashtable<>(); | |||
| for (String scannedFile : scannedFiles) { | |||
| files.put(scannedFile, scannedFile); | |||
| } | |||
| assertEquals("Classfileset did not pick up expected number of " | |||
| + "class files", 4, files.size()); | |||
| assertTrue("Result did not contain A.class", | |||
| files.containsKey("A.class")); | |||
| assertTrue("Result did not contain B.class", | |||
| files.containsKey("B.class")); | |||
| assertTrue("Result did not contain C.class", | |||
| files.containsKey("C.class")); | |||
| assertTrue("Result did not contain D.class", | |||
| files.containsKey("D.class")); | |||
| Hashtable<String, String> files = getFiles(); | |||
| assertEquals("Classfileset did not pick up expected number of class files", | |||
| 4, files.size()); | |||
| assertThat("Result did not contain A.class", files, hasKey("A.class")); | |||
| assertThat("Result did not contain B.class", files, hasKey("B.class")); | |||
| assertThat("Result did not contain C.class", files, hasKey("C.class")); | |||
| assertThat("Result did not contain D.class", files, hasKey("D.class")); | |||
| } | |||
| /** | |||
| @@ -79,20 +70,12 @@ public class ClassFileSetTest { | |||
| */ | |||
| @Test | |||
| public void testSmallSet() { | |||
| Project p = buildRule.getProject(); | |||
| buildRule.executeTarget("testsmallset"); | |||
| FileSet resultFileSet = p.getReference(RESULT_FILESET); | |||
| DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p); | |||
| Hashtable<String, String> files = new Hashtable<>(); | |||
| for (String scannedFile : scanner.getIncludedFiles()) { | |||
| files.put(scannedFile, scannedFile); | |||
| } | |||
| assertEquals("Classfileset did not pick up expected number of " | |||
| + "class files", 2, files.size()); | |||
| assertTrue("Result did not contain B.class", | |||
| files.containsKey("B.class")); | |||
| assertTrue("Result did not contain C.class", | |||
| files.containsKey("C.class")); | |||
| Hashtable<String, String> files = getFiles(); | |||
| assertEquals("Classfileset did not pick up expected number of class files", | |||
| 2, files.size()); | |||
| assertThat("Result did not contain B.class", files, hasKey("B.class")); | |||
| assertThat("Result did not contain C.class", files, hasKey("C.class")); | |||
| } | |||
| /** | |||
| @@ -100,18 +83,11 @@ public class ClassFileSetTest { | |||
| */ | |||
| @Test | |||
| public void testComboSet() { | |||
| Project p = buildRule.getProject(); | |||
| buildRule.executeTarget("testcomboset"); | |||
| FileSet resultFileSet = p.getReference(RESULT_FILESET); | |||
| DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p); | |||
| Hashtable<String, String> files = new Hashtable<>(); | |||
| for (String scannedFile : scanner.getIncludedFiles()) { | |||
| files.put(scannedFile, scannedFile); | |||
| } | |||
| assertEquals("Classfileset did not pick up expected number of " | |||
| + "class files", 1, files.size()); | |||
| assertTrue("Result did not contain C.class", | |||
| files.containsKey("C.class")); | |||
| Hashtable<String, String> files = getFiles(); | |||
| assertEquals("Classfileset did not pick up expected number of class files", | |||
| 1, files.size()); | |||
| assertThat("Result did not contain C.class", files, hasKey("C.class")); | |||
| } | |||
| /** | |||
| @@ -127,26 +103,15 @@ public class ClassFileSetTest { | |||
| */ | |||
| @Test | |||
| public void testMethodParam() { | |||
| Project p = buildRule.getProject(); | |||
| buildRule.executeTarget("testmethodparam"); | |||
| FileSet resultFileSet = p.getReference(RESULT_FILESET); | |||
| DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p); | |||
| Hashtable<String, String> files = new Hashtable<>(); | |||
| for (String scannedFile : scanner.getIncludedFiles()) { | |||
| files.put(scannedFile, scannedFile); | |||
| } | |||
| assertEquals("Classfileset did not pick up expected number of " | |||
| + "class files", 5, files.size()); | |||
| assertTrue("Result did not contain A.class", | |||
| files.containsKey("A.class")); | |||
| assertTrue("Result did not contain B.class", | |||
| files.containsKey("B.class")); | |||
| assertTrue("Result did not contain C.class", | |||
| files.containsKey("C.class")); | |||
| assertTrue("Result did not contain D.class", | |||
| files.containsKey("D.class")); | |||
| assertTrue("Result did not contain E.class", | |||
| files.containsKey("E.class")); | |||
| Hashtable<String, String> files = getFiles(); | |||
| assertEquals("Classfileset did not pick up expected number of class files", | |||
| 5, files.size()); | |||
| assertThat("Result did not contain A.class", files, hasKey("A.class")); | |||
| assertThat("Result did not contain B.class", files, hasKey("B.class")); | |||
| assertThat("Result did not contain C.class", files, hasKey("C.class")); | |||
| assertThat("Result did not contain D.class", files, hasKey("D.class")); | |||
| assertThat("Result did not contain E.class", files, hasKey("E.class")); | |||
| } | |||
| /** | |||
| @@ -154,24 +119,18 @@ public class ClassFileSetTest { | |||
| */ | |||
| @Test | |||
| public void testMethodParamInner() { | |||
| Project p = buildRule.getProject(); | |||
| buildRule.executeTarget("testmethodparaminner"); | |||
| FileSet resultFileSet = p.getReference(RESULT_FILESET); | |||
| DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p); | |||
| Hashtable<String, String> files = new Hashtable<>(); | |||
| for (String scannedFile : scanner.getIncludedFiles()) { | |||
| files.put(scannedFile, scannedFile); | |||
| } | |||
| assertEquals("Classfileset did not pick up expected number of " | |||
| + "class files", 4, files.size()); | |||
| assertTrue("Result did not contain test" + File.separator + "Outer$Inner.class", | |||
| files.containsKey("test" + File.separator + "Outer$Inner.class")); | |||
| assertTrue("Result did not contain test" + File.separator + "Outer.class", | |||
| files.containsKey("test" + File.separator + "Outer.class")); | |||
| assertTrue("Result did not contain test" + File.separator + "ContainsOnlyInner.class", | |||
| files.containsKey("test" + File.separator + "ContainsOnlyInner.class")); | |||
| assertTrue("Result did not contain test" + File.separator + "ContainsOnlyInner.class", | |||
| files.containsKey("test" + File.separator + "MethodParam.class")); | |||
| Hashtable<String, String> files = getFiles(); | |||
| assertEquals("Classfileset did not pick up expected number of class files", | |||
| 4, files.size()); | |||
| assertThat("Result did not contain test" + File.separator + "Outer$Inner.class", | |||
| files, hasKey("test" + File.separator + "Outer$Inner.class")); | |||
| assertThat("Result did not contain test" + File.separator + "Outer.class", | |||
| files, hasKey("test" + File.separator + "Outer.class")); | |||
| assertThat("Result did not contain test" + File.separator + "ContainsOnlyInner.class", | |||
| files, hasKey("test" + File.separator + "ContainsOnlyInner.class")); | |||
| assertThat("Result did not contain test" + File.separator + "ContainsOnlyInner.class", | |||
| files, hasKey("test" + File.separator + "MethodParam.class")); | |||
| } | |||
| @Test | |||
| @@ -179,4 +138,11 @@ public class ClassFileSetTest { | |||
| buildRule.executeTarget("testresourcecollection"); | |||
| } | |||
| private Hashtable<String, String> getFiles() { | |||
| FileSet resultFileSet = buildRule.getProject().getReference(RESULT_FILESET); | |||
| DirectoryScanner scanner = resultFileSet.getDirectoryScanner(buildRule.getProject()); | |||
| String[] scannedFiles = scanner.getIncludedFiles(); | |||
| return Arrays.stream(scannedFiles) | |||
| .collect(Collectors.toMap(file -> file, file -> file, (a, b) -> b, Hashtable::new)); | |||
| } | |||
| } | |||
| @@ -24,11 +24,16 @@ import java.util.Map; | |||
| import org.junit.Test; | |||
| import static org.hamcrest.Matchers.hasKey; | |||
| import static org.hamcrest.Matchers.hasValue; | |||
| import static org.hamcrest.Matchers.instanceOf; | |||
| import static org.hamcrest.Matchers.not; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertFalse; | |||
| import static org.junit.Assert.assertNull; | |||
| import static org.junit.Assert.assertSame; | |||
| import static org.junit.Assert.assertThat; | |||
| import static org.junit.Assert.assertTrue; | |||
| import static org.junit.Assert.assertNull; | |||
| import static org.junit.Assert.assertEquals; | |||
| public class LinkedHashtableTest { | |||
| @@ -48,17 +53,17 @@ public class LinkedHashtableTest { | |||
| public void testClone() { | |||
| h.put(K1, V1); | |||
| Hashtable<Object, Object> h2 = (Hashtable<Object, Object>) h.clone(); | |||
| assertTrue(h2 instanceof LinkedHashtable); | |||
| assertTrue(h2.containsKey(K1)); | |||
| assertThat(h2, instanceOf(LinkedHashtable.class)); | |||
| assertThat(h2, hasKey(K1)); | |||
| } | |||
| @Test | |||
| public void testContainsAndPut() { | |||
| h.put(K1, V1); | |||
| assertTrue(h.contains(K1)); | |||
| assertTrue(h.containsKey(K1)); | |||
| assertTrue(h.containsValue(V1)); | |||
| assertFalse(h.containsKey(K2)); | |||
| assertThat(h, hasKey(K1)); | |||
| assertThat(h, hasValue(V1)); | |||
| assertThat(h, not(hasKey(K2))); | |||
| } | |||
| @Test | |||
| @@ -86,7 +91,7 @@ public class LinkedHashtableTest { | |||
| LinkedHashtable<Object, Object> h2 = new LinkedHashtable<>(); | |||
| h.put(K1, V1); | |||
| h2.putAll(h); | |||
| assertTrue(h2.containsKey(K1)); | |||
| assertThat(h2, hasKey(K1)); | |||
| } | |||
| @Test | |||
| @@ -23,10 +23,12 @@ import java.util.Arrays; | |||
| import org.junit.Test; | |||
| import static org.hamcrest.Matchers.instanceOf; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertFalse; | |||
| import static org.junit.Assert.assertSame; | |||
| import static org.junit.Assert.assertTrue; | |||
| import static org.junit.Assert.assertThat; | |||
| public class VectorSetTest { | |||
| @@ -78,7 +80,7 @@ public class VectorSetTest { | |||
| public void testClone() { | |||
| v.add(O); | |||
| Object o = v.clone(); | |||
| assertTrue(o instanceof VectorSet); | |||
| assertThat(o, instanceOf(VectorSet.class)); | |||
| VectorSet<Object> vs = (VectorSet<Object>) o; | |||
| assertEquals(1, vs.size()); | |||
| assertTrue(vs.contains(O)); | |||
| @@ -18,8 +18,9 @@ | |||
| package org.apache.tools.zip; | |||
| import static org.hamcrest.Matchers.instanceOf; | |||
| import static org.junit.Assert.assertEquals; | |||
| import static org.junit.Assert.assertTrue; | |||
| import static org.junit.Assert.assertThat; | |||
| import org.junit.Before; | |||
| import org.junit.Rule; | |||
| @@ -85,10 +86,10 @@ public class ExtraFieldUtilsTest implements UnixStat { | |||
| ZipExtraField[] ze = ExtraFieldUtils.parse(data); | |||
| assertEquals("number of fields", 2, ze.length); | |||
| assertTrue("type field 1", ze[0] instanceof AsiExtraField); | |||
| assertThat("type field 1", ze[0], instanceOf(AsiExtraField.class)); | |||
| assertEquals("mode field 1", 040755, | |||
| ((AsiExtraField) ze[0]).getMode()); | |||
| assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField); | |||
| assertThat("type field 2", ze[1], instanceOf(UnrecognizedExtraField.class)); | |||
| assertEquals("data length field 2", 1, | |||
| ze[1].getLocalFileDataLength().getValue()); | |||
| @@ -103,10 +104,10 @@ public class ExtraFieldUtilsTest implements UnixStat { | |||
| ExtraFieldUtils.parse(data, true, | |||
| ExtraFieldUtils.UnparseableExtraField.READ); | |||
| assertEquals("number of fields", 2, ze.length); | |||
| assertTrue("type field 1", ze[0] instanceof AsiExtraField); | |||
| assertThat("type field 1", ze[0], instanceOf(AsiExtraField.class)); | |||
| assertEquals("mode field 1", 040755, | |||
| ((AsiExtraField) ze[0]).getMode()); | |||
| assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField); | |||
| assertThat("type field 2", ze[1], instanceOf(UnrecognizedExtraField.class)); | |||
| assertEquals("data length field 2", 1, | |||
| ze[1].getLocalFileDataLength().getValue()); | |||
| @@ -115,10 +116,10 @@ public class ExtraFieldUtilsTest implements UnixStat { | |||
| ze = ExtraFieldUtils.parse(data2, true, | |||
| ExtraFieldUtils.UnparseableExtraField.READ); | |||
| assertEquals("number of fields", 2, ze.length); | |||
| assertTrue("type field 1", ze[0] instanceof AsiExtraField); | |||
| assertThat("type field 1", ze[0], instanceOf(AsiExtraField.class)); | |||
| assertEquals("mode field 1", 040755, | |||
| ((AsiExtraField) ze[0]).getMode()); | |||
| assertTrue("type field 2", ze[1] instanceof UnparseableExtraFieldData); | |||
| assertThat("type field 2", ze[1], instanceOf(UnparseableExtraFieldData.class)); | |||
| assertEquals("data length field 2", 4, | |||
| ze[1].getLocalFileDataLength().getValue()); | |||
| for (int i = 0; i < 4; i++) { | |||
| @@ -134,10 +135,10 @@ public class ExtraFieldUtilsTest implements UnixStat { | |||
| ExtraFieldUtils.parse(data, true, | |||
| ExtraFieldUtils.UnparseableExtraField.SKIP); | |||
| assertEquals("number of fields", 2, ze.length); | |||
| assertTrue("type field 1", ze[0] instanceof AsiExtraField); | |||
| assertThat("type field 1", ze[0], instanceOf(AsiExtraField.class)); | |||
| assertEquals("mode field 1", 040755, | |||
| ((AsiExtraField) ze[0]).getMode()); | |||
| assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField); | |||
| assertThat("type field 2", ze[1], instanceOf(UnrecognizedExtraField.class)); | |||
| assertEquals("data length field 2", 1, | |||
| ze[1].getLocalFileDataLength().getValue()); | |||
| @@ -146,7 +147,7 @@ public class ExtraFieldUtilsTest implements UnixStat { | |||
| ze = ExtraFieldUtils.parse(data2, true, | |||
| ExtraFieldUtils.UnparseableExtraField.SKIP); | |||
| assertEquals("number of fields", 1, ze.length); | |||
| assertTrue("type field 1", ze[0] instanceof AsiExtraField); | |||
| assertThat("type field 1", ze[0], instanceOf(AsiExtraField.class)); | |||
| assertEquals("mode field 1", 040755, | |||
| ((AsiExtraField) ze[0]).getMode()); | |||
| } | |||