Skip to content

Commit 1e7456a

Browse files
committed
Refactor and upgrade gradle.
1 parent 9f52cd7 commit 1e7456a

File tree

4 files changed

+29
-73
lines changed

4 files changed

+29
-73
lines changed

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip

src/main/java/com/logcapture/assertion/ExpectedLoggingMessage.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import static java.util.Collections.singleton;
2525
import static org.hamcrest.Matchers.equalTo;
2626

27-
public class ExpectedLoggingMessage extends TypeSafeMatcher<List<ILoggingEvent>>{
27+
public class ExpectedLoggingMessage extends TypeSafeMatcher<List<ILoggingEvent>> {
2828

2929
private Matcher<Level> logLevelMatcher = new TypedAnythingMatcher<>();
3030
private Matcher<Marker> markerMatcher = new TypedAnythingMatcher<>();
@@ -46,6 +46,10 @@ public ExpectedLoggingMessage withLevel(Matcher<Level> errorLevel) {
4646
return this;
4747
}
4848

49+
public ExpectedLoggingMessage withLevel(Level errorLevel) {
50+
return withLevel(equalTo(errorLevel));
51+
}
52+
4953
public ExpectedLoggingMessage withMarker(Matcher<Marker> marker) {
5054
markerMatcher = marker;
5155
return this;
@@ -58,12 +62,12 @@ protected boolean matchesSafely(List<ILoggingEvent> events) {
5862

5963
private boolean matches(ILoggingEvent event) {
6064
return logLevelMatcher.matches(event.getLevel()) &&
61-
markerMatcher.matches(event.getMarker()) &&
62-
expectedMessageMatcher.stream().allMatch(matcher -> matcher.matches(event.getFormattedMessage())) &&
63-
expectedLoggedException.matches(event) &&
64-
expectedLoggerNameMatcher.matches(event.getLoggerName()) &&
65-
expectedLengthMatcher.matches(event.getFormattedMessage().length()) &&
66-
matchesMdc(event.getMDCPropertyMap());
65+
markerMatcher.matches(event.getMarker()) &&
66+
expectedMessageMatcher.stream().allMatch(matcher -> matcher.matches(event.getFormattedMessage())) &&
67+
expectedLoggedException.matches(event) &&
68+
expectedLoggerNameMatcher.matches(event.getLoggerName()) &&
69+
expectedLengthMatcher.matches(event.getFormattedMessage().length()) &&
70+
matchesMdc(event.getMDCPropertyMap());
6771
}
6872

6973
public ExpectedLoggingMessage withMarker(Marker marker) {
@@ -96,7 +100,7 @@ public ExpectedLoggingMessage error() {
96100

97101
private boolean matchesMdc(Map<String, String> mdcPropertyMap) {
98102
return mdcMatcher.entrySet().stream()
99-
.allMatch(entry -> entry.getValue().matches(mdcPropertyMap.get(entry.getKey())));
103+
.allMatch(entry -> entry.getValue().matches(mdcPropertyMap.get(entry.getKey())));
100104
}
101105

102106
public final ExpectedLoggingMessage withMessage(Matcher<String> expectedMessages) {
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,40 @@
11
package com.logcapture.spock
22

33
import com.logcapture.junit.LogCaptureRuleShould
4-
import org.slf4j.Logger
54
import org.slf4j.LoggerFactory
65
import spock.lang.Shared
76

87
import static ch.qos.logback.classic.Level.DEBUG
98
import static ch.qos.logback.classic.Level.INFO
109
import static com.logcapture.assertion.ExpectedLoggingMessage.aLog
11-
import static org.hamcrest.Matchers.*
10+
import static org.hamcrest.Matchers.allOf
11+
import static org.hamcrest.Matchers.equalTo
12+
import static org.hamcrest.Matchers.not
1213

1314
class LogCaptureSpecShould extends LogCaptureSpec {
1415

15-
private static final String LOG_NAME = "aLogNotAttachedToRoot"
1616
@Shared log = LoggerFactory.getLogger(LogCaptureRuleShould.class)
1717

18-
def "verify_missing_events"() {
18+
def "verify missing events"() {
1919
expect:
2020
logged(not(aLog()
2121
.withLevel(equalTo(INFO))
2222
.withMessage(equalTo("missing message"))))
2323
}
2424

25-
def "verify_multiple_events"() {
25+
def "verify multiple events"() {
2626
expect:
2727
log.info("first message")
2828
log.debug("second message")
29-
logged(allOf(aLog().withLevel(equalTo(INFO)).withMessage(equalTo("first message")),
30-
aLog().withLevel(equalTo(DEBUG)).withMessage(equalTo("second message"))))
29+
logged allOf(
30+
aLog().withLevel(INFO).withMessage("first message"),
31+
aLog().withLevel(DEBUG).withMessage("second message"))
3132
}
3233

33-
def "verify_sync_logs_using_rule"() {
34+
def "verify sync logs using rule"() {
3435
expect:
3536
log.info("a message")
3637

3738
logged(aLog().info().withMessage("a message"))
3839
}
39-
40-
// @Test
41-
// void verify_log_when_is_not_in_root() {
42-
// Logger logNotInRoot = createLogger(LOG_NAME)
43-
//
44-
// logNotInRoot.info("a message")
45-
//
46-
// assertThatExceptionOfType(VerificationException.class)
47-
// .isThrownBy(() -> logCaptureRule.logged(aLog().info().withMessage("a message")))
48-
//
49-
// logCaptureRuleAttached.logged(aLog().info().withMessage("a message"))
50-
// }
51-
52-
private Logger createLogger(String name) {
53-
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(name)
54-
logger.setLevel(DEBUG)
55-
logger.setAdditive(false)
56-
return logger
57-
}
5840
}

src/test/groovy/com/logcapture/spock/LogCaptureTraitShould.groovy

+7-37
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,43 @@ package com.logcapture.spock
22

33
import com.logcapture.junit.LogCaptureRuleShould
44
import com.logcapture.junit.LogCaptureTrait
5-
import org.slf4j.Logger
65
import org.slf4j.LoggerFactory
76
import spock.lang.Shared
87
import spock.lang.Specification
98

109
import static ch.qos.logback.classic.Level.DEBUG
11-
import static ch.qos.logback.classic.Level.DEBUG
12-
import static ch.qos.logback.classic.Level.INFO
1310
import static ch.qos.logback.classic.Level.INFO
1411
import static com.logcapture.assertion.ExpectedLoggingMessage.aLog
15-
import static com.logcapture.assertion.ExpectedLoggingMessage.aLog
16-
import static com.logcapture.assertion.ExpectedLoggingMessage.aLog
17-
import static com.logcapture.assertion.ExpectedLoggingMessage.aLog
1812
import static org.hamcrest.Matchers.allOf
1913
import static org.hamcrest.Matchers.equalTo
20-
import static org.hamcrest.Matchers.equalTo
21-
import static org.hamcrest.Matchers.equalTo
22-
import static org.hamcrest.Matchers.equalTo
23-
import static org.hamcrest.Matchers.equalTo
24-
import static org.hamcrest.Matchers.equalTo
2514
import static org.hamcrest.Matchers.not
2615

2716
class LogCaptureTraitShould extends Specification implements LogCaptureTrait {
2817

29-
30-
private static final String LOG_NAME = "aLogNotAttachedToRoot"
3118
@Shared log = LoggerFactory.getLogger(LogCaptureRuleShould.class)
3219

33-
def "verify_missing_events"() {
20+
def "verify missing events"() {
3421
expect:
3522
logged(not(aLog()
3623
.withLevel(equalTo(INFO))
3724
.withMessage(equalTo("missing message"))))
3825
}
3926

40-
def "verify_multiple_events"() {
27+
def "verify multiple events"() {
4128
expect:
4229
log.info("first message")
4330
log.debug("second message")
44-
logged(allOf(aLog().withLevel(equalTo(INFO)).withMessage(equalTo("first message")),
45-
aLog().withLevel(equalTo(DEBUG)).withMessage(equalTo("second message"))))
31+
logged(allOf(
32+
aLog().withLevel(INFO).withMessage("first message"),
33+
aLog().withLevel(DEBUG).withMessage("second message"))
34+
)
4635
}
4736

48-
def "verify_sync_logs_using_rule"() {
37+
def "verify sync logs using rule"() {
4938
expect:
5039
log.info("a message")
5140

5241
logged(aLog().info().withMessage("a message"))
5342
}
5443

55-
// @Test
56-
// void verify_log_when_is_not_in_root() {
57-
// Logger logNotInRoot = createLogger(LOG_NAME)
58-
//
59-
// logNotInRoot.info("a message")
60-
//
61-
// assertThatExceptionOfType(VerificationException.class)
62-
// .isThrownBy(() -> logCaptureRule.logged(aLog().info().withMessage("a message")))
63-
//
64-
// logCaptureRuleAttached.logged(aLog().info().withMessage("a message"))
65-
// }
66-
67-
private Logger createLogger(String name) {
68-
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(name)
69-
logger.setLevel(DEBUG)
70-
logger.setAdditive(false)
71-
return logger
72-
}
73-
7444
}

0 commit comments

Comments
 (0)