Skip to content

Commit

Permalink
Merge pull request #117 from jmock-developers/release-candidate
Browse files Browse the repository at this point in the history
2.10.0 Release Candidate JDK 11 Support
  • Loading branch information
olibye committed Nov 29, 2018
2 parents a374d8e + 1828975 commit ddce923
Show file tree
Hide file tree
Showing 74 changed files with 686 additions and 376 deletions.
84 changes: 56 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,62 @@
# JMock Library
[![Build Status](https://travis-ci.org/jmock-developers/jmock-library.svg?branch=jmock2)](https://travis-ci.org/jmock-developers/jmock-library)

[![Maven Central](https://img.shields.io/maven-central/v/org.jmock/jmock.svg?label=Maven%20Central)](https://mvnrepository.com/artifact/org.jmock)

# Maven
```xml
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-imposters</artifactId>
<version>2.10.0-RC3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit5</artifactId>
<version>2.10.0-RC3</version>
<scope>test</scope>
</dependency>
```
# Gradle
```
testCompile(
"junit:junit5:2.10.0",
"org.jmock:jmock-imposters:2.10.0-RC3"
"org.jmock:jmock-junit5:2.10.0-RC3"
)
```
# Recent Changes
## 2.10.0
* JUnit 5 Support
** Swao @Rule JUnit4Mockery for @RegisterExtension JMock5Mockery
### JUnit 5 Support
* Swap @Rule JUnit4Mockery for @RegisterExtension JMock5Mockery
* Assign to a non-private JMock5Mockery or JUnit5 won't use it

```java

import org.jmock.Expectations;
import org.jmock.junit5.JUnit5Mockery;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class JUnit5TestThatDoesSatisfyExpectations {
@RegisterExtension
JUnit5Mockery context = new JUnit5Mockery();
private Runnable runnable = context.mock(Runnable.class);

@Test
public void doesSatisfyExpectations() {
context.checking(new Expectations() {{
oneOf (runnable).run();
}});

runnable.run();
}
}
```
### JUnit 4 moved to provided scope in org.jmock:jmock
* This allows dependents to use other versions of junit or other test frameworks (e.g. junit 5)

* JUnit 4 moved to provided scope in org.jmock:jmock
** This allows dependents to use other versions of junit or other test frameworks (e.g. junit 5)
### Java7 Support will be dropped next release

## 2.9.0
* Dropped JDK 6 compliance.
Expand All @@ -19,7 +69,7 @@ We have had to make a breaking change to `with()`. Tests using `with(any(matcher

You should change

oneOf(mock).methodWithIntParams(with(any(Integer.class)));
oneOf(mock).methodWithIntParams(with(any(Integer.class)));

to the following

Expand All @@ -40,28 +90,6 @@ This is due to a compiler change in Java 1.7. The 2.6.0 release was compiled wit
of matchers in expectations.
* Expectations match in first-in, first-out order, so tests are easier to understand.



# How to get up and running

## Automatic Dependency Management

If you're using Gradle or Maven (and perhaps Ant), then it suffices to add to your build file the "integration JAR" for the test library that you want to use. For example: `jmock-junit4-2.8.2`.

For example, with Gradle:

```
testCompile(
"junit:junit:4.12",
"org.jmock:jmock-junit4:2.8.2"
)
```

## Hand-Rolled Dependencies

Add the `jmock-<version>.jar` to your classpath. (For example: `jmock-2.8.2.jar`.) Also add the integration JAR to your classpath for the test library ou're using. (For example: `jmock-junit4-2.8.2.jar`.) You also need `hamcrest-api-<version>.jar` and `hamcrest-lib-<version>.jar`.


# Package Structure

[jMock]() 2 is organised into published and internal packages. We guarantee backwards compatability of types in published packages within the same major version of jMock. There are no guarantees about backward compatability for types in internal packages.
Expand Down
105 changes: 57 additions & 48 deletions jmock-example/pom.xml
Original file line number Diff line number Diff line change
@@ -1,50 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.jmock</groupId>
<artifactId>jmock-example</artifactId>
<version>2.10.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>jMock Examples</name>

<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.10.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

</dependencies>

<build />
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<artifactId>jmock-example</artifactId>
<packaging>jar</packaging>
<name>jMock Examples</name>

<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.10.0-RC3</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit3</artifactId>
<version>2.10.0-RC3</version>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<version>2.10.0-RC3</version>
</dependency>
</dependencies>

</project>
57 changes: 57 additions & 0 deletions jmock-imposters-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.10.0-RC3</version>
</parent>
<artifactId>jmock-imposters-tests</artifactId>

<dependencies>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>2.10.0-RC3</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<version>2.10.0-RC3</version>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit5</artifactId>
<version>2.10.0-RC3</version>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-testjar</artifactId>
<version>2.10.0-RC3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

public class ClassLoaderAcceptanceTests {

final String UNSIGNED_JAR_NAME = "../testjar/target/unsigned.jar";
private static final String UNSIGNED_JAR_NAME = "../testjar/target/unsigned.jar";
private static final String CLASS_FROM_OTHER_CLASS_LOADER = "org.jmock.testjar.ClassFromOtherClassLoader";
private static final String INTERFACE_FROM_OTHER_CLASS_LOADER = "org.jmock.testjar.InterfaceFromOtherClassLoader";

Mockery mockery = new Mockery();
ClassLoader classLoader;

Expand All @@ -38,14 +41,14 @@ public void setUp() throws MalformedURLException, URISyntaxException {
@ArgumentsSource(ImposteriserParameterResolver.class)
public void testMockingInterfaceFromOtherClassLoaderWithClassImposteriser(Imposteriser imposteriserImpl) throws ClassNotFoundException {
mockery.setImposteriser(imposteriserImpl);
mockery.mock(classLoader.loadClass("InterfaceFromOtherClassLoader"));
mockery.mock(classLoader.loadClass(INTERFACE_FROM_OTHER_CLASS_LOADER));
}

@ParameterizedTest
@ArgumentsSource(CodeGeneratingImposteriserParameterResolver.class)
public void testMockingClassFromOtherClassLoaderWithClassImposteriser(Imposteriser imposteriserImpl) throws ClassNotFoundException {
mockery.setImposteriser(imposteriserImpl);
mockery.mock(classLoader.loadClass("ClassFromOtherClassLoader"));
mockery.mock(classLoader.loadClass(CLASS_FROM_OTHER_CLASS_LOADER));
}

// I've been unable to reproduce the behaviour of the Maven Surefire plugin in plain JUnit tests
Expand All @@ -56,7 +59,7 @@ public void testMockingClassFromThreadContextClassLoader(final Imposteriser impo
Runnable task = new Runnable() {
public void run() {
try {
Class<?> classToMock = Thread.currentThread().getContextClassLoader().loadClass("ClassFromOtherClassLoader");
Class<?> classToMock = Thread.currentThread().getContextClassLoader().loadClass(CLASS_FROM_OTHER_CLASS_LOADER);

Mockery threadMockery = new Mockery();
threadMockery.setImposteriser(imposteriserImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.jmock.Mockery;
import org.jmock.api.Imposteriser;
import org.jmock.test.unit.lib.legacy.CodeGeneratingImposteriserParameterResolver;
import org.jmock.test.unit.lib.legacy.ImposteriserParameterResolver;
import org.jmock.testjar.InterfaceFromOtherClassLoader;
import org.junit.Assert;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;

Expand Down Expand Up @@ -41,4 +44,13 @@ public void testCanMockClassesWithMethodsThatReturnFinalClasses(Imposteriser imp

assertSame(result, mock.returnInstanceOfFinalClass());
}

@SuppressWarnings("rawtypes")
@ParameterizedTest
@ArgumentsSource(ImposteriserParameterResolver.class)
public void testMockClassIsCached(Imposteriser imposteriserImpl) {
Class class1 = context.mock(InterfaceFromOtherClassLoader.class,"1").getClass();
Class class2 = context.mock(InterfaceFromOtherClassLoader.class,"2").getClass();
Assert.assertEquals("Type should be cached", class1, class2);
}
}

0 comments on commit ddce923

Please sign in to comment.