Skip to content

Commit 8f7c601

Browse files
authored
[16] Tests for logging to validate 1.4.10 (#1)
-removes dependency to log4j binding for slf4j, so clients can choose a different binding -adds dependency to slf4j-api -adds test logging binding by adding (test) dependency to uk.org.lidalia:slf4j-test -adds (test) dependency to assertj for better readable assertions
1 parent 62504b7 commit 8f7c601

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

lib/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@ repositories {
2626
}
2727

2828
dependencies {
29-
implementation 'org.slf4j:slf4j-log4j12:1.7.36'
3029
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.2.1'
30+
implementation 'org.slf4j:slf4j-api:1.7.36'
3131

3232
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
3333
implementation 'com.google.guava:guava:30.1.1-jre'
3434

3535
// Use JUnit Jupiter for testing.
3636
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
3737
testImplementation 'org.mockito:mockito-core:4+'
38+
testImplementation 'uk.org.lidalia:slf4j-test:1.1.0'
39+
testImplementation 'org.assertj:assertj-core:3.23.1'
3840

3941
// This dependency is exported to consumers, that is to say found on their compile classpath.
4042
api 'org.apache.commons:commons-math3:3.6.1'
@@ -121,4 +123,4 @@ publishing {
121123
url = repo_url
122124
}
123125
}
124-
}
126+
}

lib/src/test/java/dev/openfeature/javasdk/FlagEvaluationSpecTests.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
package dev.openfeature.javasdk;
22

3-
import org.junit.jupiter.api.Disabled;
4-
import org.junit.jupiter.api.Test;
3+
import org.junit.jupiter.api.*;
4+
import org.slf4j.*;
5+
import uk.org.lidalia.slf4jtest.*;
56

67
import java.util.List;
78

9+
import static org.assertj.core.api.Assertions.assertThat;
810
import static org.junit.jupiter.api.Assertions.*;
911
import static org.mockito.Mockito.*;
1012

11-
public class FlagEvaluationSpecTests {
13+
class FlagEvaluationSpecTests {
1214

13-
Client _client() {
15+
private static final TestLogger TEST_LOGGER = TestLoggerFactory.getTestLogger(OpenFeatureClient.class);
16+
17+
private Client _client() {
1418
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
1519
api.setProvider(new NoOpProvider());
1620
return api.getClient();
@@ -160,10 +164,16 @@ Client _client() {
160164
FlagEvaluationDetails<Boolean> details = c.getBooleanDetails("key", false);
161165
assertEquals("BORK", details.getErrorCode());
162166
}
167+
163168
@Specification(number="1.4.10", text="In the case of abnormal execution, the client SHOULD log an informative error message.")
164-
@Disabled("Not actually sure how to mock out the slf4j logger")
165169
@Test void log_on_error() throws NotImplementedException {
166-
throw new NotImplementedException("Dunno.");
170+
TEST_LOGGER.clear();
171+
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
172+
api.setProvider(new AlwaysBrokenProvider());
173+
Client c = api.getClient();
174+
FlagEvaluationDetails<Boolean> result = c.getBooleanDetails("test", false);
175+
assertEquals(Reason.ERROR, result.getReason());
176+
assertThat(TEST_LOGGER.getLoggingEvents()).contains(LoggingEvent.error("Unable to correctly evaluate flag with key {} due to exception {}", "test", "BORK"));
167177
}
168178

169179

0 commit comments

Comments
 (0)