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

Commit

Permalink
Avoid using the constructors directly in the tests. Deprecates ActorS…
Browse files Browse the repository at this point in the history
…ystemImpl.builder()
  • Loading branch information
zapodot committed Sep 25, 2016
1 parent 882f13e commit 459eef0
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 20 deletions.
19 changes: 19 additions & 0 deletions src/main/java/org/zapodot/akka/junit/ActorSystemRuleBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,20 @@ public class ActorSystemRuleBuilder {
private Config config = null;
private long shutdownTimeoutInSeconds = ActorSystemRule.DEFAULT_SHUTDOWN_TIMEOUT;

/**
* Builds a plain instance using only default settings
*
* @return a new {@link ActorSystemRule} instance with default settings applied
*/
public static ActorSystemRule buildWithDefaults() {
return builder().build();
}

/**
* Creates a new {@link ActorSystemRuleBuilder} allowing for customization of the underlying {@link akka.actor.ActorSystem}
*
* @return a new {@link ActorSystemRuleBuilder} instance
*/
public static ActorSystemRuleBuilder builder() {
return new ActorSystemRuleBuilder();
}
Expand All @@ -32,6 +45,12 @@ public static String defaultActorSystemName() {
return IMPLICIT_NAME_PREFIX + UUID.randomUUID().toString().replace("-", "");
}

/**
* Allows you to set a name for the underlying {@link akka.actor.ActorSystem} explicitly
*
* @param name the name to use
* @return the same {@link ActorSystemRuleBuilder} with the given name applied
*/
public ActorSystemRuleBuilder setName(final String name) {
this.name = name;
return this;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/zapodot/akka/junit/ActorSystemRuleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public ActorSystemRuleImpl() {
this(ActorSystemRuleBuilder.defaultActorSystemName());
}

/**
* @return a new {@link ActorSystemRuleBuilder} instance
* @deprecated use {@link ActorSystemRuleBuilder#builder()} instead
*/
@Deprecated
public static ActorSystemRuleBuilder builder() {
return ActorSystemRuleBuilder.builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class ActorSystemMultipleLoggersEnabled {

@Rule
public ActorSystemRule actorSystemRule = ActorSystemRuleImpl.builder()
public ActorSystemRule actorSystemRule = ActorSystemRuleBuilder.builder()
.setName(getClass().getSimpleName())
.enableEventLogging()
.enableEventTestListener()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ public class ActorSystemProvidingConfigTest {
private final static String SYSTEM_NAME = ActorSystemProvidingConfigTest.class.getSimpleName();

@Rule
public ActorSystemRule actorSystemRule = ActorSystemRuleImpl.builder().setName(SYSTEM_NAME).setConfigFromString(
"akka {\n"
+ " loggers = [\"akka.event.slf4j.Slf4jLogger\"]\n"
+ " loglevel = DEBUG\n"
+ "}").build();
public ActorSystemRule actorSystemRule = ActorSystemRuleBuilder.builder()
.setName(SYSTEM_NAME)
.setConfigFromString(
"akka {\n"
+ " loggers = [\"akka.event.slf4j.Slf4jLogger\"]\n"
+ " loglevel = DEBUG\n"
+ "}").build();

@Test
public void testConfigSet() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ActorSystemRuleBuilderTest {

@Test
public void testEnableEventListener() throws Exception {
final ActorSystemRuleBuilder actorSystemRuleBuilder = ActorSystemRuleImpl.builder().enableEventTestListener();
final ActorSystemRuleBuilder actorSystemRuleBuilder = ActorSystemRuleBuilder.builder().enableEventTestListener();
final Config config = actorSystemRuleBuilder.currentConfig();

assertEquals(TestEventListener.class.getName(), config.getStringList("akka.loggers").get(0));
Expand All @@ -22,12 +22,12 @@ public void testEnableEventListener() throws Exception {
@Test
public void testEmptyConfig() throws Exception {

assertEquals(ConfigFactory.empty(), ActorSystemRuleImpl.builder().currentConfig());
assertEquals(ConfigFactory.empty(), ActorSystemRuleBuilder.builder().currentConfig());
}

@Test
public void testAddExistingConfig() throws Exception {
assertEquals(ConfigFactory.empty(), ActorSystemRuleImpl.builder().setConfig(ConfigFactory.empty()).currentConfig());
assertEquals(ConfigFactory.empty(), ActorSystemRuleBuilder.builder().setConfig(ConfigFactory.empty()).currentConfig());
}

@Test
Expand All @@ -41,23 +41,23 @@ public void testAddExistingConfigTwice() throws Exception {

@Test
public void testEnableEventLogging() throws Exception {
final ActorSystemRuleBuilder actorSystemRuleBuilder = ActorSystemRuleImpl.builder().enableEventLogging();
final ActorSystemRuleBuilder actorSystemRuleBuilder = ActorSystemRuleBuilder.builder().enableEventLogging();
final Config config = actorSystemRuleBuilder.currentConfig();
assertEquals(Slf4jLogger.class.getName(), config.getStringList("akka.loggers").get(0));
assertEquals("DEBUG", config.getString("akka.loglevel"));
}

@Test
public void testEnableReceiveDebugLogging() throws Exception {
assertEquals("on", ActorSystemRuleImpl.builder().enableReceiveDebugLogging().currentConfig().getString(
assertEquals("on", ActorSystemRuleBuilder.builder().enableReceiveDebugLogging().currentConfig().getString(
"akka.actor.debug.receive"));
}


@Test
public void testEnableLifecycleDebugLogging() throws Exception {
assertEquals("on",
ActorSystemRuleImpl.builder()
ActorSystemRuleBuilder.builder()
.enableLifecycleDebugLogging()
.currentConfig()
.getString("akka.actor.debug.lifecycle"));
Expand All @@ -66,7 +66,7 @@ public void testEnableLifecycleDebugLogging() throws Exception {

@Test
public void testEnableLifecycleAndReceiveDebugLogging() throws Exception {
final Config config = ActorSystemRuleImpl.builder()
final Config config = ActorSystemRuleBuilder.builder()
.enableLifecycleDebugLogging()
.enableReceiveDebugLogging().currentConfig();
assertEquals("on", config.getString("akka.actor.debug.lifecycle"));
Expand All @@ -77,7 +77,7 @@ public void testEnableLifecycleAndReceiveDebugLogging() throws Exception {
@Test
public void testEnableInMemoryJournal() throws Exception {

final Config config = ActorSystemRuleImpl.builder().enableInmemoryJournal().currentConfig();
final Config config = ActorSystemRuleBuilder.builder().enableInmemoryJournal().currentConfig();
assertEquals("in-memory-journal", config.getString("akka.persistence.journal.plugin"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class ActorSystemRuleExplicitlyNamedTest {

@Rule
public ActorSystemRule actorSystemRule = ActorSystemRuleImpl.builder().setName(getClass().getSimpleName()).build();
public ActorSystemRule actorSystemRule = ActorSystemRuleBuilder.builder().setName(getClass().getSimpleName()).build();

@Test
public void testNamedActorSystemIsRunning() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
public class ActorSystemUsingFluentEventLogEnablement {

@Rule
public ActorSystemRule actorSystemWithEventLoggerEnabled = ActorSystemRuleImpl.builder()
public ActorSystemRule actorSystemWithEventLoggerEnabled = ActorSystemRuleBuilder.builder()
.enableEventLogging()
.setName(getClass().getSimpleName())
.build();

@Rule
public ActorSystemRule actorSystemWithoutEventLoggerEnabled = ActorSystemRuleImpl.builder()
public ActorSystemRule actorSystemWithoutEventLoggerEnabled = ActorSystemRuleBuilder.builder()
.setName(getClass().getSimpleName())
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
import org.junit.Rule;
import org.junit.Test;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;

@SuppressWarnings("deprecation")
public class DeprecatedActorSystemRuleImplicitlyNamedTest {

private static final String SECOND_SYSTEM_NAME = "AnotherActorSystem";

@Rule
public ActorSystemRule actorSystemRule = new ActorSystemRuleImpl();

@Rule
public ActorSystemRule anotherActorSystemRule = ActorSystemRuleImpl.builder().setName(SECOND_SYSTEM_NAME).build();

@Test
public void testActorSystemIsRunning() throws Exception {
assertNotNull(actorSystemRule.system());
assertTrue(actorSystemRule.system().name().startsWith(ActorSystemRuleBuilder.IMPLICIT_NAME_PREFIX));

assertThat(anotherActorSystemRule.system().name(), equalTo(SECOND_SYSTEM_NAME));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void onReceive(final Object message) throws Exception {
}

@Rule
public ActorSystemRule actorSystemRule = ActorSystemRuleImpl.builder().build();
public ActorSystemRule actorSystemRule = ActorSystemRuleBuilder.buildWithDefaults();

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

0 comments on commit 459eef0

Please sign in to comment.