Replace System Rules with System Lambda
System Lambda is more specific. It only wraps the part of the code that produces the output.
This commit is contained in:
6
pom.xml
6
pom.xml
@ -52,7 +52,7 @@
|
|||||||
<jaxb-api.version>2.3.1</jaxb-api.version>
|
<jaxb-api.version>2.3.1</jaxb-api.version>
|
||||||
<jaxb-impl.version>2.3.2</jaxb-impl.version>
|
<jaxb-impl.version>2.3.2</jaxb-impl.version>
|
||||||
<annotation-api.version>1.3.2</annotation-api.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>
|
<urm.version>2.0.0</urm.version>
|
||||||
<mockito-junit-jupiter.version>3.5.0</mockito-junit-jupiter.version>
|
<mockito-junit-jupiter.version>3.5.0</mockito-junit-jupiter.version>
|
||||||
<!-- SonarCloud -->
|
<!-- SonarCloud -->
|
||||||
@ -338,8 +338,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.stefanbirkner</groupId>
|
<groupId>com.github.stefanbirkner</groupId>
|
||||||
<artifactId>system-rules</artifactId>
|
<artifactId>system-lambda</artifactId>
|
||||||
<version>${system-rules.version}</version>
|
<version>${system-lambda.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.stefanbirkner</groupId>
|
<groupId>com.github.stefanbirkner</groupId>
|
||||||
<artifactId>system-rules</artifactId>
|
<artifactId>system-lambda</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
@ -23,55 +23,48 @@
|
|||||||
|
|
||||||
package com.iluwatar.subclasssandbox;
|
package com.iluwatar.subclasssandbox;
|
||||||
|
|
||||||
|
import com.github.stefanbirkner.systemlambda.Statement;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.contrib.java.lang.system.SystemOutRule;
|
|
||||||
|
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOutNormalized;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GroundDive unit tests.
|
* GroundDive unit tests.
|
||||||
*/
|
*/
|
||||||
public class GroundDiveTest {
|
public class GroundDiveTest {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public SystemOutRule log = new SystemOutRule().enableLog();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMove() {
|
public void testMove() throws Exception {
|
||||||
log.clearLog();
|
|
||||||
var groundDive = new GroundDive();
|
var groundDive = new GroundDive();
|
||||||
groundDive.move(1.0, 1.0, 1.0);
|
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 )";
|
var expectedLog = "Move to ( 1.0, 1.0, 1.0 )";
|
||||||
Assert.assertEquals(outputLog, expectedLog);
|
Assert.assertEquals(outputLog, expectedLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlaySound() {
|
public void testPlaySound() throws Exception {
|
||||||
log.clearLog();
|
|
||||||
var groundDive = new GroundDive();
|
var groundDive = new GroundDive();
|
||||||
groundDive.playSound("SOUND_NAME", 1);
|
var outputLog = getLogContent(() -> groundDive.playSound("SOUND_NAME", 1));
|
||||||
var outputLog = getLogContent(log.getLog());
|
|
||||||
var expectedLog = "Play SOUND_NAME with volumn 1";
|
var expectedLog = "Play SOUND_NAME with volumn 1";
|
||||||
Assert.assertEquals(outputLog, expectedLog);
|
Assert.assertEquals(outputLog, expectedLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSpawnParticles() {
|
public void testSpawnParticles() throws Exception {
|
||||||
log.clearLog();
|
|
||||||
var groundDive = new GroundDive();
|
var groundDive = new GroundDive();
|
||||||
groundDive.spawnParticles("PARTICLE_TYPE", 100);
|
final var outputLog = getLogContent(
|
||||||
final var outputLog = getLogContent(log.getLog());
|
() -> groundDive.spawnParticles("PARTICLE_TYPE", 100));
|
||||||
final var expectedLog = "Spawn 100 particle with type PARTICLE_TYPE";
|
final var expectedLog = "Spawn 100 particle with type PARTICLE_TYPE";
|
||||||
Assert.assertEquals(outputLog, expectedLog);
|
Assert.assertEquals(outputLog, expectedLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testActivate() {
|
public void testActivate() throws Exception {
|
||||||
log.clearLog();
|
|
||||||
var groundDive = new GroundDive();
|
var groundDive = new GroundDive();
|
||||||
groundDive.activate();
|
var logs = tapSystemOutNormalized(groundDive::activate)
|
||||||
var logs = log.getLog().split("\n");
|
.split("\n");
|
||||||
final var expectedSize = 3;
|
final var expectedSize = 3;
|
||||||
final var log1 = logs[0].split("-")[1].trim() + " -" + logs[0].split("-")[2].trim();
|
final var log1 = logs[0].split("-")[1].trim() + " -" + logs[0].split("-")[2].trim();
|
||||||
final var expectedLog1 = "Move to ( 0.0, 0.0, -20.0 )";
|
final var expectedLog1 = "Move to ( 0.0, 0.0, -20.0 )";
|
||||||
@ -85,6 +78,11 @@ public class GroundDiveTest {
|
|||||||
Assert.assertEquals(log3, expectedLog3);
|
Assert.assertEquals(log3, expectedLog3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getLogContent(Statement statement) throws Exception {
|
||||||
|
var log = tapSystemOutNormalized(statement);
|
||||||
|
return getLogContent(log);
|
||||||
|
}
|
||||||
|
|
||||||
private String getLogContent(String log) {
|
private String getLogContent(String log) {
|
||||||
return log.split("-")[1].trim();
|
return log.split("-")[1].trim();
|
||||||
}
|
}
|
||||||
|
@ -23,55 +23,47 @@
|
|||||||
|
|
||||||
package com.iluwatar.subclasssandbox;
|
package com.iluwatar.subclasssandbox;
|
||||||
|
|
||||||
|
import com.github.stefanbirkner.systemlambda.Statement;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.contrib.java.lang.system.SystemOutRule;
|
|
||||||
|
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOutNormalized;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SkyLaunch unit tests.
|
* SkyLaunch unit tests.
|
||||||
*/
|
*/
|
||||||
public class SkyLaunchTest {
|
public class SkyLaunchTest {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public SystemOutRule log = new SystemOutRule().enableLog();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMove() {
|
public void testMove() throws Exception {
|
||||||
log.clearLog();
|
|
||||||
var skyLaunch = new SkyLaunch();
|
var skyLaunch = new SkyLaunch();
|
||||||
skyLaunch.move(1.0, 1.0, 1.0);
|
var outputLog = getLogContent(() -> skyLaunch.move(1.0, 1.0, 1.0));
|
||||||
var outputLog = getLogContent(log.getLog());
|
|
||||||
var expectedLog = "Move to ( 1.0, 1.0, 1.0 )";
|
var expectedLog = "Move to ( 1.0, 1.0, 1.0 )";
|
||||||
Assert.assertEquals(outputLog, expectedLog);
|
Assert.assertEquals(outputLog, expectedLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlaySound() {
|
public void testPlaySound() throws Exception {
|
||||||
log.clearLog();
|
|
||||||
var skyLaunch = new SkyLaunch();
|
var skyLaunch = new SkyLaunch();
|
||||||
skyLaunch.playSound("SOUND_NAME", 1);
|
var outputLog = getLogContent(() -> skyLaunch.playSound("SOUND_NAME", 1));
|
||||||
var outputLog = getLogContent(log.getLog());
|
|
||||||
var expectedLog = "Play SOUND_NAME with volumn 1";
|
var expectedLog = "Play SOUND_NAME with volumn 1";
|
||||||
Assert.assertEquals(outputLog, expectedLog);
|
Assert.assertEquals(outputLog, expectedLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSpawnParticles() {
|
public void testSpawnParticles() throws Exception {
|
||||||
log.clearLog();
|
|
||||||
var skyLaunch = new SkyLaunch();
|
var skyLaunch = new SkyLaunch();
|
||||||
skyLaunch.spawnParticles("PARTICLE_TYPE", 100);
|
var outputLog = getLogContent(
|
||||||
var outputLog = getLogContent(log.getLog());
|
() -> skyLaunch.spawnParticles("PARTICLE_TYPE", 100));
|
||||||
var expectedLog = "Spawn 100 particle with type PARTICLE_TYPE";
|
var expectedLog = "Spawn 100 particle with type PARTICLE_TYPE";
|
||||||
Assert.assertEquals(outputLog, expectedLog);
|
Assert.assertEquals(outputLog, expectedLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testActivate() {
|
public void testActivate() throws Exception {
|
||||||
log.clearLog();
|
|
||||||
var skyLaunch = new SkyLaunch();
|
var skyLaunch = new SkyLaunch();
|
||||||
skyLaunch.activate();
|
var logs = tapSystemOutNormalized(skyLaunch::activate)
|
||||||
var logs = log.getLog().split("\n");
|
.split("\n");
|
||||||
final var expectedSize = 3;
|
final var expectedSize = 3;
|
||||||
final var log1 = getLogContent(logs[0]);
|
final var log1 = getLogContent(logs[0]);
|
||||||
final var expectedLog1 = "Move to ( 0.0, 0.0, 20.0 )";
|
final var expectedLog1 = "Move to ( 0.0, 0.0, 20.0 )";
|
||||||
@ -85,6 +77,11 @@ public class SkyLaunchTest {
|
|||||||
Assert.assertEquals(log3, expectedLog3);
|
Assert.assertEquals(log3, expectedLog3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getLogContent(Statement statement) throws Exception {
|
||||||
|
var log = tapSystemOutNormalized(statement);
|
||||||
|
return getLogContent(log);
|
||||||
|
}
|
||||||
|
|
||||||
private String getLogContent(String log) {
|
private String getLogContent(String log) {
|
||||||
return log.split("-")[1].trim();
|
return log.split("-")[1].trim();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user