pax_global_header 0000666 0000000 0000000 00000000064 13470025346 0014516 g ustar 00root root 0000000 0000000 52 comment=488bfea2315261d208fd1d3bbc0115386d9003c2
jmock-library-2.12.0/ 0000775 0000000 0000000 00000000000 13470025346 0014345 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/.gitignore 0000664 0000000 0000000 00000000300 13470025346 0016326 0 ustar 00root root 0000000 0000000 build/
out/
bin/
workspace.xml
.DS_Store
.idea
target/
hamcrest-test-src
.settings
.project
.classpath
.gradle
.factorypath
gradle
*.iml
*.ipr
*.iws
gradlew
gradlew.bat
pom.xml.versionsBackup
jmock-library-2.12.0/.travis.yml 0000664 0000000 0000000 00000001224 13470025346 0016455 0 ustar 00root root 0000000 0000000 language: java
jdk:
- openjdk-ea
- openjdk11
- oraclejdk11
- openjdk10
# - oraclejdk10
- openjdk9
- oraclejdk8 #not supported
matrix:
allow_failures:
- jdk: openjdk-ea
env:
# Travis has slow VMs?
global:
- blitzerThreads=1 blitzerActions=1 blitzerTimeout=1000
- secure: "XBIyEF5RxH/zKjh0gle5ce/FRe9pP5b46LXKNOfwlau5QYvn8WXC41Sb6yYC8VW3vI9S930BnVGZONiDXsSWuylLezdu2g88nwJ2CsTxHU0Yg2GAzKwaorBQqyK/6w2foRRXtz69NJccfdIdPuDZSEhJtTKWSmMMQ7U65KH+zzQ="
- secure: "SSlAKOg8QLEAkZX1ehy9c6FR5R6gMzLhc6u2Smq9tm8JsWVz4EtS6NnTQaosthrNEfLJwVVCfmOh2dzvYZfhtbKAUMdkox45tem4+LZfgkSaQAGjSvsC6geioa4Alo6AKyR8foc5Y7P34f9ujYSZHNyRG9F6E0Qq2zj/hzHhstU="
jmock-library-2.12.0/LICENSE.txt 0000664 0000000 0000000 00000002663 13470025346 0016177 0 ustar 00root root 0000000 0000000 Copyright (c) 2000-2017, jMock.org
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of jMock nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
jmock-library-2.12.0/README.DEVELOPMENT 0000664 0000000 0000000 00000003401 13470025346 0017004 0 ustar 00root root 0000000 0000000 Development rules
=================
Here are some rules that we follow when developing jMock:
* Never check in a class without associated unit tests.
* Never check a failing unit test into the repository.
* Acceptance tests may fail. A failing acceptance test indicates
something that needs to be done: a todo item, feature request or
bug report, for example. It's ok to check a failing acceptance test
into the repository.
* Separate acceptance and unit tests. Make it easy to run only the
unit tests so that we can check that they pass before committing,
even when acceptance tests are failing.
* Resolve and remove all TODO comments before checking in.
* Avoid the following words in class names and other identifiers:
Helper, Impl (or a derivative), Manager.
* And the reverse: don't start interfaces with an I.
* Use the TestDox naming conventions for unit tests.
Architectural Constraints
=========================
* No dependency on any specific test framework.
That means, don't use JUnit Assert.assertBlahBlah to check expectations.
Throw ExpectationError to report a violated expectation.
Throw some kind of RuntimeException to report programming errors in the
use of the framework. E.g. trying to set up an expectation to return a
result of the wrong type.
Release
=======
mvn versions:set -DoldVersion=* -DnewVersion=2.10.0 -DgroupId=org.jmock -DgenerateBackupPoms=false
eval $(gpg-agent --daemon --no-grab --write-env-file $HOME/.gpg-agent-info)
export GPG_AGENT_INFO
export GPG_TTY=$(tty)
export SONATYPE_USERNAME=UUU
export SONATYPE_PASSWORD=PPPP
mvn clean deploy -P release --settings settings.xml -Dgpg.keyname=XXXXXXXX
mvn versions:set -DoldVersion=* -DnewVersion=2.11.0-SNAPSHOT -DgroupId=org.jmock -DgenerateBackupPoms=false
jmock-library-2.12.0/README.md 0000664 0000000 0000000 00000011300 13470025346 0015617 0 ustar 00root root 0000000 0000000 # JMock Library
[](https://travis-ci.org/jmock-developers/jmock-library)
[](https://mvnrepository.com/artifact/org.jmock)
# Maven
```xml
org.jmockjmock-junit52.11.0test
```
# Gradle
```
testCompile(
"junit:junit5:5.3.1",
"org.jmock:jmock-junit5:2.11.0"
)
```
# Recent Changes
## 2.10.0
### 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)
### Java7 Support will be dropped next release
## 2.9.0
* Dropped JDK 6 compliance.
* Exposed the InvocationDispatcher so that ThreadingPolicies
## 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`.
You should change
oneOf(mock).methodWithIntParams(with(any(Integer.class)));
to the following
oneOf(mock).methodWithIntParams(with.intIs(anything());
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
* Uses real method calls, not strings, so you can refactor more easily and
autocomplete in the IDE.
* Customisation by delegation, not by inheritance.
* Many more plugin-points for customisation.
* Independent of any testing framework: compatability with the testing
framework is a plugin-point.
* Can mock concrete classes *without* calling their constructors (if
you really want to).
* Uses Hamcrest matchers, so can use a large and ever-growing library
of matchers in expectations.
* Expectations match in first-in, first-out order, so tests are easier to understand.
# 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
### org.jmock
DSL-style API
### org.jmock.api
### org.jmock.lib
Convenient classes that implement the APIs in the core, are used by the DSL-style API, and can be used in user-defined APIs
### org.jmock.integration
Classes integrating jMock with different testing APIs, such as JUnit 3.x, JUnit 4.x and TestNG.
## 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
### org.jmock.internal
Internal implementation details
### org.jmock.test
Tests for jMock itself
## Plug-in Points
### Matcher
Controls the matching of invocations to expectations
### Action
Performs an action in response to an invocation
### Imposteriser
Wraps mock objects in an adapter of the correct type
### Expectation
Matches an invocation and fakes its behaviour
### ExpectationErrorTranslator
Translates expectation errors into error type used by a specific
testing framework.
### MockObjectNamingScheme
Creates names for mock objects based on the mocked type.
# Contributing
If you'd like to contribute, then do the following:
1. clone this repository (`git clone …`)
2. install Maven (`brew install mvn` on Mac OS, for example)
3. `$ mvn package` in order to generate a signed JAR. This will run all the tests. (`$ mvn test` appears not to suffice.)
jmock-library-2.12.0/jmock-example/ 0000775 0000000 0000000 00000000000 13470025346 0017101 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/pom.xml 0000664 0000000 0000000 00000003772 13470025346 0020427 0 ustar 00root root 0000000 0000000
4.0.0jmock-examplejarjMock Examplesorg.jmockjmock-parent2.12.0../pom.xmlUTF-8UTF-8junitjunitcompileorg.jmockjmock${project.version}compileorg.jmockjmock${project.version}test-jartestorg.jmockjmock-junit3${project.version}org.jmockjmock-junit4${project.version}org.codehaus.mojoversions-maven-plugin
jmock-library-2.12.0/jmock-example/src/ 0000775 0000000 0000000 00000000000 13470025346 0017670 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/ 0000775 0000000 0000000 00000000000 13470025346 0020614 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/ 0000775 0000000 0000000 00000000000 13470025346 0021535 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/ 0000775 0000000 0000000 00000000000 13470025346 0022324 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/ 0000775 0000000 0000000 00000000000 13470025346 0023427 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/ 0000775 0000000 0000000 00000000000 13470025346 0025062 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/announcer/ 0000775 0000000 0000000 00000000000 13470025346 0027052 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/announcer/Announcer.java 0000664 0000000 0000000 00000003221 13470025346 0031643 0 ustar 00root root 0000000 0000000 package org.jmock.example.announcer;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.EventListener;
import java.util.List;
public class Announcer {
private final T proxy;
private final List listeners = new ArrayList();
public Announcer(Class extends T> listenerType) {
proxy = listenerType.cast(Proxy.newProxyInstance(
listenerType.getClassLoader(),
new Class>[]{listenerType},
new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
announce(method, args);
return null;
}
}));
}
public void addListener(T listener) {
listeners.add(listener);
}
public void removeListener(T listener) {
listeners.remove(listener);
}
public T announce() {
return proxy;
}
private void announce(Method m, Object[] args) {
try {
for (T listener : listeners) {
m.invoke(listener, args);
}
}
catch (IllegalAccessException e) {
throw new IllegalArgumentException("could not invoke listener", e);
}
catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException)cause;
}
else if (cause instanceof Error) {
throw (Error)cause;
}
else {
throw new UnsupportedOperationException("listener threw exception", cause);
}
}
}
public static Announcer to(Class extends T> listenerType) {
return new Announcer(listenerType);
}
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/announcer/AnnouncerTests.java 0000664 0000000 0000000 00000004252 13470025346 0032673 0 ustar 00root root 0000000 0000000 package org.jmock.example.announcer;
import java.util.EventListener;
import org.jmock.Expectations;
import org.jmock.Sequence;
import org.jmock.integration.junit3.MockObjectTestCase;
public class AnnouncerTests extends MockObjectTestCase {
public static class CheckedException extends Exception {}
public interface Listener extends EventListener {
public void eventA();
public void eventB();
public void eventWithArguments(int a, int b);
public void badEvent() throws CheckedException;
}
Announcer announcer = Announcer.to(Listener.class);
Listener listener1 = mock(Listener.class, "listener1");
Listener listener2 = mock(Listener.class, "listener2");
@Override
public void setUp() {
announcer.addListener(listener1);
announcer.addListener(listener2);
}
public void testAnnouncesToRegisteredListenersInOrderOfAddition() {
final Sequence eventOrder = sequence("eventOrder");
checking(new Expectations() {{
oneOf (listener1).eventA(); inSequence(eventOrder);
oneOf (listener2).eventA(); inSequence(eventOrder);
oneOf (listener1).eventB(); inSequence(eventOrder);
oneOf (listener2).eventB(); inSequence(eventOrder);
}});
announcer.announce().eventA();
announcer.announce().eventB();
}
public void testPassesEventArgumentsToListeners() {
checking(new Expectations() {{
oneOf (listener1).eventWithArguments(1, 2);
oneOf (listener2).eventWithArguments(1, 2);
oneOf (listener1).eventWithArguments(3, 4);
oneOf (listener2).eventWithArguments(3, 4);
}});
announcer.announce().eventWithArguments(1, 2);
announcer.announce().eventWithArguments(3, 4);
}
public void testCanRemoveListeners() {
announcer.removeListener(listener1);
checking(new Expectations() {{
oneOf (listener2).eventA();
}});
announcer.announce().eventA();
}
public void testDoesNotAllowListenersToThrowCheckedExceptions() throws Exception {
checking(new Expectations() {{
allowing (listener1).badEvent(); will(throwException(new CheckedException()));
}});
try {
announcer.announce().badEvent();
fail("should have thrown UnsupportedOperationException");
}
catch (UnsupportedOperationException expected) {}
}
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/gettingstarted/ 0000775 0000000 0000000 00000000000 13470025346 0030112 5 ustar 00root root 0000000 0000000 GettingStartedJUnit3.java 0000664 0000000 0000000 00000001203 13470025346 0034657 0 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/gettingstarted package org.jmock.example.gettingstarted;
import org.jmock.Expectations;
import org.jmock.integration.junit3.MockObjectTestCase;
public class GettingStartedJUnit3 extends MockObjectTestCase {
public void testOneSubscriberReceivesAMessage() {
// set up
final Subscriber subscriber = mock(Subscriber.class);
Publisher publisher = new Publisher();
publisher.add(subscriber);
final String message = "message";
// expectations
checking(new Expectations() {{
oneOf(subscriber).receive(message);
}});
// execute
publisher.publish(message);
}
}
GettingStartedJUnit3Mockomatic.java 0000664 0000000 0000000 00000001217 13470025346 0036673 0 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/gettingstarted package org.jmock.example.gettingstarted;
import org.jmock.Expectations;
import org.jmock.auto.Mock;
import org.jmock.integration.junit3.MockObjectTestCase;
public class GettingStartedJUnit3Mockomatic extends MockObjectTestCase {
@Mock Subscriber subscriber;
public void testOneSubscriberReceivesAMessage() {
// set up
Publisher publisher = new Publisher();
publisher.add(subscriber);
final String message = "message";
// expectations
checking(new Expectations() {{
oneOf(subscriber).receive(message);
}});
// execute
publisher.publish(message);
}
} GettingStartedJUnit4.java 0000664 0000000 0000000 00000001467 13470025346 0034674 0 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/gettingstarted package org.jmock.example.gettingstarted;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(JMock.class)
public class GettingStartedJUnit4 {
Mockery context = new JUnit4Mockery();
@Test
public void oneSubscriberReceivesAMessage() {
// set up
final Subscriber subscriber = context.mock(Subscriber.class);
Publisher publisher = new Publisher();
publisher.add(subscriber);
final String message = "message";
// expectations
context.checking(new Expectations() {{
oneOf(subscriber).receive(message);
}});
// execute
publisher.publish(message);
}
} GettingStartedJUnit4Mockomatic.java 0000664 0000000 0000000 00000001370 13470025346 0036674 0 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/gettingstarted package org.jmock.example.gettingstarted;
import org.jmock.Expectations;
import org.jmock.auto.Mock;
import org.jmock.integration.junit4.JUnitRuleMockery;
import org.junit.Rule;
import org.junit.Test;
public class GettingStartedJUnit4Mockomatic {
@Rule
public JUnitRuleMockery context = new JUnitRuleMockery();
@Mock Subscriber subscriber;
@Test
public void oneSubscriberReceivesAMessage() {
// set up
Publisher publisher = new Publisher();
publisher.add(subscriber);
final String message = "message";
// expectations
context.checking(new Expectations() {{
oneOf(subscriber).receive(message);
}});
// execute
publisher.publish(message);
}
} GettingStartedJUnit4Rule.java 0000664 0000000 0000000 00000001366 13470025346 0035522 0 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/gettingstarted package org.jmock.example.gettingstarted;
import org.jmock.Expectations;
import org.jmock.integration.junit4.JUnitRuleMockery;
import org.junit.Rule;
import org.junit.Test;
public class GettingStartedJUnit4Rule {
@Rule
public JUnitRuleMockery context = new JUnitRuleMockery();
@Test
public void oneSubscriberReceivesAMessage() {
// set up
final Subscriber subscriber = context.mock(Subscriber.class);
Publisher publisher = new Publisher();
publisher.add(subscriber);
final String message = "message";
// expectations
context.checking(new Expectations() {{
oneOf(subscriber).receive(message);
}});
// execute
publisher.publish(message);
}
} GettingStartedJUnit4RuleMockomatic.java 0000664 0000000 0000000 00000001400 13470025346 0037516 0 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/gettingstarted package org.jmock.example.gettingstarted;
import org.jmock.Expectations;
import org.jmock.auto.Mock;
import org.jmock.integration.junit4.JUnitRuleMockery;
import org.junit.Rule;
import org.junit.Test;
public class GettingStartedJUnit4RuleMockomatic {
@Rule
public JUnitRuleMockery context = new JUnitRuleMockery();
@Mock Subscriber subscriber;
@Test
public void oneSubscriberReceivesAMessage() {
// set up
Publisher publisher = new Publisher();
publisher.add(subscriber);
final String message = "message";
// expectations
context.checking(new Expectations() {{
oneOf(subscriber).receive(message);
}});
// execute
publisher.publish(message);
}
} jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/gettingstarted/Publisher.java 0000664 0000000 0000000 00000000663 13470025346 0032717 0 ustar 00root root 0000000 0000000 package org.jmock.example.gettingstarted;
import java.util.ArrayList;
import java.util.List;
public class Publisher {
private List subscribers = new ArrayList();
public void add(Subscriber subscriber) {
subscribers.add(subscriber);
}
public void publish(String message) {
for (Subscriber subscriber : subscribers) {
subscriber.receive(message);
}
}
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/gettingstarted/Subscriber.java 0000664 0000000 0000000 00000000155 13470025346 0033061 0 ustar 00root root 0000000 0000000 package org.jmock.example.gettingstarted;
public interface Subscriber {
void receive(String message);
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/qcon/ 0000775 0000000 0000000 00000000000 13470025346 0026022 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/qcon/DJ.java 0000664 0000000 0000000 00000002064 13470025346 0027164 0 ustar 00root root 0000000 0000000 package org.jmock.example.qcon;
public class DJ implements LocationAware, MediaTracker {
private final MediaControl mediaControl;
private final Playlist playlist;
private String currentLocationName = null;
private boolean trackFinished = true;
private boolean locationChanged = false;
public DJ(Playlist playlist, MediaControl mediaControl) {
this.playlist = playlist;
this.mediaControl = mediaControl;
}
public void locationChangedTo(String newLocationName) {
currentLocationName = newLocationName;
if (trackFinished) {
startPlaying();
trackFinished = false;
}
else {
locationChanged = true;
}
}
public void mediaFinished() {
if (locationChanged) {
startPlaying();
locationChanged = false;
}
else {
trackFinished = true;
}
}
private void startPlaying() {
mediaControl.play(playlist.trackFor(currentLocationName));
}
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/qcon/DJTests.java 0000664 0000000 0000000 00000004750 13470025346 0030213 0 ustar 00root root 0000000 0000000 package org.jmock.example.qcon;
import org.jmock.Expectations;
import org.jmock.integration.junit3.MockObjectTestCase;
public class DJTests extends MockObjectTestCase {
Playlist playlist = mock(Playlist.class);
MediaControl mediaControl = mock(MediaControl.class);
DJ dj = new DJ(playlist, mediaControl);
private static final String LOCATION_A = "location-a";
private static final String TRACK_A = "track-a";
private static final String LOCATION_B = "location-b";
private static final String TRACK_B = "track-b";
@Override
public void setUp() {
checking(new Expectations() {{
allowing (playlist).hasTrackFor(LOCATION_A); will(returnValue(true));
allowing (playlist).trackFor(LOCATION_A); will(returnValue(TRACK_A));
allowing (playlist).hasTrackFor(LOCATION_B); will(returnValue(true));
allowing (playlist).trackFor(LOCATION_B); will(returnValue(TRACK_B));
allowing (playlist).hasTrackFor(with(any(String.class))); will(returnValue(false));
}});
}
public void testStartsPlayingTrackForCurrentLocationWhenLocationFirstDetected() {
checking(new Expectations() {{
oneOf (mediaControl).play(TRACK_A);
}});
dj.locationChangedTo(LOCATION_A);
}
public void testPlaysTrackForCurrentLocationWhenPreviousTrackFinishesIfLocationChangedWhileTrackWasPlaying() {
startingIn(LOCATION_A);
dj.locationChangedTo(LOCATION_B);
checking(new Expectations() {{
oneOf (mediaControl).play(TRACK_B);
}});
dj.mediaFinished();
}
public void testDoesNotPlayTrackAgainIfStillInTheSameLocation() {
startingIn(LOCATION_A);
checking(new Expectations() {{
never (mediaControl).play(with(any(String.class)));
}});
dj.mediaFinished();
}
public void testPlaysNewTrackAsSoonAsLocationChangesIfPreviousTrackFinishedWhileInSameLocation() {
startingIn(LOCATION_A);
dj.mediaFinished();
checking(new Expectations() {{
oneOf (mediaControl).play(TRACK_B);
}});
dj.locationChangedTo(LOCATION_B);
}
private void startingIn(String initialLocation) {
checking(new Expectations() {{
oneOf (mediaControl).play(with(any(String.class)));
}});
dj.locationChangedTo(initialLocation);
}
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/qcon/LocationAware.java 0000664 0000000 0000000 00000000170 13470025346 0031413 0 ustar 00root root 0000000 0000000 package org.jmock.example.qcon;
public interface LocationAware {
void locationChangedTo(String newLocationName);
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/qcon/MediaControl.java 0000664 0000000 0000000 00000000145 13470025346 0031245 0 ustar 00root root 0000000 0000000 package org.jmock.example.qcon;
public interface MediaControl {
void play(String mediaFile);
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/qcon/MediaTracker.java 0000664 0000000 0000000 00000000135 13470025346 0031217 0 ustar 00root root 0000000 0000000 package org.jmock.example.qcon;
public interface MediaTracker {
void mediaFinished();
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/qcon/Playlist.java 0000664 0000000 0000000 00000000217 13470025346 0030466 0 ustar 00root root 0000000 0000000 package org.jmock.example.qcon;
public interface Playlist {
boolean hasTrackFor(String location);
String trackFor(String location);
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/sniper/ 0000775 0000000 0000000 00000000000 13470025346 0026362 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/sniper/Auction.java 0000664 0000000 0000000 00000000173 13470025346 0030630 0 ustar 00root root 0000000 0000000 package org.jmock.example.sniper;
public interface Auction {
public void bid(Money amount) throws AuctionException;
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/sniper/AuctionException.java 0000664 0000000 0000000 00000000361 13470025346 0032506 0 ustar 00root root 0000000 0000000 package org.jmock.example.sniper;
public class AuctionException extends Exception {
public AuctionException(String message) {
super(message);
}
public AuctionException(String message, Exception cause) {
super(message, cause);
}
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/sniper/AuctionListener.java 0000664 0000000 0000000 00000000172 13470025346 0032335 0 ustar 00root root 0000000 0000000 package org.jmock.example.sniper;
public interface AuctionListener {
void bidAccepted(Auction item, Money amount);
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/sniper/AuctionSniper.java 0000664 0000000 0000000 00000002010 13470025346 0032001 0 ustar 00root root 0000000 0000000 package org.jmock.example.sniper;
public class AuctionSniper implements AuctionListener {
private Auction lotToBidFor;
private Money bidIncrement;
private Money maximumBid;
private AuctionSniperListener listener;
public AuctionSniper(Auction lotToBidFor, Money bidIncrement, Money maximumBid, AuctionSniperListener listener) {
this.lotToBidFor = lotToBidFor;
this.bidIncrement = bidIncrement;
this.maximumBid = maximumBid;
this.listener = listener;
}
public void bidAccepted(Auction lot, Money amount) {
if (lot != lotToBidFor) return;
if (amount.compareTo(maximumBid) <= 0) {
placeBid(lot, amount);
}
else {
listener.sniperFinished(this);
}
}
private void placeBid(Auction item, Money amount) {
try {
item.bid(Money.min(maximumBid, amount.add(bidIncrement)));
}
catch (AuctionException ex) {
listener.sniperBidFailed(this, ex);
}
}
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/sniper/AuctionSniperListener.java0000664 0000000 0000000 00000000370 13470025346 0033516 0 ustar 00root root 0000000 0000000 package org.jmock.example.sniper;
import java.util.EventListener;
public interface AuctionSniperListener extends EventListener {
void sniperBidFailed(AuctionSniper sniper, AuctionException failure);
void sniperFinished(AuctionSniper sniper);
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/sniper/AuctionSniperTests.java 0000664 0000000 0000000 00000004533 13470025346 0033040 0 ustar 00root root 0000000 0000000 package org.jmock.example.sniper;
import org.jmock.Expectations;
import org.jmock.integration.junit3.MockObjectTestCase;
public class AuctionSniperTests extends MockObjectTestCase {
Money increment = new Money(2);
Money maximumBid = new Money(20);
Money beatableBid = new Money(10);
Money unbeatableBid = maximumBid.add(new Money(1));
Auction auction = mock(Auction.class);
AuctionSniperListener listener = mock(AuctionSniperListener.class, "listener");
AuctionSniper sniper = new AuctionSniper(auction, increment, maximumBid, listener);
public void testTriesToBeatTheLatestHighestBid() throws Exception {
final Money expectedBid = beatableBid.add(increment);
checking(new Expectations() {{
oneOf (auction).bid(expectedBid);
}});
sniper.bidAccepted(auction, beatableBid);
}
public void testWillNotBidPriceGreaterThanMaximum() throws Exception {
checking(new Expectations() {{
ignoring (listener);
never (auction).bid(with(any(Money.class)));
}});
sniper.bidAccepted(auction, unbeatableBid);
}
public void testWillLimitBidToMaximum() throws Throwable {
checking(new Expectations() {{
exactly(1).of (auction).bid(maximumBid);
}});
sniper.bidAccepted(auction, maximumBid.subtract(new Money(1)));
}
public void testWillNotBidWhenToldAboutBidsOnOtherItems() throws Throwable {
final Auction otherLot = mock(Auction.class, "otherLot");
checking(new Expectations() {{
never (otherLot).bid(new Money(10));
}});
sniper.bidAccepted(otherLot, beatableBid);
}
public void testWillAnnounceItHasFinishedIfPriceGoesAboveMaximum() {
checking(new Expectations() {{
exactly(1).of (listener).sniperFinished(sniper);
}});
sniper.bidAccepted(auction, unbeatableBid);
}
public void testCatchesExceptionsAndReportsThemToErrorListener() throws Exception {
final AuctionException exception = new AuctionException("test");
checking(new Expectations() {{
allowing (auction).bid(with(any(Money.class)));
will(throwException(exception));
exactly(1).of (listener).sniperBidFailed(sniper, exception);
}});
sniper.bidAccepted(auction, beatableBid);
}
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/sniper/Money.java 0000664 0000000 0000000 00000002206 13470025346 0030314 0 ustar 00root root 0000000 0000000 package org.jmock.example.sniper;
import java.math.BigDecimal;
public class Money implements Comparable {
private BigDecimal amount;
public Money(BigDecimal amount) {
this.amount = amount;
}
public Money(int amount) {
this(new BigDecimal(amount));
}
public Money(double amount) {
this(new BigDecimal(amount));
}
public Money add(Money other) {
return new Money(amount.add(other.amount));
}
public Money subtract(Money other) {
return new Money(amount.subtract(other.amount));
}
@Override
public String toString() {
return "£" + amount;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return amount.equals(((Money) o).amount);
}
@Override
public int hashCode() {
return amount.hashCode();
}
public int compareTo(Money other) {
return amount.compareTo(other.amount);
}
public static Money min(Money m1, Money m2) {
return new Money(m1.amount.min(m2.amount));
}
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/timedcache/ 0000775 0000000 0000000 00000000000 13470025346 0027150 5 ustar 00root root 0000000 0000000 jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/timedcache/Clock.java 0000664 0000000 0000000 00000000153 13470025346 0031045 0 ustar 00root root 0000000 0000000 package org.jmock.example.timedcache;
import java.util.Date;
public interface Clock {
Date time();
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/timedcache/ObjectLoader.java 0000664 0000000 0000000 00000000146 13470025346 0032351 0 ustar 00root root 0000000 0000000 package org.jmock.example.timedcache;
public interface ObjectLoader {
Object load(Object key);
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/timedcache/ReloadPolicy.java 0000664 0000000 0000000 00000000232 13470025346 0032376 0 ustar 00root root 0000000 0000000 package org.jmock.example.timedcache;
import java.util.Date;
public interface ReloadPolicy {
boolean shouldReload(Date loadTime, Date fetchTime);
}
jmock-library-2.12.0/jmock-example/src/main/java/org/jmock/example/timedcache/TimedCache.java 0000664 0000000 0000000 00000002277 13470025346 0032011 0 ustar 00root root 0000000 0000000 package org.jmock.example.timedcache;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class TimedCache {
private ObjectLoader loader;
private Clock clock;
private ReloadPolicy reloadPolicy;
private Map