Skip to content

Commit

Permalink
Merge pull request #128 from olibye/master
Browse files Browse the repository at this point in the history
Fix Synchroniser issue #121 and ByteBudderImposteriser ClassLoader issue #127
  • Loading branch information
olibye committed May 18, 2019
2 parents a6a9d32 + 706db90 commit 29efca3
Show file tree
Hide file tree
Showing 28 changed files with 74 additions and 55 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
@@ -1,15 +1,17 @@
language: java

jdk:
# - openjdk-ea
- openjdk-ea
- openjdk11
# - oraclejdk11
- oraclejdk11
- openjdk10
# - oraclejdk10
- openjdk9
- oraclejdk8
# - openjdk7 #oracle not supported anymore
# - openjdk6 not supported any more
- oraclejdk8 #not supported

matrix:
allow_failures:
- jdk: openjdk-ea

env:
# Travis has slow VMs?
Expand Down
6 changes: 3 additions & 3 deletions jmock-example/pom.xml
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.11.0</version>
<version>2.12.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -47,12 +47,12 @@
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit3</artifactId>
<version>2.11.0</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<version>2.11.0</version>
<version>${project.version}</version>
</dependency>
</dependencies>

Expand Down
10 changes: 5 additions & 5 deletions jmock-imposters-tests/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.11.0</version>
<version>2.12.0-SNAPSHOT</version>
</parent>
<artifactId>jmock-imposters-tests</artifactId>

Expand All @@ -15,23 +15,23 @@
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>2.11.0</version>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<version>2.11.0</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit5</artifactId>
<version>2.11.0</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-testjar</artifactId>
<version>2.11.0</version>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

Expand Down
Expand Up @@ -2,13 +2,16 @@

import java.io.File;

import javax.sql.DataSource;

import org.jmock.api.Imposteriser;
import org.jmock.imposters.ByteBuddyClassImposteriser;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.junit5.JUnit5Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.jmock.test.acceptance.AbstractImposteriserParameterResolver;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;

