You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2019/01/16 16:40:25 UTC

[brooklyn-server] 13/31: Extract newMockBundle() utility methods to BundleTestUtil

This is an automated email from the ASF dual-hosted git repository.

aledsage pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit 0ec04184d60ea00ecd0f4cea2d8faac2529dae93
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Mon Oct 22 14:20:45 2018 +0100

    Extract newMockBundle() utility methods to BundleTestUtil
---
 .../brooklyn/core/typereg/BundleTestUtil.java      | 39 ++++++++++++++++++++++
 .../core/typereg/BundleUpgradeParserTest.java      | 27 +--------------
 2 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
new file mode 100644
index 0000000..2a5c3d7
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
@@ -0,0 +1,39 @@
+package org.apache.brooklyn.core.typereg;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.brooklyn.util.osgi.VersionedName;
+import org.mockito.Mockito;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+
+class BundleTestUtil {
+
+    static Bundle newMockBundle(Map<String, String> rawHeaders) {
+        return newMockBundle(VersionedName.fromString("do.no.care:1.2.3"), rawHeaders);
+    }
+
+    static Bundle newMockBundle(VersionedName name) {
+        return newMockBundle(name, ImmutableMap.of());
+    }
+
+    static Bundle newMockBundle(VersionedName name, Map<String, String> rawHeaders) {
+        Dictionary<String, String> headers = new Hashtable<>(rawHeaders);
+        Bundle result;
+        try {
+            result = Mockito.mock(Bundle.class);
+        } catch (Exception e) {
+            throw new IllegalStateException("Java too old.  There is a bug in really early java 1.8.0 "
+                    + "that causes mocks to fail, and has probably caused this.", e);
+        }
+        Mockito.when(result.getHeaders()).thenReturn(headers);
+        Mockito.when(result.getSymbolicName()).thenReturn(name.getSymbolicName());
+        Mockito.when(result.getVersion()).thenReturn(Version.valueOf(name.getOsgiVersionString()));
+        return result;
+    }
+
+
+}
diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
index 8803294..1b437b3 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
@@ -18,14 +18,12 @@
  */
 package org.apache.brooklyn.core.typereg;
 
+import static org.apache.brooklyn.core.typereg.BundleTestUtil.newMockBundle;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
-import java.util.Dictionary;
-import java.util.Hashtable;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
@@ -401,29 +399,6 @@ public class BundleUpgradeParserTest {
         assertEquals(BundleUpgradeParser.stripQuotes("''"), "");
     }
     
-    private Bundle newMockBundle(Map<String, String> rawHeaders) {
-        return newMockBundle(VersionedName.fromString("do.no.care:1.2.3"), rawHeaders);
-    }
-
-    private Bundle newMockBundle(VersionedName name) {
-        return newMockBundle(name, ImmutableMap.of());
-    }
-    
-    private Bundle newMockBundle(VersionedName name, Map<String, String> rawHeaders) {
-        Dictionary<String, String> headers = new Hashtable<>(rawHeaders);
-        Bundle result;
-        try {
-            result = Mockito.mock(Bundle.class);
-        } catch (Exception e) {
-            throw new IllegalStateException("Java too old.  There is a bug in really early java 1.8.0 "
-                + "that causes mocks to fail, and has probably caused this.", e);
-        }
-        Mockito.when(result.getHeaders()).thenReturn(headers);
-        Mockito.when(result.getSymbolicName()).thenReturn(name.getSymbolicName());
-        Mockito.when(result.getVersion()).thenReturn(Version.valueOf(name.getOsgiVersionString()));
-        return result;
-    }
-
     private RegisteredType newMockRegisteredType(String symbolicName, String version) {
         RegisteredType result = Mockito.mock(RegisteredType.class);
         Mockito.when(result.getSymbolicName()).thenReturn(symbolicName);