[FELIX-3386] File install tests use deprecated EasyMock API

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1301199 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java b/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
index f457955..eb3737d 100644
--- a/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
+++ b/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
@@ -23,8 +23,8 @@
 import java.util.Hashtable;
 
 import junit.framework.TestCase;
-import org.easymock.ArgumentsMatcher;
-import org.easymock.MockControl;
+import org.easymock.EasyMock;
+import org.easymock.IArgumentMatcher;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.cm.Configuration;
@@ -35,32 +35,23 @@
  */
 public class ConfigInstallerTest extends TestCase {
 
-    MockControl mockBundleContextControl;
     BundleContext mockBundleContext;
-    MockControl mockBundleControl;
     Bundle mockBundle;
-    MockControl mockConfigurationAdminControl;
     ConfigurationAdmin mockConfigurationAdmin;
-    MockControl mockConfigurationControl;
     Configuration mockConfiguration;
 
     protected void setUp() throws Exception
     {
         super.setUp();
-        mockBundleContextControl = MockControl.createControl( BundleContext.class );
-        mockBundleContext = ( BundleContext ) mockBundleContextControl.getMock();
-        mockBundleControl = MockControl.createControl( Bundle.class );
-        mockBundle = ( Bundle ) mockBundleControl.getMock();
-        mockConfigurationAdminControl = MockControl.createControl( ConfigurationAdmin.class );
-        mockConfigurationAdmin = ( ConfigurationAdmin ) mockConfigurationAdminControl.getMock();
-        mockConfigurationControl = MockControl.createControl( Configuration.class );
-        mockConfiguration = ( Configuration ) mockConfigurationControl.getMock();
+        mockBundleContext = (BundleContext) EasyMock.createMock(BundleContext.class);
+        mockBundle = ( Bundle ) EasyMock.createMock(Bundle.class);
+        mockConfigurationAdmin = ( ConfigurationAdmin ) EasyMock.createMock(ConfigurationAdmin.class);
+        mockConfiguration = ( Configuration ) EasyMock.createMock(Configuration.class);
     }
 
 
     public void testParsePidWithoutFactoryPid()
     {
-        mockBundleContextControl.replay();
         ConfigInstaller ci = new ConfigInstaller(null, null, null);
 
         String path = "pid.cfg";
@@ -71,7 +62,6 @@
 
     public void testParsePidWithFactoryPid()
     {
-        mockBundleContextControl.replay();
         ConfigInstaller ci = new ConfigInstaller(null, null, null);
 
         String path = "factory-pid.cfg";
@@ -81,125 +71,97 @@
 
     public void testGetNewFactoryConfiguration() throws Exception
     {
-        mockConfigurationControl.replay();
-        mockConfigurationAdmin.listConfigurations( null );
-        mockConfigurationAdminControl.setMatcher( MockControl.ALWAYS_MATCHER );
-        mockConfigurationAdminControl.setReturnValue( null );
-        mockConfigurationAdmin.createFactoryConfiguration( "pid", null );
-        mockConfigurationAdminControl.setReturnValue( mockConfiguration );
-        mockConfigurationAdminControl.replay();
-        mockBundleContextControl.replay();
+        EasyMock.expect(mockConfigurationAdmin.listConfigurations((String) EasyMock.anyObject()))
+                    .andReturn(null);
+        EasyMock.expect(mockConfigurationAdmin.createFactoryConfiguration( "pid", null ))
+                    .andReturn(mockConfiguration);
+        EasyMock.replay(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
 
         ConfigInstaller ci = new ConfigInstaller( mockBundleContext, mockConfigurationAdmin, new FileInstall() );
 
         assertEquals( "Factory configuration retrieved", mockConfiguration, ci.getConfiguration( "pid-factoryPid.cfg", "pid", "factoryPid" ) );
 
-        mockConfigurationAdminControl.verify();
-        mockConfigurationControl.verify();
-        mockBundleContextControl.verify();
+        EasyMock.verify(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
     }
 
 
     public void testGetExistentFactoryConfiguration() throws Exception
     {
-        mockConfigurationControl.replay();
-        mockConfigurationAdmin.listConfigurations( null );
-        mockConfigurationAdminControl.setMatcher( MockControl.ALWAYS_MATCHER );
-        mockConfigurationAdminControl.setReturnValue( null );
-        mockConfigurationAdmin.createFactoryConfiguration( "pid", null );
-        mockConfigurationAdminControl.setReturnValue( mockConfiguration );
-        mockConfigurationAdminControl.replay();
-        mockBundleContextControl.replay();
+        EasyMock.expect(mockConfigurationAdmin.listConfigurations((String) EasyMock.anyObject()))
+                        .andReturn(null);
+        EasyMock.expect(mockConfigurationAdmin.createFactoryConfiguration( "pid", null ))
+                        .andReturn(mockConfiguration);
+        EasyMock.replay(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
 
         ConfigInstaller ci = new ConfigInstaller( mockBundleContext, mockConfigurationAdmin, new FileInstall() );
 
         assertEquals( "Factory configuration retrieved", mockConfiguration, ci.getConfiguration( "pid-factoryPid.cfg","pid", "factoryPid" ) );
 
-        mockConfigurationAdminControl.verify();
-        mockConfigurationControl.verify();
-        mockBundleContextControl.verify();
+        EasyMock.verify(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
     }
 
 
     public void testGetExistentNoFactoryConfiguration() throws Exception
     {
-        mockConfigurationControl.replay();
-        mockConfigurationAdmin.listConfigurations( null );
-        mockConfigurationAdminControl.setMatcher( MockControl.ALWAYS_MATCHER );
-        mockConfigurationAdminControl.setReturnValue( null );
-        mockConfigurationAdmin.getConfiguration( "pid", null );
-        mockConfigurationAdminControl.setReturnValue( mockConfiguration );
-        mockConfigurationAdminControl.replay();
-        mockBundleContextControl.replay();
+        EasyMock.expect(mockConfigurationAdmin.listConfigurations((String) EasyMock.anyObject()))
+                        .andReturn(null);
+        EasyMock.expect(mockConfigurationAdmin.getConfiguration( "pid", null ))
+                        .andReturn(mockConfiguration);
+        EasyMock.replay(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
 
         ConfigInstaller ci = new ConfigInstaller( mockBundleContext, mockConfigurationAdmin, new FileInstall() );
 
         assertEquals( "Factory configuration retrieved", mockConfiguration, ci.getConfiguration( "pid.cfg", "pid", null ) );
 
-        mockConfigurationAdminControl.verify();
-        mockConfigurationControl.verify();
-        mockBundleContextControl.verify();
+        EasyMock.verify(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
     }
 
 
     public void testDeleteConfig() throws Exception
     {
         mockConfiguration.delete();
-        mockConfigurationControl.replay();
-        mockConfigurationAdmin.listConfigurations( null );
-        mockConfigurationAdminControl.setMatcher( MockControl.ALWAYS_MATCHER );
-        mockConfigurationAdminControl.setReturnValue( null );
-        mockConfigurationAdmin.getConfiguration( "pid", null );
-        mockConfigurationAdminControl.setReturnValue( mockConfiguration );
-        mockConfigurationAdminControl.replay();
-        mockBundleContextControl.replay();
+        EasyMock.expect(mockConfigurationAdmin.listConfigurations((String) EasyMock.anyObject()))
+                        .andReturn(null);
+        EasyMock.expect(mockConfigurationAdmin.getConfiguration("pid", null ))
+                        .andReturn(mockConfiguration);
+        EasyMock.replay(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
 
         ConfigInstaller ci = new ConfigInstaller( mockBundleContext, mockConfigurationAdmin, new FileInstall() );
 
         assertTrue( ci.deleteConfig( new File( "pid.cfg" ) ) );
 
-        mockConfigurationAdminControl.verify();
-        mockConfigurationControl.verify();
-        mockBundleContextControl.verify();
+        EasyMock.verify(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
     }
 
 
     public void testSetConfiguration() throws Exception
     {
-        mockConfiguration.getBundleLocation();
-        mockConfigurationControl.setReturnValue( null );
-        mockConfiguration.getProperties();
-        mockConfigurationControl.setReturnValue( new Hashtable() );
-        mockConfiguration.update( new Hashtable() );
-        mockConfigurationControl.setMatcher( new ArgumentsMatcher()
+        EasyMock.expect(mockConfiguration.getBundleLocation()).andReturn(null);
+        EasyMock.expect(mockConfiguration.getProperties()).andReturn(new Hashtable());
+        EasyMock.reportMatcher(new IArgumentMatcher()
         {
-            public boolean matches( Object[] expected, Object[] actual )
+            public boolean matches( Object argument )
             {
-                return ( actual.length == 1 ) && ( (Dictionary) actual[0] ).get( "testkey" ).equals( "testvalue" );
+                return ((Dictionary) argument).get("testkey").equals("testvalue");
             }
 
-
-            public String toString( Object[] arg0 )
+            public void appendTo(StringBuffer buffer)
             {
-                return arg0.toString();
+                buffer.append("<Dictionary check: testkey present?>");
             }
         } );
-        mockConfigurationControl.replay();
-        mockConfigurationAdmin.listConfigurations( null );
-        mockConfigurationAdminControl.setMatcher( MockControl.ALWAYS_MATCHER );
-        mockConfigurationAdminControl.setReturnValue( null );
-        mockConfigurationAdmin.getConfiguration( "firstcfg", null );
-        mockConfigurationAdminControl.setReturnValue( mockConfiguration );
-        mockConfigurationAdminControl.replay();
-        mockBundleContextControl.replay();
+        mockConfiguration.update(new Hashtable());
+        EasyMock.expect(mockConfigurationAdmin.listConfigurations((String) EasyMock.anyObject()))
+                        .andReturn(null);
+        EasyMock.expect(mockConfigurationAdmin.getConfiguration("firstcfg", null))
+                        .andReturn(mockConfiguration);
+        EasyMock.replay(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
 
         ConfigInstaller ci = new ConfigInstaller( mockBundleContext, mockConfigurationAdmin, new FileInstall() );
 
         assertTrue( ci.setConfig( new File( "src/test/resources/watched/firstcfg.cfg" ) ) );
 
-        mockConfigurationAdminControl.verify();
-        mockConfigurationControl.verify();
-        mockBundleContextControl.verify();
+        EasyMock.verify(new Object[]{mockConfiguration, mockConfigurationAdmin, mockBundleContext});
     }
 
 
diff --git a/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java b/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
index 617c8fb..88c1f7c 100644
--- a/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
+++ b/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
@@ -24,11 +24,11 @@
 import java.util.Hashtable;
 
 import junit.framework.TestCase;
-
-import org.easymock.MockControl;
+import org.easymock.EasyMock;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleListener;
+import org.osgi.service.log.LogService;
 import org.osgi.service.packageadmin.PackageAdmin;
 
 
@@ -41,33 +41,34 @@
     private final static String TEST = "test.key";
     Dictionary props = new Hashtable();
     DirectoryWatcher dw;
-    MockControl mockBundleContextControl;
     BundleContext mockBundleContext;
-    MockControl mockPackageAdminControl;
     PackageAdmin mockPackageAdmin;
-    MockControl mockBundleControl;
     Bundle mockBundle;
 
 
     protected void setUp() throws Exception
     {
         super.setUp();
-        mockBundleContextControl = MockControl.createControl( BundleContext.class );
-        mockBundleContext = ( BundleContext ) mockBundleContextControl.getMock();
-        mockPackageAdminControl = MockControl.createControl( PackageAdmin.class );
-        mockPackageAdmin = ( PackageAdmin ) mockPackageAdminControl.getMock();
-        mockBundleControl = MockControl.createControl( Bundle.class );
-        mockBundle = ( Bundle ) mockBundleControl.getMock();
+        mockBundleContext = (BundleContext) EasyMock.createMock(BundleContext.class);
+        mockPackageAdmin = (PackageAdmin) EasyMock.createMock(PackageAdmin.class);
+        mockBundle = (Bundle) EasyMock.createMock(Bundle.class);
         props.put( DirectoryWatcher.DIR, new File( "target/load" ).getAbsolutePath() );
+
+        // Might get called, but most of the time it doesn't matter whether they do or don't.
+        EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.LOG_LEVEL))
+                        .andStubReturn(null);
+        EasyMock.expect(mockBundleContext.getServiceReference(LogService.class.getName()))
+                        .andStubReturn(null);
     }
 
 
     public void testGetLongWithNonExistentProperty()
     {
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContextControl.replay();
+        EasyMock.replay(new Object[]{mockBundleContext});
         dw = new DirectoryWatcher( props, mockBundleContext );
         assertEquals( "getLong gives the default value for non-existing properties", 100, dw.getLong( props, TEST, 100 ) );
+        EasyMock.verify(new Object[]{mockBundleContext});
     }
 
 
@@ -76,9 +77,10 @@
         props.put( TEST, "33" );
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContextControl.replay();
+        EasyMock.replay(new Object[]{mockBundleContext});
         dw = new DirectoryWatcher( props, mockBundleContext );
         assertEquals( "getLong retrieves the right property value", 33, dw.getLong( props, TEST, 100 ) );
+        EasyMock.verify(new Object[]{mockBundleContext});
     }
 
 
@@ -87,20 +89,20 @@
         props.put( TEST, "incorrect" );
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContext.getServiceReference( "org.osgi.service.log.LogService" );
-        mockBundleContextControl.setReturnValue( null );
-        mockBundleContextControl.replay();
+        EasyMock.replay(new Object[]{mockBundleContext});
         dw = new DirectoryWatcher( props, mockBundleContext );
         assertEquals( "getLong retrieves the right property value", 100, dw.getLong( props, TEST, 100 ) );
+        EasyMock.verify(new Object[]{mockBundleContext});
     }
 
 
     public void testGetBooleanWithNonExistentProperty()
     {
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContextControl.replay();
+        EasyMock.replay(new Object[]{mockBundleContext});
         dw = new DirectoryWatcher( props, mockBundleContext );
         assertEquals( "getBoolean gives the default value for non-existing properties", true, dw.getBoolean( props, TEST, true ) );
+        EasyMock.verify(new Object[]{mockBundleContext});
     }
 
 
@@ -109,9 +111,10 @@
         props.put( TEST, "true" );
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContextControl.replay();
+        EasyMock.replay(new Object[]{mockBundleContext});
         dw = new DirectoryWatcher( props, mockBundleContext );
         assertEquals( "getBoolean retrieves the right property value", true, dw.getBoolean( props, TEST, false ) );
+        EasyMock.verify(new Object[]{mockBundleContext});
     }
 
 
@@ -120,20 +123,20 @@
         props.put( TEST, "incorrect" );
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContext.getServiceReference( "org.osgi.service.log.LogService" );
-        mockBundleContextControl.setReturnValue( null );
-        mockBundleContextControl.replay();
+        EasyMock.replay(new Object[]{mockBundleContext});
         dw = new DirectoryWatcher( props, mockBundleContext );
         assertEquals( "getBoolean retrieves the right property value", false, dw.getBoolean( props, TEST, true ) );
+        EasyMock.verify(new Object[]{mockBundleContext});
     }
 
 
     public void testGetFileWithNonExistentProperty()
     {
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContextControl.replay();
+        EasyMock.replay(new Object[]{mockBundleContext});
         dw = new DirectoryWatcher( props, mockBundleContext );
         assertEquals( "getFile gives the default value for non-existing properties", new File("tmp"), dw.getFile( props, TEST, new File("tmp") ) );
+        EasyMock.verify(new Object[]{mockBundleContext});
     }
 
 
@@ -142,9 +145,10 @@
         props.put( TEST, "test" );
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContextControl.replay();
+        EasyMock.replay(new Object[]{mockBundleContext});
         dw = new DirectoryWatcher( props, mockBundleContext );
         assertEquals( "getBoolean retrieves the right property value", new File("test"), dw.getFile( props, TEST, new File("tmp") ) );
+        EasyMock.verify(new Object[]{mockBundleContext});
     }
 
 
@@ -158,7 +162,8 @@
         props.put( DirectoryWatcher.FILTER, ".*\\.cfg" );
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContextControl.replay();
+        EasyMock.replay(new Object[]{mockBundleContext});
+
         dw = new DirectoryWatcher( props, mockBundleContext );
 
         assertEquals( "POLL parameter correctly read", 500l, dw.poll );
@@ -169,6 +174,7 @@
             "src" + File.separatorChar + "test" + File.separatorChar + "resources" ) );
         assertEquals( "START_NEW_BUNDLES parameter correctly read", false, dw.startBundles );
         assertEquals( "FILTER parameter correctly read", ".*\\.cfg", dw.filter );
+        EasyMock.verify(new Object[]{mockBundleContext});
     }
 
 
@@ -177,7 +183,8 @@
         props.put( DirectoryWatcher.DIR, new File( "src/test/resources" ).getAbsolutePath() );
 
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContextControl.replay();
+        EasyMock.replay(new Object[]{mockBundleContext});
+
         dw = new DirectoryWatcher( props, mockBundleContext );
 
         assertTrue( "DIR parameter correctly read", dw.watchedDirectory.getAbsolutePath().endsWith(
@@ -188,28 +195,25 @@
                 new File(System.getProperty("java.io.tmpdir")).getAbsolutePath()) );
         assertEquals( "Default START_NEW_BUNDLES parameter correctly read", true, dw.startBundles );
         assertEquals( "Default FILTER parameter correctly read", null, dw.filter );
+        EasyMock.verify(new Object[]{mockBundleContext});
     }
 
 
     public void testIsFragment() throws Exception
     {
         mockBundleContext.addBundleListener((BundleListener) org.easymock.EasyMock.anyObject());
-        mockBundleContext.createFilter( "" );
-        mockBundleContextControl.setMatcher( MockControl.ALWAYS_MATCHER );
-        mockBundleContextControl.setReturnValue( null );
-        mockBundleContextControl.replay();
-        mockPackageAdmin.getBundleType( mockBundle );
-        mockPackageAdminControl.setReturnValue( new Long(PackageAdmin.BUNDLE_TYPE_FRAGMENT) );
-        mockPackageAdminControl.replay();
-        mockBundleControl.replay();
+        EasyMock.expect(mockBundleContext.createFilter((String) EasyMock.anyObject()))
+                        .andReturn(null);
+        EasyMock.expect(Long.valueOf(mockPackageAdmin.getBundleType(mockBundle)))
+                        .andReturn(new Long(PackageAdmin.BUNDLE_TYPE_FRAGMENT) );
+        EasyMock.replay(new Object[]{mockBundleContext, mockPackageAdmin, mockBundle});
 
         FileInstall.padmin = new MockServiceTracker( mockBundleContext, mockPackageAdmin );
         dw = new DirectoryWatcher( props, mockBundleContext );
 
         assertTrue( "Fragment type correctly retrieved from Package Admin service", dw.isFragment( mockBundle ) );
 
-        mockPackageAdminControl.verify();
-        mockBundleContextControl.verify();
+        EasyMock.verify(new Object[]{mockBundleContext});
     }