Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
Remove the TestKitRule again. Incorporate it into the existing rule a…
Browse files Browse the repository at this point in the history
…s suggested in issue #2
  • Loading branch information
zapodot committed Sep 22, 2016
1 parent e91bce4 commit e61fa0e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 55 deletions.
7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
<maven-javadoc-plugin.version>2.10.2</maven-javadoc-plugin.version>
<nexus-staging-maven-plugin.version>1.6.5</nexus-staging-maven-plugin.version>
<maven-source-plugin.version>2.4</maven-source-plugin.version>
<coveralls-maven-plugin.version>3.1.0</coveralls-maven-plugin.version>
<jacoco-maven-plugin.version>0.7.5.201505241946</jacoco-maven-plugin.version>
</properties>
<profiles>
<profile>
Expand Down Expand Up @@ -171,6 +173,7 @@
<links>
<link>http://junit.org/junit4/javadoc/latest/</link>
<link>http://docs.oracle.com/javase/7/docs/api/</link>
<link>http://doc.akka.io/japi/akka/${akka.version}/</link>
</links>
<locale>en</locale>
<keywords>true</keywords>
Expand All @@ -180,12 +183,12 @@
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>3.1.0</version>
<version>${coveralls-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<version>${jacoco-maven-plugin.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/zapodot/akka/junit/ActorSystemRule.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
package org.zapodot.akka.junit;

import akka.actor.ActorSystem;
import akka.testkit.JavaTestKit;
import org.junit.rules.TestRule;

/**
* @author zapodot at gmail dot com
*/
public interface ActorSystemRule extends TestRule {

/**
* Assertion that is used to check whether a given message was unhandled
*
* @param letter the message
* @return boolean indicating whether the message was unhandled
*/
boolean isUnhandled(Object letter);

/**
* Provides access to the {@link ActorSystem} that was instantiated before the test was run
*
* @return the currently running {@link ActorSystem}
*/
ActorSystem system();

/**
* Convienience method that provides easy access to a {@link JavaTestKit} instance.
*
* @return the {@link JavaTestKit} instance that was created before the test ran
*/
JavaTestKit testKit();

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,4 @@ public ActorSystemRule build() {
return new ActorSystemRuleImpl(name, config);
}

public TestKitRule buildTestKit() {
return new TestKitRuleImpl(name, config);
}
}
14 changes: 9 additions & 5 deletions src/main/java/org/zapodot/akka/junit/ActorSystemRuleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ActorSystemRuleImpl extends ExternalResource implements ActorSystem
private ActorSystem actorSystem;
private Config config = null;
private TestActorRef<ConsumingActor> unhandledMessagesConsumer;
private JavaTestKit javaTestKit;


public ActorSystemRuleImpl(final String name,
Expand Down Expand Up @@ -62,29 +63,32 @@ public boolean isUnhandled(final Object letter) {
return false;
}

/**
* Provides access to the {@link ActorSystem} that was instantiated before the test was run
*
* @return the currently running {@link ActorSystem}
*/

@Override
public ActorSystem system() {
return actorSystem;
}

@Override
public JavaTestKit testKit() {
return javaTestKit;
}

@Override
protected void before() throws Throwable {
LOGGER.debug("Instantiating ActorSystem \"{}\"", name);
actorSystem = config == null ? ActorSystem.create(name) : ActorSystem.create(name, config);

unhandledMessagesConsumer = TestActorRef.create(actorSystem, Props.create(ConsumingActor.class), "unhandledMessagesConsumer");
actorSystem.eventStream().subscribe(unhandledMessagesConsumer, UnhandledMessage.class);
javaTestKit = new JavaTestKit(actorSystem);

}

@Override
protected void after() {

javaTestKit = null;
if (!actorSystem.isTerminated()) {
LOGGER.debug("Shutting down ActorSystem \"{}\"", name);
JavaTestKit.shutdownActorSystem(actorSystem);
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/org/zapodot/akka/junit/TestKitRule.java

This file was deleted.

33 changes: 0 additions & 33 deletions src/main/java/org/zapodot/akka/junit/TestKitRuleImpl.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/java/org/zapodot/akka/junit/TestKitRuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onReceive(final Object message) throws Exception {
}

@Rule
public TestKitRule testKitRule = ActorSystemRuleBuilder.builder().setName(getClass().getSimpleName()).buildTestKit();
public ActorSystemRule testKitRule = ActorSystemRuleBuilder.builder().setName(getClass().getSimpleName()).build();

@Test
public void testRule() throws Exception {
Expand Down

0 comments on commit e61fa0e

Please sign in to comment.