Skip to content

Commit 15d795b

Browse files
authored
Merge pull request iluwatar#1505 from stefanbirkner/system-lambda
Replace System Rules with System Lambda
2 parents 6d83ceb + 3754c66 commit 15d795b

File tree

4 files changed

+40
-45
lines changed

4 files changed

+40
-45
lines changed

Diff for: pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<jaxb-api.version>2.3.1</jaxb-api.version>
5353
<jaxb-impl.version>2.3.2</jaxb-impl.version>
5454
<annotation-api.version>1.3.2</annotation-api.version>
55-
<system-rules.version>1.19.0</system-rules.version>
55+
<system-lambda.version>1.1.0</system-lambda.version>
5656
<urm.version>2.0.0</urm.version>
5757
<mockito-junit-jupiter.version>3.5.0</mockito-junit-jupiter.version>
5858
<!-- SonarCloud -->
@@ -338,8 +338,8 @@
338338
</dependency>
339339
<dependency>
340340
<groupId>com.github.stefanbirkner</groupId>
341-
<artifactId>system-rules</artifactId>
342-
<version>${system-rules.version}</version>
341+
<artifactId>system-lambda</artifactId>
342+
<version>${system-lambda.version}</version>
343343
<scope>test</scope>
344344
</dependency>
345345
</dependencies>

Diff for: subclass-sandbox/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</dependency>
4343
<dependency>
4444
<groupId>com.github.stefanbirkner</groupId>
45-
<artifactId>system-rules</artifactId>
45+
<artifactId>system-lambda</artifactId>
4646
</dependency>
4747
<dependency>
4848
<groupId>org.junit.jupiter</groupId>

Diff for: subclass-sandbox/src/test/java/com/iluwatar/subclasssandbox/GroundDiveTest.java

+18-20
Original file line numberDiff line numberDiff line change
@@ -23,55 +23,48 @@
2323

2424
package com.iluwatar.subclasssandbox;
2525

26+
import com.github.stefanbirkner.systemlambda.Statement;
2627
import org.junit.Assert;
27-
import org.junit.Rule;
2828
import org.junit.Test;
29-
import org.junit.contrib.java.lang.system.SystemOutRule;
29+
30+
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOutNormalized;
3031