Expand All @@ -20,8 +23,10 @@
* @see https://github.com/cglib/cglib/issues/20
*
*/
public class Java8Issue79UnitTest {
public final JUnit4Mockery context = new JUnit4Mockery();
public class Issue79And127UnitTest {

@RegisterExtension
public final JUnit5Mockery context = new JUnit5Mockery();

/**
* However it fails in java 11 as asm and cglib do not appear to support java
Expand All @@ -45,6 +50,7 @@ public void testMock(Imposteriser imposteriserImpl) {
public void testByteBuddyImposteriser(Imposteriser imposteriserImpl) {
context.setImposteriser(imposteriserImpl);
context.mock(File.class);
context.mock(DataSource.class);
}

public static class ByteBuddyImposteriserParameterResolver extends AbstractImposteriserParameterResolver {
Expand Down
2 changes: 1 addition & 1 deletion jmock-imposters/pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.11.0</version>
<version>2.12.0-SNAPSHOT</version>
</parent>
<artifactId>jmock-imposters</artifactId>
<description>Class mocks are more numerous than interface mocks, so drop the legacy name</description>
Expand Down
Expand Up @@ -152,7 +152,8 @@ public Object invoke(Object receiver, Method method, Object[] args) throws Throw
// https://mydailyjava.blogspot.com/2018/04/jdk-11-and-proxies-in-world-past.html
ClassLoadingStrategy<ClassLoader> strategy;
if (ClassInjector.UsingLookup.isAvailable() && !protectedPackageNameSpaces(mockedType)
&& !defaultPackage(mockedType)) {
&& !defaultPackage(mockedType)
&& mockedType.getClassLoader() == this.getClass().getClassLoader()) {
Class<?> methodHandles = Class.forName("java.lang.invoke.MethodHandles");
Object lookup = methodHandles.getMethod("lookup").invoke(null);
Method privateLookupIn = methodHandles.getMethod("privateLookupIn",
Expand Down
2 changes: 1 addition & 1 deletion jmock-junit3/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.11.0</version>
<version>2.12.0-SNAPSHOT</version>
</parent>

<artifactId>jmock-junit3</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion jmock-junit4/pom.xml
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.11.0</version>
<version>2.12.0-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Expand Up @@ -22,7 +22,8 @@ public interface Events {
}

Synchroniser synchroniser = new Synchroniser();


// Not a rule, to allow checking the mockery is *not* satisfied
Mockery mockery = new JUnit4Mockery() {{
setThreadingPolicy(synchroniser);
}};
Expand All @@ -42,7 +43,7 @@ public void run() {
mockObject.action();
}
});

mockery.assertIsSatisfied();
}

Expand Down Expand Up @@ -70,6 +71,7 @@ public void run() {
});

synchroniser.waitUntil(threads.is("finished"));
mockery.assertIsSatisfied();
}

@Test(timeout=250)
Expand All @@ -96,6 +98,7 @@ public void run() {
});

synchroniser.waitUntil(threads.is("finished"), 100);
mockery.assertIsSatisfied();
}

@Test(timeout=250)
Expand Down
2 changes: 1 addition & 1 deletion jmock-junit5/pom.xml
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.11.0</version>
<version>2.12.0-SNAPSHOT</version>
</parent>

<properties>
Expand Down
@@ -1,15 +1,20 @@
package org.jmock.junit5.acceptance;

import org.jmock.junit5.testdata.DerivedJUnit5TestThatDoesNotSatisfyExpectations;
import org.jmock.junit5.testdata.JUnit5TestThatAutoInstantiatesMocks;
import org.jmock.junit5.testdata.JUnit5TestThatCreatesNoMockery;
import org.jmock.junit5.testdata.JUnit5TestThatCreatesTwoMockeries;
import org.jmock.junit5.testdata.JUnit5TestThatDoesNotCreateAMockery;
import org.jmock.junit5.testdata.JUnit5TestThatDoesNotSatisfyExpectations;
import org.jmock.junit5.testdata.JUnit5TestThatDoesSatisfyExpectations;
import org.jmock.junit5.testdata.JUnit5TestThatThrowsExpectedException;
import org.jmock.junit5.testdata.jmock.acceptance.DerivedJUnit5TestThatDoesNotSatisfyExpectations;
import org.jmock.junit5.testdata.jmock.acceptance.JUnit5TestThatAutoInstantiatesMocks;
import org.jmock.junit5.testdata.jmock.acceptance.JUnit5TestThatCreatesNoMockery;
import org.jmock.junit5.testdata.jmock.acceptance.JUnit5TestThatCreatesTwoMockeries;
import org.jmock.junit5.testdata.jmock.acceptance.JUnit5TestThatDoesNotCreateAMockery;
import org.jmock.junit5.testdata.jmock.acceptance.JUnit5TestThatDoesNotSatisfyExpectations;
import org.jmock.junit5.testdata.jmock.acceptance.JUnit5TestThatDoesSatisfyExpectations;
import org.jmock.junit5.testdata.jmock.acceptance.JUnit5TestThatThrowsExpectedException;
import org.junit.jupiter.api.Test;

/**
* Wrap, running "testdata" testcases. Some of which are supposed to fail
* @author oliverbye
*
*/
public class JUnit5TestRunnerTests {

FailureRecordingTestExecutionListener listener = new FailureRecordingTestExecutionListener();
Expand Down
@@ -1,6 +1,6 @@
package org.jmock.junit5.acceptance;

import org.jmock.junit5.testdata.JUnit5WithRulesExamples;
import org.jmock.junit5.testdata.jmock.acceptance.JUnit5WithRulesExamples;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionConfigurationException;

Expand Down
@@ -1,4 +1,4 @@
package org.jmock.junit5.testdata;
package org.jmock.junit5.testdata.jmock.acceptance;

import org.jmock.junit5.JUnit5Mockery;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down
@@ -1,4 +1,4 @@
package org.jmock.junit5.testdata;
package org.jmock.junit5.testdata.jmock.acceptance;

import org.jmock.Expectations;
import org.jmock.auto.Mock;
Expand Down
@@ -1,4 +1,4 @@
package org.jmock.junit5.testdata;
package org.jmock.junit5.testdata.jmock.acceptance;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
Expand Down
@@ -1,4 +1,4 @@
package org.jmock.junit5.testdata;
package org.jmock.junit5.testdata.jmock.acceptance;

import org.jmock.junit5.JUnit5Mockery;
import org.junit.jupiter.api.Test;
Expand Down
@@ -1,4 +1,4 @@
package org.jmock.junit5.testdata;
package org.jmock.junit5.testdata.jmock.acceptance;

import org.jmock.junit5.JUnit5Mockery;
import org.junit.jupiter.api.Test;
Expand Down
@@ -1,4 +1,4 @@
package org.jmock.junit5.testdata;
package org.jmock.junit5.testdata.jmock.acceptance;

import org.jmock.junit5.JUnit5Mockery;
import org.junit.jupiter.api.Test;
Expand Down
@@ -1,4 +1,4 @@
package org.jmock.junit5.testdata;
package org.jmock.junit5.testdata.jmock.acceptance;

import org.jmock.Expectations;
import org.jmock.auto.Mock;
Expand Down
@@ -1,4 +1,4 @@
package org.jmock.junit5.testdata;
package org.jmock.junit5.testdata.jmock.acceptance;

import org.jmock.Expectations;
import org.jmock.auto.Mock;
Expand Down
@@ -1,4 +1,4 @@
package org.jmock.junit5.testdata;
package org.jmock.junit5.testdata.jmock.acceptance;

import org.jmock.Expectations;
import org.jmock.junit5.JUnit5Mockery;
Expand Down
@@ -1,4 +1,4 @@
package org.jmock.junit5.testdata;
package org.jmock.junit5.testdata.jmock.acceptance;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
Expand Down
Expand Up @@ -14,7 +14,6 @@
import org.jmock.lib.concurrent.Synchroniser;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class SynchroniserTests {
public interface Events {
Expand All @@ -23,7 +22,8 @@ public interface Events {
}

Synchroniser synchroniser = new Synchroniser();
@RegisterExtension

// Not an extension, to allow checking the mockery is *not* satisfied
JUnit5Mockery mockery = new JUnit5Mockery() {{
setThreadingPolicy(synchroniser);
}};
Expand Down Expand Up @@ -73,6 +73,7 @@ public void run() {
});

synchroniser.waitUntil(threads.is("finished"));
mockery.assertIsSatisfied();
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion jmock-legacy/pom.xml
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.11.0</version>
<version>2.12.0-SNAPSHOT</version>
</parent>

<properties>
Expand Down
6 changes: 3 additions & 3 deletions jmock/pom.xml
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.11.0</version>
<version>2.12.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -58,7 +58,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<version>3.1.2</version>
<executions>
<execution>
<goals>
Expand All @@ -71,7 +71,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<version>1.6.0</version>
<executions>
<execution>
<phase>process-classes</phase>
Expand Down
3 changes: 2 additions & 1 deletion jmock/src/main/java/org/jmock/Mockery.java
Expand Up @@ -53,7 +53,7 @@ public class Mockery implements SelfDescribing {
private final Set<String> mockNames = new HashSet<String>();
private final ReturnDefaultValueAction defaultAction = new ReturnDefaultValueAction(imposteriser);
private final List<Invocation> actualInvocations = new ArrayList<Invocation>();
private final InvocationDispatcher dispatcher = threadingPolicy.dispatcher();
private InvocationDispatcher dispatcher = threadingPolicy.dispatcher();

private Error firstError = null;

Expand Down Expand Up @@ -126,6 +126,7 @@ public void setExpectationErrorTranslator(ExpectationErrorTranslator expectation
*/
public void setThreadingPolicy(ThreadingPolicy threadingPolicy) {
this.threadingPolicy = threadingPolicy;
this.dispatcher = threadingPolicy.dispatcher();
}

/*
Expand Down

0 comments on commit 29efca3

Please sign in to comment.