[Title] Refactoring plugin util test for using setup class in other test class which...
authorho.namkoong <ho.namkoong@samsung.com>
Wed, 19 Sep 2012 14:25:07 +0000 (23:25 +0900)
committerho.namkoong <ho.namkoong@samsung.com>
Wed, 19 Sep 2012 14:25:07 +0000 (23:25 +0900)
[Type]
[Module]
[Priority]
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: I05c7477c82cc73bee0e05d743bbc429dd990e8a8

org.tizen.common/test/src/org/tizen/common/util/PluginUtilTest.java

index 245350f..5fccdcf 100644 (file)
@@ -47,38 +47,27 @@ import org.tizen.common.Surrogate;
  * 
  * @see PluginUtil
  */
+@SuppressWarnings("unchecked")
 public class PluginUtilTest {
 
     /**
      * mock up test extension point id
      */
-    private static final String TEST_EXT_ID = "test-ep";
+    public static String TEST_EXT_ID = "test-ep";
     
     /**
      * mock up test class id
      */
-    private static final String TEST_CLS_ID = "test-class";
+    public static String TEST_CLS_ID = "test-class";
     
-    @SuppressWarnings("unchecked")
-    @Before
-    public void setUp() throws Exception {
-        PluginUtil.platformSurrogate = mock(Surrogate.class);
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        PluginUtil.platformSurrogate = null;
-    }
-
     /**
-     * Test {@link PluginUtil#loadClasses(String)}
-     * 
-     * @throws Exception in case of failure in test
-     * 
-     * @see PluginUtil#loadClasses(String)
+     * mock up IConfigurationElement
      */
-    @Test
-    public void testLoadClasses() throws Exception {
+    public static IConfigurationElement config;
+    
+    @Before
+    public void setUp() {
+        PluginUtil.platformSurrogate = mock(Surrogate.class);
         
         final IExtensionRegistry registry = mock(IExtensionRegistry.class);
         when(PluginUtil.platformSurrogate.getAdapter()).thenReturn(registry);
@@ -92,11 +81,27 @@ public class PluginUtilTest {
         final IExtension ext = mock(IExtension.class);
         exts[0] = ext;
         
-        final IConfigurationElement config = mock(IConfigurationElement.class);
         final IConfigurationElement[] configs = new IConfigurationElement[1];
         when(ext.getConfigurationElements()).thenReturn(configs);
-        configs[0] = config;
         
+        config = mock(IConfigurationElement.class);
+        configs[0] = config;
+    }
+    
+    @After
+    public void tearDown() {
+        PluginUtil.platformSurrogate = null;
+    }
+
+    /**
+     * Test {@link PluginUtil#loadClasses(String)}
+     * 
+     * @throws Exception in case of failure in test
+     * 
+     * @see PluginUtil#loadClasses(String)
+     */
+    @Test
+    public void testLoadClasses() throws Exception {
         PluginUtil.loadClasses(TEST_EXT_ID);
         Mockito.verify(config).createExecutableExtension("class");
     }
@@ -110,24 +115,7 @@ public class PluginUtilTest {
      */
     @Test
     public void testLoadClass() throws Exception {
-        
-        final IExtensionRegistry registry = mock(IExtensionRegistry.class);
-        when(PluginUtil.platformSurrogate.getAdapter()).thenReturn(registry);
-        
-        final IExtensionPoint ep = mock(IExtensionPoint.class);
-        when(registry.getExtensionPoint(TEST_EXT_ID)).thenReturn(ep);
-        
-        IExtension[] exts = new IExtension[1];
-        when(ep.getExtensions()).thenReturn(exts);
-        
-        final IExtension ext = mock(IExtension.class);
-        exts[0] = ext;
-        
-        final IConfigurationElement config = mock(IConfigurationElement.class);
         when(config.getAttribute("id")).thenReturn(TEST_CLS_ID);
-        final IConfigurationElement[] configs = new IConfigurationElement[1];
-        when(ext.getConfigurationElements()).thenReturn(configs);
-        configs[0] = config;
         
         PluginUtil.loadClass(TEST_EXT_ID, TEST_CLS_ID);
         Mockito.verify(config).createExecutableExtension("class");