未验证 提交 15d795bf 编写于 作者: I Ilkka Seppälä 提交者: GitHub

Merge pull request #1505 from stefanbirkner/system-lambda

Replace System Rules with System Lambda
......@@ -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 -->
......@@ -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>
......
......@@ -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>
......
......@@ -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 )";
......@@ -85,6 +78,11 @@ public class GroundDiveTest {
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();
}
......
......@@ -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 )";
......@@ -85,6 +77,11 @@ public class SkyLaunchTest {
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();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册