Skip to content

Commit e6f07ac

Browse files
authored
Use system-lambda instead of system-rules. (#554)
1 parent e7fe366 commit e6f07ac

File tree

4 files changed

+26
-31
lines changed

4 files changed

+26
-31
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ subprojects {
9292

9393
dependencies {
9494
dependency 'com.google.guava:guava:' + ext['guava.version']
95-
dependency 'com.github.stefanbirkner:system-rules:1.19.0'
95+
dependency 'com.github.stefanbirkner:system-lambda:1.0.0'
9696
dependencySet(group: 'com.squareup.retrofit2', version: ext['retrofit.version']) {
9797
entry 'converter-jackson'
9898
entry 'retrofit'
@@ -110,7 +110,7 @@ subprojects {
110110
// http://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html#configuration-metadata-annotation-processor
111111

112112
testImplementation 'com.google.guava:guava'
113-
testImplementation 'com.github.stefanbirkner:system-rules'
113+
testImplementation 'com.github.stefanbirkner:system-lambda'
114114
testImplementation 'com.squareup.okhttp3:mockwebserver'
115115
testImplementation 'org.hibernate.validator:hibernate-validator'
116116
testImplementation 'org.springframework.boot:spring-boot-starter-test' // MockHttpServletRequest

line-bot-api-client/src/test/java/com/linecorp/bot/client/exception/LineMessagingExceptionTest.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,26 @@
1616

1717
package com.linecorp.bot.client.exception;
1818

19+
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOut;
1920
import static java.util.Collections.emptyList;
2021
import static org.assertj.core.api.Assertions.assertThat;
2122

22-
import org.junit.Rule;
2323
import org.junit.Test;
24-
import org.junit.contrib.java.lang.system.SystemOutRule;
2524

2625
import com.linecorp.bot.model.error.ErrorResponse;
2726

2827
import lombok.extern.slf4j.Slf4j;
2928

3029
@Slf4j
3130
public class LineMessagingExceptionTest {
32-
@Rule
33-
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();
34-
3531
@Test
36-
public void errorResponseIncludedInMessageTest() {
32+
public void errorResponseIncludedInMessageTest() throws Exception {
3733
final ErrorResponse errorResponse = new ErrorResponse("requestId_in_response", null, emptyList());
3834
final BadRequestException exception = new BadRequestException("Message", errorResponse);
3935

40-
log.error("", exception);
36+
String systemOut = tapSystemOut(() -> log.error("", exception));
4137

42-
assertThat(systemOutRule.getLogWithNormalizedLineSeparator())
38+
assertThat(systemOut)
4339
.contains("requestId_in_response")
4440
.contains(errorResponse.toString());
4541
}

line-bot-cli/src/test/java/com/linecorp/bot/cli/ApplicationTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@
1616

1717
package com.linecorp.bot.cli;
1818

19+
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOut;
1920
import static org.assertj.core.api.Assertions.assertThat;
2021

21-
import org.junit.Rule;
2222
import org.junit.Test;
23-
import org.junit.contrib.java.lang.system.SystemOutRule;
2423

2524
public class ApplicationTest {
26-
@Rule
27-
public final SystemOutRule systemOut = new SystemOutRule().enableLog();
28-
2925
@Test
3026
public void contextStartupTest() throws Exception {
31-
Application.main("--line.bot.channel-secret=xxx", "--line.bot.channel-token=token");
27+
String systemOut = tapSystemOut(
28+
() -> Application.main("--line.bot.channel-secret=xxx", "--line.bot.channel-token=token"));
3229

33-
assertThat(systemOut.getLogWithNormalizedLineSeparator())
30+
assertThat(systemOut)
3431
.contains("No command resolved.");
3532
}
3633
}

line-bot-spring-boot/src/test/java/com/linecorp/bot/spring/boot/support/ReplyByReturnValueConsumerTest.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.linecorp.bot.spring.boot.support;
1818

19+
import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOut;
1920
import static java.util.Collections.singletonList;
2021
import static java.util.concurrent.CompletableFuture.completedFuture;
2122
import static org.assertj.core.api.Assertions.assertThat;
@@ -32,7 +33,6 @@
3233
import org.junit.Before;
3334
import org.junit.Rule;
3435
import org.junit.Test;
35-
import org.junit.contrib.java.lang.system.SystemOutRule;
3636
import org.mockito.InjectMocks;
3737
import org.mockito.Mock;
3838
import org.mockito.junit.MockitoJUnit;
@@ -52,9 +52,6 @@ public class ReplyByReturnValueConsumerTest {
5252
@Rule
5353
public final MockitoRule mockitoRule = MockitoJUnit.rule();
5454

55-
@Rule
56-
public final SystemOutRule systemOut = new SystemOutRule().enableLog();
57-
5855
@Mock
5956
private LineMessagingClient lineMessagingClient;
6057

@@ -121,32 +118,37 @@ public void acceptCompletableListReplyTest() throws Exception {
121118
}
122119

123120
@Test
124-
public void errorInCompletableLoggingTest() {
121+
public void errorInCompletableLoggingTest() throws Exception {
125122
// Do
126-
final CompletableFuture<List<TextMessage>> returnValue = new CompletableFuture<>();
127-
target.accept(returnValue);
128-
returnValue.completeExceptionally(new GeneralLineMessagingException("EXCEPTION HAPPEN!", null, null));
123+
String systemOut = tapSystemOut(() -> {
124+
final CompletableFuture<List<TextMessage>> returnValue = new CompletableFuture<>();
125+
target.accept(returnValue);
126+
returnValue.completeExceptionally(
127+
new GeneralLineMessagingException("EXCEPTION HAPPEN!", null, null));
128+
});
129129

130130
// Verify
131-
assertThat(systemOut.getLogWithNormalizedLineSeparator())
131+
assertThat(systemOut)
132132
.contains("EXCEPTION HAPPEN!");
133133
}
134134

135135
@Test
136-
public void errorInLineMessagingClientLoggingTest() {
136+
public void errorInLineMessagingClientLoggingTest() throws Exception {
137137
reset(lineMessagingClient);
138138
when(lineMessagingClient.replyMessage(any()))
139139
.thenReturn(new CompletableFuture<BotApiResponse>() {{
140140
completeExceptionally(new GeneralLineMessagingException("EXCEPTION HAPPEN!", null, null));
141141
}});
142142

143143
// Do
144-
final CompletableFuture<List<TextMessage>> returnValue = new CompletableFuture<>();
145-
target.accept(returnValue);
146-
returnValue.complete(singletonList(new TextMessage("Reply Text")));
144+
String systemOut = tapSystemOut(() -> {
145+
final CompletableFuture<List<TextMessage>> returnValue = new CompletableFuture<>();
146+
target.accept(returnValue);
147+
returnValue.complete(singletonList(new TextMessage("Reply Text")));
148+
});
147149

148150
// Verify
149-
assertThat(systemOut.getLogWithNormalizedLineSeparator())
151+
assertThat(systemOut)
150152
.contains("failed")
151153
.contains("EXCEPTION HAPPEN!");
152154
}

0 commit comments

Comments
 (0)