From 50c9893cec970642a9b1ce627bf47e1edd5ce563 Mon Sep 17 00:00:00 2001 From: oliverbye Date: Tue, 30 Oct 2018 09:01:41 +0000 Subject: [PATCH] Update README with JUnit5 example --- README.md | 77 ++++++++++++------- ...JUnit5TestThatDoesSatisfyExpectations.java | 2 +- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 9b83853da..84fd363d3 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,55 @@ +# 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 + + org.jmock + jmock-junit5 + 2.10.0-SNAPSHOT + test + +``` +# Gradle +``` +testCompile( + "junit:junit5:2.10.0-SNAPSHOT", + "org.jmock:jmock-junit5:2.10.0-SNAPSHOT" +) +``` # 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. @@ -19,7 +62,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 @@ -40,28 +83,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-.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-.jar` and `hamcrest-lib-.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. diff --git a/jmock-junit5/src/test/java/org/jmock/junit5/testdata/JUnit5TestThatDoesSatisfyExpectations.java b/jmock-junit5/src/test/java/org/jmock/junit5/testdata/JUnit5TestThatDoesSatisfyExpectations.java index f18d0a149..ab0722ca3 100644 --- a/jmock-junit5/src/test/java/org/jmock/junit5/testdata/JUnit5TestThatDoesSatisfyExpectations.java +++ b/jmock-junit5/src/test/java/org/jmock/junit5/testdata/JUnit5TestThatDoesSatisfyExpectations.java @@ -7,7 +7,7 @@ public class JUnit5TestThatDoesSatisfyExpectations { @RegisterExtension - private JUnit5Mockery context = new JUnit5Mockery(); + JUnit5Mockery context = new JUnit5Mockery(); private Runnable runnable = context.mock(Runnable.class); @Test