Skip to content

Commit

Permalink
Merge pull request #107 from olibye/master
Browse files Browse the repository at this point in the history
Blocking alternative to non-blocking CopyOnWriteArrayList expectation strategy
  • Loading branch information
olibye authored May 23, 2018
2 parents bc7b531 + 0ff8243 commit 498d09a
Show file tree
Hide file tree
Showing 26 changed files with 368 additions and 200 deletions.
11 changes: 4 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ jdk:

env:
# Travis has slow VMs?
- blitzerThreads=1 blitzerActions=1 blitzerTimeout=1000

secure: "XBIyEF5RxH/zKjh0gle5ce/FRe9pP5b46LXKNOfwlau5QYvn8WXC41Sb6yYC8VW3vI9S930BnVGZONiDXsSWuylLezdu2g88nwJ2CsTxHU0Yg2GAzKwaorBQqyK/6w2foRRXtz69NJccfdIdPuDZSEhJtTKWSmMMQ7U65KH+zzQ="
secure: "SSlAKOg8QLEAkZX1ehy9c6FR5R6gMzLhc6u2Smq9tm8JsWVz4EtS6NnTQaosthrNEfLJwVVCfmOh2dzvYZfhtbKAUMdkox45tem4+LZfgkSaQAGjSvsC6geioa4Alo6AKyR8foc5Y7P34f9ujYSZHNyRG9F6E0Qq2zj/hzHhstU="

