From 4c56b0aedb0284140ef94aa3db0531da7342c628 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Sun, 19 Dec 2021 19:19:28 +0100 Subject: Simplify testing by sticking to assertEquals/True/False --- .../com/yahoo/container/plugin/BundleTest.java | 30 ++++++++++------------ .../container/plugin/ExportPackageVersionTest.java | 15 +++++------ 2 files changed, 21 insertions(+), 24 deletions(-) (limited to 'bundle-plugin-test/integration-test') diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java index dbfac4e730f..faa33542f5c 100644 --- a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java +++ b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/BundleTest.java @@ -18,10 +18,8 @@ import java.util.jar.Manifest; import java.util.regex.Pattern; import java.util.zip.ZipEntry; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** @@ -35,7 +33,7 @@ public class BundleTest { // If bundle-plugin-test is compiled in a mvn command that also built dependencies, e.g. jrt, // the artifact is jrt.jar, otherwise the installed and versioned artifact // is used: jrt-7-SNAPSHOT.jar or e.g. jrt-7.123.45.jar. - private static String snapshotOrVersionOrNone = "(-\\d+((-SNAPSHOT)|((\\.\\d+(\\.\\d+)?)?))?)?\\.jar"; + private static final String snapshotOrVersionOrNone = "(-\\d+((-SNAPSHOT)|((\\.\\d+(\\.\\d+)?)?))?)?\\.jar"; private JarFile jarFile; private Attributes mainAttributes; @@ -67,12 +65,12 @@ public class BundleTest { // Because of snapshot builds, we can only verify the major version. int majorBundleVersion = Integer.valueOf(bundleVersion.substring(0, bundleVersion.indexOf('.'))); - assertThat(majorBundleVersion, is(VespaVersion.major)); + assertEquals(VespaVersion.major, majorBundleVersion); } @Test public void require_that_bundle_symbolic_name_matches_pom_artifactId() { - assertThat(mainAttributes.getValue("Bundle-SymbolicName"), is("main")); + assertEquals("main", mainAttributes.getValue("Bundle-SymbolicName")); } @Test @@ -80,29 +78,29 @@ public class BundleTest { String importPackage = mainAttributes.getValue("Import-Package"); // From SimpleSearcher - assertThat(importPackage, containsString("com.yahoo.prelude.hitfield")); + assertTrue(importPackage.contains("com.yahoo.prelude.hitfield")); // From SimpleSearcher2 - assertThat(importPackage, containsString("com.yahoo.processing")); - assertThat(importPackage, containsString("com.yahoo.metrics.simple")); - assertThat(importPackage, containsString("com.google.inject")); + assertTrue(importPackage.contains("com.yahoo.processing")); + assertTrue(importPackage.contains("com.yahoo.metrics.simple")); + assertTrue(importPackage.contains("com.google.inject")); } @Test public void require_that_manifest_contains_manual_imports() { String importPackage = mainAttributes.getValue("Import-Package"); - assertThat(importPackage, containsString("manualImport.withoutVersion")); - assertThat(importPackage, containsString("manualImport.withVersion;version=\"12.3.4\"")); + assertTrue(importPackage.contains("manualImport.withoutVersion")); + assertTrue(importPackage.contains("manualImport.withVersion;version=\"12.3.4\"")); for (int i=1; i<=2; ++i) - assertThat(importPackage, containsString("multiple.packages.with.the.same.version" + i + ";version=\"[1,2)\"")); + assertTrue(importPackage.contains("multiple.packages.with.the.same.version" + i + ";version=\"[1,2)\"")); } @Test public void require_that_manifest_contains_exports() { String exportPackage = mainAttributes.getValue("Export-Package"); - assertThat(exportPackage, containsString("com.yahoo.test;version=1.2.3.RELEASE")); + assertTrue(exportPackage.contains("com.yahoo.test;version=1.2.3.RELEASE")); } @Test @@ -110,7 +108,7 @@ public class BundleTest { // generated bundle. (It's compile scoped in pom.xml to be added to the bundle-cp.) public void require_that_manifest_contains_bundle_class_path() { String bundleClassPath = mainAttributes.getValue("Bundle-ClassPath"); - assertThat(bundleClassPath, containsString(".,")); + assertTrue(bundleClassPath.contains(".,")); Pattern jrtPattern = Pattern.compile("dependencies/jrt" + snapshotOrVersionOrNone); assertTrue("Bundle class path did not contain jrt.", jrtPattern.matcher(bundleClassPath).find()); @@ -139,7 +137,7 @@ public class BundleTest { @Test public void require_that_web_inf_url_is_propagated_to_the_manifest() { String webInfUrl = mainAttributes.getValue("WebInfUrl"); - assertThat(webInfUrl, containsString("/WEB-INF/web.xml")); + assertTrue(webInfUrl.contains("/WEB-INF/web.xml")); } } diff --git a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/ExportPackageVersionTest.java b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/ExportPackageVersionTest.java index 36d3faba81f..f99f1583324 100644 --- a/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/ExportPackageVersionTest.java +++ b/bundle-plugin-test/integration-test/src/test/java/com/yahoo/container/plugin/ExportPackageVersionTest.java @@ -10,9 +10,8 @@ import java.util.jar.Attributes; import java.util.jar.JarFile; import static com.yahoo.container.plugin.BundleTest.findBundleJar; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * Verifies that the 'useArtifactVersionForExportPackages' setting for the bundle-plugin works as intended. @@ -42,16 +41,16 @@ public class ExportPackageVersionTest { String expectedExport = "ai.vespa.noversion;version=" + bundleVersion; String exportPackage = mainAttributes.getValue("Export-Package"); - assertThat(exportPackage, containsString(expectedExport)); + assertTrue(exportPackage.contains(expectedExport)); // Verify that there is no qualifier - assertThat(exportPackage, not(containsString(expectedExport + "."))); + assertFalse(exportPackage.contains(expectedExport + ".")); } @Test public void explicit_version_in_ExportPackage_annotation_overrides_artifact_version() { String exportPackage = mainAttributes.getValue("Export-Package"); - assertThat(exportPackage, containsString("ai.vespa.explicitversion;version=2.4.6.RELEASE")); + assertTrue(exportPackage.contains("ai.vespa.explicitversion;version=2.4.6.RELEASE")); } @Test @@ -60,13 +59,13 @@ public class ExportPackageVersionTest { // TODO: This test should have checked for a fixed version of the dependency bundle, different than the main bundle version. // See comment in the dependency bundle's pom.xml for why this is not the case. - assertThat(exportPackage, containsString("ai.vespa.noversion_dep;version=" + bundleVersion)); + assertTrue(exportPackage.contains("ai.vespa.noversion_dep;version=" + bundleVersion)); } @Test public void explicit_version_in_ExportPackage_annotation_overrides_artifact_version_of_compile_scoped_dependency() { String exportPackage = mainAttributes.getValue("Export-Package"); - assertThat(exportPackage, containsString("ai.vespa.explicitversion_dep;version=3.6.9.RELEASE")); + assertTrue(exportPackage.contains("ai.vespa.explicitversion_dep;version=3.6.9.RELEASE")); } } -- cgit v1.2.3