Skip to content

Commit 0a60536

Browse files
authored
chore: Apply code style. (#5)
1 parent 4368e02 commit 0a60536

File tree

8 files changed

+33
-52
lines changed

8 files changed

+33
-52
lines changed

src/main/java/com/launchdarkly/openfeature/serverprovider/Provider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public String getName() {
3636

3737
private final Metadata metaData = new ProviderMetaData();
3838

39-
private LDLogger logger;
40-
private EvaluationDetailConverter evaluationDetailConverter;
41-
private ValueConverter valueConverter;
42-
private EvaluationContextConverter evaluationContextConverter;
39+
private final LDLogger logger;
40+
private final EvaluationDetailConverter evaluationDetailConverter;
41+
private final ValueConverter valueConverter;
42+
private final EvaluationContextConverter evaluationContextConverter;
4343

44-
private LDClientInterface client;
44+
private final LDClientInterface client;
4545

4646
/**
4747
* Create a provider with the given LaunchDarkly client and provider configuration.

src/test/java/com/launchdarkly/openfeature/serverprovider/GivenAContextConverter.java renamed to src/test/java/com/launchdarkly/openfeature/serverprovider/ContextConverterTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import static org.junit.Assert.*;
1717

18-
public class GivenAContextConverter {
18+
public class ContextConverterTest {
1919
TestLogger testLogger = new TestLogger();
2020
EvaluationContextConverter evaluationContextConverter = new EvaluationContextConverter(
2121
LDLogger.withAdapter(testLogger, "test-logger")
@@ -31,7 +31,7 @@ public void itCanCreateAContextFromAKeyOnly() {
3131
LDContext converted = evaluationContextConverter.toLdContext(new ImmutableContext("the-key"));
3232
assertEquals(expectedContext, converted);
3333

34-
HashMap<String, Value> attributes = new HashMap();
34+
HashMap<String, Value> attributes = new HashMap<>();
3535
attributes.put("key", new Value("the-key"));
3636
LDContext convertedKey = evaluationContextConverter.toLdContext(new ImmutableContext(attributes));
3737
assertEquals(expectedContext, convertedKey);
@@ -44,7 +44,7 @@ public void itCanCreateAContextFromAKeyAndKind() {
4444
LDContext expectedContext = LDContext.builder(ContextKind.of("organization"), "org-key").build();
4545

4646
LDContext converted = evaluationContextConverter
47-
.toLdContext(new ImmutableContext("org-key", new HashMap() {{
47+
.toLdContext(new ImmutableContext("org-key", new HashMap<String, Value>() {{
4848
put("kind", new Value("organization"));
4949
}}));
5050

@@ -66,7 +66,7 @@ public void itLogsAnErrorWhenThereIsNoTargetingKey() {
6666
public void itGivesTargetingKeyPrecedence() {
6767
LDContext expectedContext = LDContext.builder("key-to-use").build();
6868

69-
HashMap<String, Value> attributes = new HashMap();
69+
HashMap<String, Value> attributes = new HashMap<>();
7070
attributes.put("key", new Value("key-not-to-use"));
7171

7272
LDContext converted = evaluationContextConverter.toLdContext(
@@ -80,7 +80,7 @@ public void itGivesTargetingKeyPrecedence() {
8080

8181
@Test
8282
public void itHandlesAKeyOfIncorrectType() {
83-
HashMap<String, Value> attributes = new HashMap();
83+
HashMap<String, Value> attributes = new HashMap<>();
8484
attributes.put("key", new Value(0));
8585

8686
evaluationContextConverter.toLdContext(
@@ -98,7 +98,7 @@ public void itHandlesAKeyOfIncorrectType() {
9898
public void itHandlesInvalidBuiltInAttributes() {
9999
LDContext expectedContext = LDContext.builder("user-key").build();
100100

101-
HashMap<String, Value> attributes = new HashMap();
101+
HashMap<String, Value> attributes = new HashMap<>();
102102
attributes.put("name", new Value(3));
103103
attributes.put("anonymous", new Value("potato"));
104104
// The attributes were not valid, so they should be discarded.
@@ -123,7 +123,7 @@ public void itHandlesValidBuiltInAttributes() {
123123
.anonymous(true)
124124
.build();
125125

126-
HashMap<String, Value> attributes = new HashMap();
126+
HashMap<String, Value> attributes = new HashMap<>();
127127
attributes.put("name", new Value("the-name"));
128128
attributes.put("anonymous", new Value(true));
129129

@@ -148,17 +148,17 @@ public void itCanCreateAValidMultiKindContext() {
148148
.build()
149149
);
150150

151-
EvaluationContext evaluationContext = new ImmutableContext(new HashMap() {{
151+
EvaluationContext evaluationContext = new ImmutableContext(new HashMap<String, Value>() {{
152152
put("kind", new Value("multi"));
153-
put("organization", new Value(new ImmutableStructure(new HashMap() {{
153+
put("organization", new Value(new ImmutableStructure(new HashMap<String, Value>() {{
154154
put("name", new Value("the-org-name"));
155155
put("targetingKey", new Value("my-org-key"));
156156
put("myCustomAttribute", new Value("myAttributeValue"));
157157
put("privateAttributes", new Value(new ArrayList<Value>() {{
158158
add(new Value("myCustomAttribute"));
159159
}}));
160160
}})));
161-
put("user", new Value(new ImmutableStructure(new HashMap() {{
161+
put("user", new Value(new ImmutableStructure(new HashMap<String, Value>() {{
162162
put("key", new Value("my-user-key"));
163163
put("anonymous", new Value(true));
164164
put("myCustomAttribute", new Value("myAttributeValue"));
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,21 @@
99

1010
import static org.junit.Assert.*;
1111

12-
public class GivenAnEvaluationDetailConverter {
12+
public class EvaluationDetailConverterTest {
1313
private final Double EPSILON = 0.00001;
1414
TestLogger testLogger = new TestLogger();
1515
EvaluationDetailConverter evaluationDetailConverter = new EvaluationDetailConverter(
1616
LDLogger.withAdapter(testLogger, "test-logger")
1717
);
1818

19-
private TestLogger.TestChannel logs() {
20-
return testLogger.getChannel("test-logger");
21-
}
22-
2319
@Test
2420
public void itCanConvertDoubleEvaluationDetail() {
2521
EvaluationDetail<Double> inputDetail = EvaluationDetail.fromValue(
2622
3.0, 17, EvaluationReason.off());
2723

2824
ProviderEvaluation<Double> converted = evaluationDetailConverter.toEvaluationDetails(inputDetail);
2925

30-
assertEquals(3.0, converted.getValue().doubleValue(), EPSILON);
26+
assertEquals(3.0, converted.getValue(), EPSILON);
3127
assertEquals("17", converted.getVariant());
3228
assertEquals(Reason.DISABLED.toString(), converted.getReason());
3329
}
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44
import com.launchdarkly.sdk.ArrayBuilder;
55
import com.launchdarkly.sdk.LDValue;
66
import com.launchdarkly.sdk.ObjectBuilder;
7-
import dev.openfeature.sdk.ImmutableStructure;
87
import dev.openfeature.sdk.Structure;
98
import dev.openfeature.sdk.Value;
109
import org.junit.Test;
1110

12-
import java.util.ArrayList;
13-
import java.util.HashMap;
1411
import java.util.List;
1512

1613
import static org.junit.Assert.*;
1714

18-
public class GivenAnLdValueConverter {
19-
private LDValueConverter valueConverter = new LDValueConverter(LDLogger.none());
15+
public class LdValueConverterTest {
16+
private final LDValueConverter valueConverter = new LDValueConverter(LDLogger.none());
2017
private final Double EPSILON = 0.00001;
2118

2219
@Test
@@ -77,13 +74,6 @@ public void itCanConvertLists() {
7774

7875
@Test
7976
public void itCanConvertStructures() {
80-
Value ofValueStructure = new Value(new ImmutableStructure(new HashMap<String, Value>(){{
81-
put("aKey", new Value("aValue"));
82-
put("structKey", new Value(new ImmutableStructure(new HashMap<String, Value>(){{
83-
put("bKey", new Value("bValue"));
84-
}})));
85-
}}));
86-
8777
LDValue ldStructValue = new ObjectBuilder()
8878
.put("aKey", "aValue")
8979
.put("structKey", new ObjectBuilder().put("bKey", "bValue").build()).build();

src/test/java/com/launchdarkly/openfeature/serverprovider/ProviderConfigurationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.launchdarkly.openfeature.serverprovider;
22

3-
import com.launchdarkly.logging.LDLogAdapter;
43
import com.launchdarkly.logging.LDLogLevel;
54
import com.launchdarkly.logging.LDLogger;
65
import com.launchdarkly.sdk.server.Components;
76
import com.launchdarkly.sdk.server.subsystems.LoggingConfiguration;
87
import org.junit.Test;
98

10-
import static org.junit.Assert.*;
9+
import static org.junit.Assert.assertNotNull;
10+
import static org.junit.Assert.assertTrue;
1111

1212

1313
public class ProviderConfigurationTests {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import static org.mockito.Mockito.*;
1212
import static org.junit.Assert.*;
1313

14-
public class GivenAProviderWithMockLdClient {
14+
public class ProviderTest {
1515
LDClientInterface mockedLdClient = mock(LDClientInterface.class);
1616
Provider ldProvider = new Provider(mockedLdClient);
1717

src/test/java/com/launchdarkly/openfeature/serverprovider/TestLogger.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.launchdarkly.logging.LDLogAdapter;
44
import com.launchdarkly.logging.LDLogLevel;
5-
import jdk.nashorn.internal.runtime.regexp.joni.Regex;
65

76
import java.util.ArrayList;
87
import java.util.HashMap;
@@ -12,16 +11,15 @@
1211
* and validate the content of those messages.
1312
*/
1413
class TestLogger implements LDLogAdapter {
15-
private HashMap<String, TestChannel> channels = new HashMap<>();
14+
private final HashMap<String, TestChannel> channels = new HashMap<>();
1615

1716
public TestChannel getChannel(String name) {
1817
return channels.get(name);
1918
}
2019

21-
public class TestChannel implements Channel {
22-
private String name;
20+
public static class TestChannel implements Channel {
2321

24-
private HashMap<LDLogLevel, ArrayList<String>> messages = new HashMap();
22+
private final HashMap<LDLogLevel, ArrayList<String>> messages = new HashMap<>();
2523

2624
public int countForLevel(LDLogLevel level) {
2725
if (messages.containsKey(level)) {
@@ -32,9 +30,7 @@ public int countForLevel(LDLogLevel level) {
3230

3331
public boolean expectedMessageInLevel(LDLogLevel level, String regexString) {
3432
if (messages.containsKey(level)) {
35-
return messages.get(level).stream().anyMatch(value -> {
36-
return value.matches(regexString);
37-
});
33+
return messages.get(level).stream().anyMatch(value -> value.matches(regexString));
3834
}
3935
return false;
4036
}
@@ -43,12 +39,11 @@ public boolean containsAnyLogs() {
4339
return messages.size() != 0;
4440
}
4541

46-
private TestChannel(String name) {
47-
this.name = name;
42+
private TestChannel(String ignoredName) {
4843
}
4944

5045
private void addMessage(LDLogLevel ldLogLevel, String message) {
51-
ArrayList<String> forLevel = messages.getOrDefault(ldLogLevel, new ArrayList());
46+
ArrayList<String> forLevel = messages.getOrDefault(ldLogLevel, new ArrayList<>());
5247

5348
forLevel.add(message);
5449

src/test/java/com/launchdarkly/openfeature/serverprovider/GivenAValueConverter.java renamed to src/test/java/com/launchdarkly/openfeature/serverprovider/ValueConverterTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import static org.junit.Assert.*;
1616

17-
public class GivenAValueConverter {
18-
private ValueConverter valueConverter = new ValueConverter(LDLogger.none());
17+
public class ValueConverterTest {
18+
private final ValueConverter valueConverter = new ValueConverter(LDLogger.none());
1919
private final Double EPSILON = 0.00001;
2020

2121
@Test
@@ -70,7 +70,7 @@ public void itCanConvertLists() {
7070
}});
7171

7272
LDValue ldValue = valueConverter.toLdValue(ofValueList);
73-
List<LDValue> ldValueList = new ArrayList();
73+
List<LDValue> ldValueList = new ArrayList<>();
7474
ldValue.values().forEach(ldValueList::add);
7575

7676
assertEquals(5, ldValueList.size());
@@ -93,10 +93,10 @@ public void itCanConvertStructures() {
9393

9494
LDValue ldValue = valueConverter.toLdValue(ofValueStructure);
9595

96-
List<String> keyList = new ArrayList();
96+
List<String> keyList = new ArrayList<>();
9797
ldValue.keys().forEach(keyList::add);
9898

99-
List<LDValue> valueList = new ArrayList();
99+
List<LDValue> valueList = new ArrayList<>();
100100
ldValue.values().forEach(valueList::add);
101101

102102
assertEquals("aKey", keyList.get(0));

0 commit comments

Comments
 (0)