Skip to content

Commit 25e8ba3

Browse files
committed
FELIX--5457 : Logger Support. Use Mockito instead of EasyMock
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1781365 13f79535-47bb-0310-9956-ffa450edef68
1 parent 0ee26b8 commit 25e8ba3

3 files changed

Lines changed: 27 additions & 38 deletions

File tree

osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/BundleComponentActivatorTest.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import java.util.Enumeration;
2525
import java.util.Vector;
2626

27-
import junit.framework.TestCase;
28-
29-
import org.easymock.EasyMock;
27+
import org.mockito.Mockito;
3028
import org.osgi.framework.Bundle;
3129

30+
import junit.framework.TestCase;
31+
3232
public class BundleComponentActivatorTest extends TestCase
3333
{
3434

@@ -83,14 +83,11 @@ public void test_findDescriptors_withNonWildcardLocation() throws MalformedURLEx
8383
final URL[] descriptors = new URL[]
8484
{ new URL( "file:foo.xml" ) };
8585
final Enumeration de = new Vector( Arrays.asList( descriptors ) ).elements();
86-
final Bundle bundle = ( Bundle ) EasyMock.createNiceMock( Bundle.class );
87-
EasyMock.expect( bundle.findEntries( "/some/location", "foo.xml", false ) ).andReturn( de );
86+
final Bundle bundle = Mockito.mock( Bundle.class );
87+
Mockito.when( bundle.findEntries( "/some/location", "foo.xml", false ) ).thenReturn( de );
8888

89-
EasyMock.replay( new Object[]
90-
{ bundle } );
9189
final URL[] urls = BundleComponentActivator.findDescriptors( bundle, "/some/location/foo.xml" );
92-
EasyMock.verify( new Object[]
93-
{ bundle } );
90+
Mockito.verify( bundle ).findEntries("/some/location", "foo.xml", false);
9491

9592
assertNotNull( "Descriptor array is not null", urls );
9693
assertEquals( "Descriptor length", 1, urls.length );
@@ -109,12 +106,11 @@ public void findDescriptors_withWildcardLocation( final String location,
109106
new URL( "file:foo2.xml" )
110107
};
111108
final Enumeration de = new Vector( Arrays.asList( urls ) ).elements();
112-
final Bundle bundle = (Bundle) EasyMock.createNiceMock( Bundle.class );
113-
EasyMock.expect( bundle.findEntries( path, filePattern, false ) ).andReturn( de );
109+
final Bundle bundle = Mockito.mock( Bundle.class );
110+
Mockito.when( bundle.findEntries( path, filePattern, false ) ).thenReturn( de );
114111

115-
EasyMock.replay( new Object[]{ bundle } );
116112
final URL[] actualUrls = BundleComponentActivator.findDescriptors( bundle, location );
117-
EasyMock.verify( new Object[]{ bundle } );
113+
Mockito.verify( bundle ).findEntries( path, filePattern, false );
118114

119115
assertNotNull( "Descriptor array is not null", actualUrls );
120116
assertEquals( "Descriptor length", urls.length, actualUrls.length );
@@ -154,12 +150,11 @@ public void test_findDescriptors_withWildcardLocation02()
154150
public void test_findDescriptors_withWildcardLocation_nullEnum()
155151
throws MalformedURLException
156152
{
157-
final Bundle bundle = (Bundle) EasyMock.createNiceMock( Bundle.class );
158-
EasyMock.expect( bundle.findEntries( "/", "*.xml", false ) ).andReturn( null );
153+
final Bundle bundle = Mockito.mock( Bundle.class );
154+
Mockito.when( bundle.findEntries( "/", "*.xml", false ) ).thenReturn( null );
159155

160-
EasyMock.replay( new Object[]{ bundle } );
161156
final URL[] actualUrls = BundleComponentActivator.findDescriptors( bundle, "*.xml" );
162-
EasyMock.verify( new Object[]{ bundle } );
157+
Mockito.verify( bundle).findEntries( "/", "*.xml", false );
163158

164159
assertNotNull( "Descriptor array is not null", actualUrls );
165160
assertEquals( "Descriptor length", 0, actualUrls.length );
@@ -173,12 +168,11 @@ public void test_findDescriptors_withWildcardLocation_nullEnum()
173168
public void test_findDescriptors_withWildcardLocation_emptyEnum()
174169
throws MalformedURLException
175170
{
176-
final Bundle bundle = (Bundle) EasyMock.createNiceMock( Bundle.class );
177-
EasyMock.expect( bundle.findEntries( "/", "*.xml", false ) ).andReturn( new Vector().elements() );
171+
final Bundle bundle = Mockito.mock( Bundle.class );
172+
Mockito.when( bundle.findEntries( "/", "*.xml", false ) ).thenReturn( new Vector().elements() );
178173

179-
EasyMock.replay( new Object[]{ bundle } );
180174
final URL[] actualUrls = BundleComponentActivator.findDescriptors( bundle, "*.xml" );
181-
EasyMock.verify( new Object[]{ bundle } );
175+
Mockito.verify( bundle ).findEntries( "/", "*.xml", false );
182176

183177
assertNotNull( "Descriptor array is not null", actualUrls );
184178
assertEquals( "Descriptor length", 0, actualUrls.length );

osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/AnnotationTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.util.List;
2626
import java.util.Map;
2727

28-
import org.easymock.EasyMock;
28+
import org.mockito.Mockito;
2929
import org.osgi.framework.Bundle;
3030

3131
import junit.framework.TestCase;
@@ -69,10 +69,9 @@ public enum E1 {a, b, c}
6969

7070
private Bundle mockBundle() throws ClassNotFoundException
7171
{
72-
Bundle b = EasyMock.createMock(Bundle.class);
73-
EasyMock.expect(b.loadClass(String.class.getName())).andReturn((Class) String.class).anyTimes();
74-
EasyMock.expect(b.loadClass(Integer.class.getName())).andReturn((Class) Integer.class).anyTimes();
75-
EasyMock.replay(b);
72+
Bundle b = Mockito.mock(Bundle.class);
73+
Mockito.when(b.loadClass(String.class.getName())).thenReturn((Class) String.class);
74+
Mockito.when(b.loadClass(Integer.class.getName())).thenReturn((Class) Integer.class);
7675
return b;
7776
}
7877

osgi-r7/scr/src/test/java/org/apache/felix/scr/impl/inject/BindMethodTest.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.apache.felix.scr.impl.manager.components2.T2;
3636
import org.apache.felix.scr.impl.metadata.ComponentMetadata;
3737
import org.apache.felix.scr.impl.metadata.DSVersion;
38-
import org.easymock.EasyMock;
38+
import org.mockito.Mockito;
3939
import org.osgi.framework.BundleContext;
4040
import org.osgi.framework.Constants;
4141
import org.osgi.framework.ServiceReference;
@@ -54,19 +54,15 @@ public class BindMethodTest extends TestCase
5454
@Override
5555
public void setUp()
5656
{
57-
m_serviceReference = EasyMock.createNiceMock( ServiceReference.class );
58-
m_serviceInstance = EasyMock.createNiceMock( FakeService.class );
59-
m_context = EasyMock.createNiceMock( BundleContext.class );
57+
m_serviceReference = Mockito.mock( ServiceReference.class );
58+
m_serviceInstance = Mockito.mock( FakeService.class );
59+
m_context = Mockito.mock( BundleContext.class );
6060

61-
EasyMock.expect( m_context.getService( m_serviceReference ) ).andReturn( m_serviceInstance )
62-
.anyTimes();
61+
Mockito.when( m_context.getService( m_serviceReference ) ).thenReturn( m_serviceInstance );
6362

64-
EasyMock.expect( m_serviceReference.getPropertyKeys() ).andReturn( new String[]
65-
{ Constants.SERVICE_ID } ).anyTimes();
66-
EasyMock.expect( m_serviceReference.getProperty( Constants.SERVICE_ID ) ).andReturn( "Fake Service" )
67-
.anyTimes();
68-
EasyMock.replay( new Object[]
69-
{ m_serviceReference, m_context } );
63+
Mockito.when( m_serviceReference.getPropertyKeys() ).thenReturn( new String[]
64+
{ Constants.SERVICE_ID } );
65+
Mockito.when( m_serviceReference.getProperty( Constants.SERVICE_ID ) ).thenReturn( "Fake Service" );
7066
}
7167

7268

0 commit comments

Comments
 (0)