Skip to content

Commit 4a61823

Browse files
Fix OSGi issues occurring since ByteBuddy was added (close #626)
1 parent 1ce4c19 commit 4a61823

4 files changed

Lines changed: 42 additions & 31 deletions

File tree

core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@
112112
<extensions>true</extensions>
113113
<configuration>
114114
<instructions>
115-
<Export-Package>org.easymock.internal.*;poweruser=true;mandatory:=poweruser,org.easymock,org.easymock.bytebuddy,org.easymock.asm</Export-Package>
116-
<Import-Package>org.easymock,org.easymock.internal;poweruser=true, org.easymock.bytebuddy,org.easymock.asm,org.objenesis;resolution:=optional</Import-Package>
115+
<Export-Package>org.easymock.*</Export-Package>
116+
<Import-Package>org.easymock.*,net.bytebuddy.*;resolution:=optional,org.objectweb.asm.*,org.objenesis;resolution:=optional</Import-Package>
117117
</instructions>
118118
</configuration>
119119
<executions>

test-osgi/src/test/java/org/easymock/itests/InterfaceOnlyTest.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@
1818
import org.easymock.MockType;
1919
import org.easymock.internal.MocksControl;
2020
import org.easymock.internal.matchers.Equals;
21-
import org.junit.Ignore;
2221
import org.junit.Test;
22+
import org.ops4j.pax.exam.Configuration;
23+
import org.ops4j.pax.exam.MavenUtils;
24+
import org.ops4j.pax.exam.Option;
2325

2426
import java.io.IOException;
2527
import java.util.ArrayList;
2628

2729
import static org.easymock.EasyMock.*;
2830
import static org.junit.Assert.*;
31+
import static org.ops4j.pax.exam.CoreOptions.bundle;
32+
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
33+
import static org.ops4j.pax.exam.CoreOptions.options;
2934

3035
/**
3136
* Test that we still can mock interfaces without ByteBuddy and Objenesis as
@@ -35,6 +40,15 @@
3540
*/
3641
public class InterfaceOnlyTest extends OsgiBaseTest {
3742

43+
@Configuration
44+
public Option[] config() {
45+
String version = MavenUtils.getArtifactVersion("org.easymock", "easymock");
46+
return options(
47+
bundle("file:../core/target/easymock-" + version + ".jar"),
48+
junitBundles()
49+
);
50+
}
51+
3852
@Test
3953
public void testCanMock() throws IOException {
4054
Appendable mock = mock(Appendable.class);
@@ -44,28 +58,24 @@ public void testCanMock() throws IOException {
4458
verifyAll();
4559
}
4660

47-
@Ignore("Doesn't work with pax-exam yet")
4861
@Test
4962
public void testCanUseMatchers() {
5063
new Equals(new Object());
5164
}
5265

53-
@Ignore("Doesn't work with pax-exam yet")
5466
@Test
5567
public void testCanUseInternal() {
5668
new MocksControl(MockType.DEFAULT);
5769
}
5870

59-
@Ignore("Doesn't work with pax-exam yet")
6071
@Test
6172
public void testCannotMock() {
73+
// Do not use assertThrows, Pax-exam doesn't like it
6274
try {
6375
mock(ArrayList.class);
6476
fail("Should throw an exception due to a NoClassDefFoundError");
65-
} catch (RuntimeException e) {
66-
assertEquals("Class mocking requires to have objenesis library in the classpath", e
67-
.getMessage());
68-
assertTrue(e.getCause() instanceof NoClassDefFoundError);
77+
} catch (NoClassDefFoundError e) {
78+
// a class from bytebuddy will be missing, no need to check which one
6979
}
7080
}
7181
}

test-osgi/src/test/java/org/easymock/itests/OsgiBaseTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
import org.easymock.EasyMockSupport;
1919
import org.junit.Test;
2020
import org.junit.runner.RunWith;
21-
import org.ops4j.pax.exam.Configuration;
22-
import org.ops4j.pax.exam.MavenUtils;
23-
import org.ops4j.pax.exam.Option;
2421
import org.ops4j.pax.exam.junit.PaxExam;
2522
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
2623
import org.ops4j.pax.exam.spi.reactors.PerMethod;
@@ -30,9 +27,6 @@
3027

3128
import javax.inject.Inject;
3229

33-
import static org.ops4j.pax.exam.CoreOptions.*;
34-
35-
3630
/**
3731
* @author Henri Tremblay
3832
*/
@@ -61,16 +55,6 @@ protected String getImplementationVersion(Class<?> c) {
6155
@Inject
6256
private BundleContext bundleContext;
6357

64-
@Configuration
65-
public Option[] config() {
66-
String version = MavenUtils.getArtifactVersion("org.easymock", "easymock");
67-
return options(
68-
bundle("file:../core/target/easymock-" + version + ".jar"),
69-
mavenBundle().groupId("org.objenesis").artifactId("objenesis").versionAsInProject(),
70-
junitBundles()
71-
);
72-
}
73-
7458
@Test
7559
public void testOsgiPlatformStarts() {
7660
System.out.println("Framework vendor: " + this.bundleContext.getProperty(Constants.FRAMEWORK_VENDOR));

test-osgi/src/test/java/org/easymock/itests/OsgiTest.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@
2020
import org.easymock.internal.matchers.Equals;
2121
import org.junit.Ignore;
2222
import org.junit.Test;
23+
import org.ops4j.pax.exam.Configuration;
24+
import org.ops4j.pax.exam.MavenUtils;
25+
import org.ops4j.pax.exam.Option;
2326

2427
import java.io.IOException;
2528
import java.util.ArrayList;
2629

2730
import static org.easymock.EasyMock.*;
2831
import static org.junit.Assert.assertEquals;
2932
import static org.junit.Assert.assertSame;
33+
import static org.ops4j.pax.exam.CoreOptions.bundle;
34+
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
35+
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
36+
import static org.ops4j.pax.exam.CoreOptions.options;
3037

3138
/**
3239
* Note: This is a JUnit 3 test because of the Spring OSGi test framework
@@ -39,6 +46,18 @@ public static abstract class A {
3946
public abstract void foo();
4047
}
4148

49+
@Configuration
50+
public Option[] config() {
51+
String version = MavenUtils.getArtifactVersion("org.easymock", "easymock");
52+
return options(
53+
bundle("file:../core/target/easymock-" + version + ".jar"),
54+
mavenBundle().groupId("org.objenesis").artifactId("objenesis").versionAsInProject(),
55+
mavenBundle().groupId("net.bytebuddy").artifactId("byte-buddy").versionAsInProject(),
56+
mavenBundle().groupId("org.ow2.asm").artifactId("asm").versionAsInProject(),
57+
junitBundles()
58+
);
59+
}
60+
4261
@Test
4362
public void testCanMock() throws IOException {
4463
Appendable mock = mock(Appendable.class);
@@ -48,13 +67,11 @@ public void testCanMock() throws IOException {
4867
verifyAll();
4968
}
5069

51-
@Ignore("Doesn't work with pax-exam yet")
5270
@Test
5371
public void testCanUseMatchers() {
5472
new Equals(new Object());
5573
}
5674

57-
@Ignore("Doesn't work with pax-exam yet")
5875
@Test
5976
public void testCanUseInternal() {
6077
new MocksControl(MockType.DEFAULT);
@@ -65,7 +82,7 @@ public void testCanUseInternal() {
6582
* this case, cglib creates the proxy in its own class loader. So I need to
6683
* test this case is working
6784
*/
68-
@Ignore("Fails with ByteBuddy and should be fixed")
85+
@Ignore("Doesn't work above Java 8 yet")
6986
@Test
7087
public void testCanMock_BootstrapClassLoader() {
7188
ArrayList<?> mock = mock(ArrayList.class);
@@ -78,7 +95,7 @@ public void testCanMock_BootstrapClassLoader() {
7895
/**
7996
* Normal case of a class in this class loader
8097
*/
81-
@Ignore("Fails with ByteBuddy and should be fixed")
98+
@Ignore("Doesn't work above Java 8 yet")
8299
@Test
83100
public void testCanMock_OtherClassLoader() {
84101
A mock = mock(A.class);
@@ -88,7 +105,7 @@ public void testCanMock_OtherClassLoader() {
88105
verifyAll();
89106
}
90107

91-
@Ignore("Fails with ByteBuddy and should be fixed")
108+
@Ignore("Doesn't work above Java 8 yet")
92109
@Test
93110
public void testCanPartialMock() {
94111
A mock = partialMockBuilder(A.class).withConstructor().addMockedMethod("foo").createMock();

0 commit comments

Comments
 (0)