3132
/**
3233
* GroundDive unit tests.
3334
*/
3435
public class GroundDiveTest {
3536

36-
@Rule
37-
public SystemOutRule log = new SystemOutRule().enableLog();
38-
3937
@Test
40-
public void testMove() {
41-
log.clearLog();
38+
public void testMove() throws Exception {
4239
var groundDive = new GroundDive();
4340
groundDive.move(1.0, 1.0, 1.0);
44-
var outputLog = getLogContent(log.getLog());
41+
var outputLog = getLogContent(() -> groundDive.move(1.0, 1.0, 1.0));
4542
var expectedLog = "Move to ( 1.0, 1.0, 1.0 )";
4643
Assert.assertEquals(outputLog, expectedLog);
4744
}
4845

4946
@Test
50-
public void testPlaySound() {
51-
log.clearLog();
47+
public void testPlaySound() throws Exception {
5248
var groundDive = new GroundDive();
53-
groundDive.playSound("SOUND_NAME", 1);
54-
var outputLog = getLogContent(log.getLog());
49+
var outputLog = getLogContent(() -> groundDive.playSound("SOUND_NAME", 1));
5550
var expectedLog = "Play SOUND_NAME with volumn 1";
5651
Assert.assertEquals(outputLog, expectedLog);
5752
}
5853

5954
@Test
60-
public void testSpawnParticles() {
61-
log.clearLog();
55+
public void testSpawnParticles() throws Exception {
6256
var groundDive = new GroundDive();
63-
groundDive.spawnParticles("PARTICLE_TYPE", 100);
64-
final var outputLog = getLogContent(log.getLog());
57+
final var outputLog = getLogContent(
58+
() -> groundDive.spawnParticles("PARTICLE_TYPE", 100));
6559
final var expectedLog = "Spawn 100 particle with type PARTICLE_TYPE";
6660
Assert.assertEquals(outputLog, expectedLog);
6761
}
6862

6963
@Test
70-
public void testActivate() {
71-
log.clearLog();
64+
public void testActivate() throws Exception {
7265
var groundDive = new GroundDive();
73-
groundDive.activate();
74-
var logs = log.getLog().split("\n");
66+
var logs = tapSystemOutNormalized(groundDive::activate)
67+
.split("\n");
7568
final var expectedSize = 3;
7669
final var log1 = logs[0].split("-")[1].trim() + " -" + logs[0].split("-")[2].trim();
7770
final var expectedLog1 = "Move to ( 0.0, 0.0, -20.0 )";
@@ -85,6 +78,11 @@ public void testActivate() {
8578
Assert.assertEquals(log3, expectedLog3);
8679
}
8780

81+
private String getLogContent(Statement statement) throws Exception {
82+
var log = tapSystemOutNormalized(statement);
83+
return getLogContent(log);
84+
}
85+
8886
private String getLogContent(String log) {
8987
return log.split("-")[1].trim();
9088
}

Diff for: subclass-sandbox/src/test/java/com/iluwatar/subclasssandbox/SkyLaunchTest.java

+18-21
Original file line numberDiff line numberDiff line change
@@ -23,55 +23,47 @@
2323

2424
package com.iluwatar.subclasssandbox;
2525

26+
import com.github.stefanbirkner.systemlambda.Statement;
2627
import org.junit.Assert;
27-
import org.junit.Rule;
2828
import org.junit.Test;
29-
import org.junit.contrib.java.lang.system.SystemOutRule;
29+
30+
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOutNormalized;
3031

3132
/**
3233
* SkyLaunch unit tests.
3334
*/
3435
public class SkyLaunchTest {
3536

36-
@Rule
37-
public SystemOutRule log = new SystemOutRule().enableLog();
38-
3937
@Test
40-
public void testMove() {
41-
log.clearLog();
38+
public void testMove() throws Exception {
4239
var skyLaunch = new SkyLaunch();
43-
skyLaunch.move(1.0, 1.0, 1.0);
44-
var outputLog = getLogContent(log.getLog());
40+
var outputLog = getLogContent(() -> skyLaunch.move(1.0, 1.0, 1.0));
4541
var expectedLog = "Move to ( 1.0, 1.0, 1.0 )";
4642
Assert.assertEquals(outputLog, expectedLog);
4743
}
4844

4945
@Test
50-
public void testPlaySound() {
51-
log.clearLog();
46+
public void testPlaySound() throws Exception {
5247
var skyLaunch = new SkyLaunch();
53-
skyLaunch.playSound("SOUND_NAME", 1);
54-
var outputLog = getLogContent(log.getLog());
48+
var outputLog = getLogContent(() -> skyLaunch.playSound("SOUND_NAME", 1));
5549
var expectedLog = "Play SOUND_NAME with volumn 1";
5650
Assert.assertEquals(outputLog, expectedLog);
5751
}
5852

5953
@Test
60-
public void testSpawnParticles() {
61-
log.clearLog();
54+
public void testSpawnParticles() throws Exception {
6255
var skyLaunch = new SkyLaunch();
63-
skyLaunch.spawnParticles("PARTICLE_TYPE", 100);
64-
var outputLog = getLogContent(log.getLog());
56+
var outputLog = getLogContent(
57+
() -> skyLaunch.spawnParticles("PARTICLE_TYPE", 100));
6558
var expectedLog = "Spawn 100 particle with type PARTICLE_TYPE";
6659
Assert.assertEquals(outputLog, expectedLog);
6760
}
6861

6962
@Test
70-
public void testActivate() {
71-
log.clearLog();
63+
public void testActivate() throws Exception {
7264
var skyLaunch = new SkyLaunch();
73-
skyLaunch.activate();
74-
var logs = log.getLog().split("\n");
65+
var logs = tapSystemOutNormalized(skyLaunch::activate)
66+
.split("\n");
7567
final var expectedSize = 3;
7668
final var log1 = getLogContent(logs[0]);
7769
final var expectedLog1 = "Move to ( 0.0, 0.0, 20.0 )";
@@ -85,6 +77,11 @@ public void testActivate() {
8577
Assert.assertEquals(log3, expectedLog3);
8678
}
8779

80+
private String getLogContent(Statement statement) throws Exception {
81+
var log = tapSystemOutNormalized(statement);
82+
return getLogContent(log);
83+
}
84+
8885
private String getLogContent(String log) {
8986
return log.split("-")[1].trim();
9087
}

0 commit comments

Comments
 (0)