Skip to content

Replace System Rules with System Lambda #1505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<jaxb-api.version>2.3.1</jaxb-api.version>
<jaxb-impl.version>2.3.2</jaxb-impl.version>
<annotation-api.version>1.3.2</annotation-api.version>
<system-rules.version>1.19.0</system-rules.version>
<system-lambda.version>1.1.0</system-lambda.version>
<urm.version>2.0.0</urm.version>
<mockito-junit-jupiter.version>3.5.0</mockito-junit-jupiter.version>
<!-- SonarCloud -->
Expand Down Expand Up @@ -338,8 +338,8 @@
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>${system-rules.version}</version>
<artifactId>system-lambda</artifactId>
<version>${system-lambda.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion subclass-sandbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<artifactId>system-lambda</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,48 @@

package com.iluwatar.subclasssandbox;

import com.github.stefanbirkner.systemlambda.Statement;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;

import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOutNormalized;

/**
* GroundDive unit tests.
*/
public class GroundDiveTest {

@Rule
public SystemOutRule log = new SystemOutRule().enableLog();

@Test
public void testMove() {
log.clearLog();
public void testMove() throws Exception {
var groundDive = new GroundDive();
groundDive.move(1.0, 1.0, 1.0);
var outputLog = getLogContent(log.getLog());
var outputLog = getLogContent(() -> groundDive.move(1.0, 1.0, 1.0));
var expectedLog = "Move to ( 1.0, 1.0, 1.0 )";
Assert.assertEquals(outputLog, expectedLog);
}

@Test
public void testPlaySound() {
log.clearLog();
public void testPlaySound() throws Exception {
var groundDive = new GroundDive();
groundDive.playSound("SOUND_NAME", 1);
var outputLog = getLogContent(log.getLog());
var outputLog = getLogContent(() -> groundDive.playSound("SOUND_NAME", 1));
var expectedLog = "Play SOUND_NAME with volumn 1";
Assert.assertEquals(outputLog, expectedLog);
}

@Test
public void testSpawnParticles() {
log.clearLog();
public void testSpawnParticles() throws Exception {
var groundDive = new GroundDive();
groundDive.spawnParticles("PARTICLE_TYPE", 100);
final var outputLog = getLogContent(log.getLog());
final var outputLog = getLogContent(
() -> groundDive.spawnParticles("PARTICLE_TYPE", 100));
final var expectedLog = "Spawn 100 particle with type PARTICLE_TYPE";
Assert.assertEquals(outputLog, expectedLog);
}

@Test
public void testActivate() {
log.clearLog();
public void testActivate() throws Exception {
var groundDive = new GroundDive();
groundDive.activate();
var logs = log.getLog().split("\n");
var logs = tapSystemOutNormalized(groundDive::activate)
.split("\n");
final var expectedSize = 3;
final var log1 = logs[0].split("-")[1].trim() + " -" + logs[0].split("-")[2].trim();
final var expectedLog1 = "Move to ( 0.0, 0.0, -20.0 )";
Expand All @@ -85,6 +78,11 @@ public void testActivate() {
Assert.assertEquals(log3, expectedLog3);
}

private String getLogContent(Statement statement) throws Exception {
var log = tapSystemOutNormalized(statement);
return getLogContent(log);
}

private String getLogContent(String log) {
return log.split("-")[1].trim();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,47 @@

package com.iluwatar.subclasssandbox;

import com.github.stefanbirkner.systemlambda.Statement;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;

import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOutNormalized;

/**
* SkyLaunch unit tests.
*/
public class SkyLaunchTest {

@Rule
public SystemOutRule log = new SystemOutRule().enableLog();

@Test
public void testMove() {
log.clearLog();
public void testMove() throws Exception {
var skyLaunch = new SkyLaunch();
skyLaunch.move(1.0, 1.0, 1.0);
var outputLog = getLogContent(log.getLog());
var outputLog = getLogContent(() -> skyLaunch.move(1.0, 1.0, 1.0));
var expectedLog = "Move to ( 1.0, 1.0, 1.0 )";
Assert.assertEquals(outputLog, expectedLog);
}

@Test
public void testPlaySound() {
log.clearLog();
public void testPlaySound() throws Exception {
var skyLaunch = new SkyLaunch();
skyLaunch.playSound("SOUND_NAME", 1);
var outputLog = getLogContent(log.getLog());
var outputLog = getLogContent(() -> skyLaunch.playSound("SOUND_NAME", 1));
var expectedLog = "Play SOUND_NAME with volumn 1";
Assert.assertEquals(outputLog, expectedLog);
}

@Test
public void testSpawnParticles() {
log.clearLog();
public void testSpawnParticles() throws Exception {
var skyLaunch = new SkyLaunch();
skyLaunch.spawnParticles("PARTICLE_TYPE", 100);
var outputLog = getLogContent(log.getLog());
var outputLog = getLogContent(
() -> skyLaunch.spawnParticles("PARTICLE_TYPE", 100));
var expectedLog = "Spawn 100 particle with type PARTICLE_TYPE";
Assert.assertEquals(outputLog, expectedLog);
}

@Test
public void testActivate() {
log.clearLog();
public void testActivate() throws Exception {
var skyLaunch = new SkyLaunch();
skyLaunch.activate();
var logs = log.getLog().split("\n");
var logs = tapSystemOutNormalized(skyLaunch::activate)
.split("\n");
final var expectedSize = 3;
final var log1 = getLogContent(logs[0]);
final var expectedLog1 = "Move to ( 0.0, 0.0, 20.0 )";
Expand All @@ -85,6 +77,11 @@ public void testActivate() {
Assert.assertEquals(log3, expectedLog3);
}

private String getLogContent(Statement statement) throws Exception {
var log = tapSystemOutNormalized(statement);
return getLogContent(log);
}

private String getLogContent(String log) {
return log.split("-")[1].trim();
}
Expand Down