aboutsummaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/test/java/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'bundle-plugin/src/test/java/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.java')
-rw-r--r--bundle-plugin/src/test/java/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.java59
1 files changed, 17 insertions, 42 deletions
diff --git a/bundle-plugin/src/test/java/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.java b/bundle-plugin/src/test/java/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.java
index 8fba5983049..62ecd780d7e 100644
--- a/bundle-plugin/src/test/java/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.java
+++ b/bundle-plugin/src/test/java/com/yahoo/container/plugin/bundle/AnalyzeBundleTest.java
@@ -3,25 +3,17 @@ package com.yahoo.container.plugin.bundle;
import com.yahoo.container.plugin.osgi.ExportPackages;
import com.yahoo.container.plugin.osgi.ExportPackages.Export;
-import org.hamcrest.Description;
-import org.hamcrest.TypeSafeMatcher;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import java.io.File;
-import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
-import static com.yahoo.container.plugin.classanalysis.TestUtilities.throwableMessage;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.Matchers.startsWith;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
/**
* @author Tony Vaagenes
@@ -36,7 +28,7 @@ public class AnalyzeBundleTest {
public AnalyzeBundleTest() {
File notOsgi = new File(jarDir, "notAOsgiBundle.jar");
File simple = new File(jarDir, "simple1.jar");
- exports = AnalyzeBundle.exportedPackagesAggregated(Arrays.asList(notOsgi, simple));
+ exports = AnalyzeBundle.exportedPackagesAggregated(List.of(notOsgi, simple));
exportsByPackageName = ExportPackages.exportsByPackageName(this.exports);
}
@@ -46,45 +38,28 @@ public class AnalyzeBundleTest {
@Test
public void require_that_non_osgi_bundles_are_ignored() {
- assertThat(exportsByPackageName.keySet(), not(hasItem("com.yahoo.sample.exported.package.ignored")));
+ assertFalse(exportsByPackageName.containsKey("com.yahoo.sample.exported.package.ignored"));
}
@Test
public void require_that_exports_are_retrieved_from_manifest_in_jars() {
- assertThat(exportsByPackageName.keySet().size(), is(1));
- assertThat(exportsByPackageName.keySet(), hasItem("com.yahoo.sample.exported.package"));
+ assertEquals(1, exportsByPackageName.keySet().size());
+ assertTrue(exportsByPackageName.containsKey("com.yahoo.sample.exported.package"));
}
@Test
public void exported_class_names_can_be_retrieved() {
- assertThat(ExportPackages.packageNames(exports), is(new HashSet<>(exports.get(0).getPackageNames())));
+ assertEquals(ExportPackages.packageNames(exports), exports.get(0).getPackageNames().stream().collect(Collectors.toSet()));
}
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
@Test
public void require_that_invalid_exports_throws_exception() {
- exception.expect(Exception.class);
-
- exception.expectMessage(containsString("Invalid manifest in bundle"));
- exception.expectMessage(matchesPattern("Invalid manifest in bundle '.*errorExport.jar'"));
- exception.expectCause(throwableMessage(startsWith("Failed parsing Export-Package")));
-
- AnalyzeBundle.exportedPackages(jarFile("errorExport.jar"));
- }
-
- private TypeSafeMatcher<String> matchesPattern(String pattern) {
- return new TypeSafeMatcher<String>() {
- @Override
- protected boolean matchesSafely(String s) {
- return s.matches(pattern);
- }
-
- @Override
- public void describeTo(Description description) {
- description.appendText("expects String that matches the pattern ").appendValue(pattern);
- }
- };
+ try {
+ AnalyzeBundle.exportedPackages(jarFile("errorExport.jar"));
+ fail();
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().contains("Invalid manifest in bundle 'src/test/resources/jar/errorExport.jar'"));
+ assertTrue(e.getCause().getMessage(), e.getCause().getMessage().startsWith("Failed parsing Export-Package"));
+ }
}
}