after_success:
- mvn deploy --settings settings.xml -DskipTests=true -B
global:
- blitzerThreads=1 blitzerActions=1 blitzerTimeout=1000
- secure: "XBIyEF5RxH/zKjh0gle5ce/FRe9pP5b46LXKNOfwlau5QYvn8WXC41Sb6yYC8VW3vI9S930BnVGZONiDXsSWuylLezdu2g88nwJ2CsTxHU0Yg2GAzKwaorBQqyK/6w2foRRXtz69NJccfdIdPuDZSEhJtTKWSmMMQ7U65KH+zzQ="
- secure: "SSlAKOg8QLEAkZX1ehy9c6FR5R6gMzLhc6u2Smq9tm8JsWVz4EtS6NnTQaosthrNEfLJwVVCfmOh2dzvYZfhtbKAUMdkox45tem4+LZfgkSaQAGjSvsC6geioa4Alo6AKyR8foc5Y7P34f9ujYSZHNyRG9F6E0Qq2zj/hzHhstU="
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[![Build Status](https://travis-ci.org/jmock-developers/jmock-library.svg?branch=jmock2)](https://travis-ci.org/jmock-developers/jmock-library)

# Recent Changes
## 2.9.0
* Dropped JDK 6 compliance.
* Exposed the InvocationDispatcher so that ThreadingPolicies

Upgrading to 2.8.X
==================
## Upgrading to 2.8.X
Are you seeing NPEs?

We have had to make a breaking change to `with()`. Tests using `with(any(matcher))` for method signatures that require native types will throw `NullPointerException`.
Expand All @@ -17,8 +20,7 @@ to the following
This is due to a compiler change in Java 1.7. The 2.6.0 release was compiled with Java 1.6 so it did not suffer this problem.


Advantages of jMock 2 over jMock 1
==================================
# Advantages of jMock 2 over jMock 1
* Uses real method calls, not strings, so you can refactor more easily and
autocomplete in the IDE.
* Customisation by delegation, not by inheritance.
Expand All @@ -33,8 +35,7 @@ Advantages of jMock 2 over jMock 1



How to get up and running
=========================
# How to get up and running

## Automatic Dependency Management

Expand All @@ -54,16 +55,14 @@ testCompile(
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
=================
# 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.

Types defined in published packages may themselves define public methods that accept or return types from internal packages or inherit methods from types in internal packages. Such methods have no compatability guarantees and should not be considered as part of the published interface.


Published packages
------------------
## Published packages

### org.jmock

Expand All @@ -80,16 +79,14 @@ Convenient classes that implement the APIs in the core, are used by the DSL-sty
Classes integrating jMock with different testing APIs, such as JUnit 3.x, JUnit 4.x and TestNG.


Packages of example code
------------------------
## Packages of example code

### org.jmock.lib.nonstd

Lib classes that rely on clever hacks or otherwise cannot be guaranteed to always work in all JVMs. There are no compatability guarantees with these classes. Use at your own risk.


Internal packages
-----------------
## Internal packages

### org.jmock.internal

Expand All @@ -100,8 +97,7 @@ Internal implementation details
Tests for jMock itself


Plug-in Points
==============
## Plug-in Points

### Matcher

Expand Down
4 changes: 2 additions & 2 deletions jmock-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

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

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

Expand Down
2 changes: 1 addition & 1 deletion jmock-junit3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.8.4</version>
<version>2.9.0-SNAPSHOT</version>
</parent>

<artifactId>jmock-junit3</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion jmock-junit4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.8.4</version>
<version>2.9.0-SNAPSHOT</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion jmock-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.8.4</version>
<version>2.9.0-SNAPSHOT</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion jmock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.jmock</groupId>
<artifactId>jmock-parent</artifactId>
<version>2.8.4</version>
<version>2.9.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
1 change: 1 addition & 0 deletions jmock/src/main/java/org/jmock/AbstractExpectations.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.hamcrest.Matcher;
import org.hamcrest.core.*;
import org.jmock.api.Action;
import org.jmock.api.ExpectationCollector;
import org.jmock.internal.*;
import org.jmock.lib.action.*;
import org.jmock.syntax.*;
Expand Down
2 changes: 0 additions & 2 deletions jmock/src/main/java/org/jmock/ExpectationsCreator.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jmock;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -10,7 +9,6 @@
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

Expand Down
34 changes: 25 additions & 9 deletions jmock/src/main/java/org/jmock/Mockery.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
package org.jmock;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.hamcrest.Description;
import org.hamcrest.SelfDescribing;
import org.jmock.api.*;
import org.jmock.internal.*;
import org.jmock.api.Expectation;
import org.jmock.api.ExpectationError;
import org.jmock.api.ExpectationErrorTranslator;
import org.jmock.api.Imposteriser;
import org.jmock.api.Invocation;
import org.jmock.api.InvocationDispatcher;
import org.jmock.api.Invokable;
import org.jmock.api.MockObjectNamingScheme;
import org.jmock.api.ThreadingPolicy;
import org.jmock.internal.CaptureControl;
import org.jmock.internal.ExpectationBuilder;
import org.jmock.internal.ExpectationCapture;
import org.jmock.internal.InvocationDiverter;
import org.jmock.internal.InvocationToExpectationTranslator;
import org.jmock.internal.NamedSequence;
import org.jmock.internal.ObjectMethodExpectationBouncer;
import org.jmock.internal.ProxiedObjectIdentity;
import org.jmock.internal.ReturnDefaultValueAction;
import org.jmock.internal.SingleThreadedPolicy;
import org.jmock.lib.CamelCaseNamingScheme;
import org.jmock.lib.IdentityExpectationErrorTranslator;
import org.jmock.lib.JavaReflectionImposteriser;
import org.jmock.lib.concurrent.Synchroniser;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;


/**
* A Mockery represents the context, or neighbourhood, of the object(s) under test.
Expand All @@ -37,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 = new InvocationDispatcher(new CopyOnWriteArrayList(), new CopyOnWriteArrayList());
private final InvocationDispatcher dispatcher = threadingPolicy.dispatcher();

private Error firstError = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package org.jmock.internal;

import org.jmock.api.Expectation;
package org.jmock.api;

public interface ExpectationCollector {
void add(Expectation expectation);
Expand Down
20 changes: 20 additions & 0 deletions jmock/src/main/java/org/jmock/api/InvocationDispatcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jmock.api;

import org.hamcrest.Description;
import org.hamcrest.SelfDescribing;
import org.jmock.internal.StateMachine;

public interface InvocationDispatcher extends SelfDescribing, ExpectationCollector {

StateMachine newStateMachine(String name);

void add(Expectation expectation);

void describeTo(Description description);

void describeMismatch(Invocation invocation, Description description);

boolean isSatisfied();

Object dispatch(Invocation invocation) throws Throwable;
}
4 changes: 2 additions & 2 deletions jmock/src/main/java/org/jmock/api/ThreadingPolicy.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jmock.api;

import org.jmock.internal.InvocationDispatcher;

public interface ThreadingPolicy {
Invokable synchroniseAccessTo(Invokable mockObject);

InvocationDispatcher dispatcher();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jmock.internal;

import org.jmock.api.Action;
import org.jmock.api.ExpectationCollector;

public interface ExpectationBuilder {
void buildExpectations(Action defaultAction, ExpectationCollector collector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.util.ConcurrentModificationException;

import org.jmock.api.Invocation;
import org.jmock.api.InvocationDispatcher;
import org.jmock.api.Invokable;
import org.jmock.api.ThreadingPolicy;
import org.jmock.lib.concurrent.Synchroniser;
import org.jmock.lib.concurrent.UnsynchronisedInvocationDispatcher;

public class SingleThreadedPolicy implements ThreadingPolicy {
private final Thread testThread;
Expand Down Expand Up @@ -34,4 +36,9 @@ private void reportError(String error) {
System.err.println(error);
throw new ConcurrentModificationException(error);
}

@Override
public InvocationDispatcher dispatcher() {
return new UnsynchronisedInvocationDispatcher();
}
}
Loading

0 comments on commit 498d09a

Please sign in to comment.