Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public String getName() {

private final Metadata metaData = new ProviderMetaData();

private LDLogger logger;
private EvaluationDetailConverter evaluationDetailConverter;
private ValueConverter valueConverter;
private EvaluationContextConverter evaluationContextConverter;
private final LDLogger logger;
private final EvaluationDetailConverter evaluationDetailConverter;
private final ValueConverter valueConverter;
private final EvaluationContextConverter evaluationContextConverter;

private LDClientInterface client;
private final LDClientInterface client;

/**
* Create a provider with the given LaunchDarkly client and provider configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import static org.junit.Assert.*;

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

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

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

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

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

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

@Test
public void itHandlesAKeyOfIncorrectType() {
HashMap<String, Value> attributes = new HashMap();
HashMap<String, Value> attributes = new HashMap<>();
attributes.put("key", new Value(0));

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

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

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

Expand All @@ -148,17 +148,17 @@ public void itCanCreateAValidMultiKindContext() {
.build()
);

EvaluationContext evaluationContext = new ImmutableContext(new HashMap() {{
EvaluationContext evaluationContext = new ImmutableContext(new HashMap<String, Value>() {{
put("kind", new Value("multi"));
put("organization", new Value(new ImmutableStructure(new HashMap() {{
put("organization", new Value(new ImmutableStructure(new HashMap<String, Value>() {{
put("name", new Value("the-org-name"));
put("targetingKey", new Value("my-org-key"));
put("myCustomAttribute", new Value("myAttributeValue"));
put("privateAttributes", new Value(new ArrayList<Value>() {{
add(new Value("myCustomAttribute"));
}}));
}})));
put("user", new Value(new ImmutableStructure(new HashMap() {{
put("user", new Value(new ImmutableStructure(new HashMap<String, Value>() {{
put("key", new Value("my-user-key"));
put("anonymous", new Value(true));
put("myCustomAttribute", new Value("myAttributeValue"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@

import static org.junit.Assert.*;

public class GivenAnEvaluationDetailConverter {
public class EvaluationDetailConverterTest {
private final Double EPSILON = 0.00001;
TestLogger testLogger = new TestLogger();
EvaluationDetailConverter evaluationDetailConverter = new EvaluationDetailConverter(
LDLogger.withAdapter(testLogger, "test-logger")
);

private TestLogger.TestChannel logs() {
return testLogger.getChannel("test-logger");
}

@Test
public void itCanConvertDoubleEvaluationDetail() {
EvaluationDetail<Double> inputDetail = EvaluationDetail.fromValue(
3.0, 17, EvaluationReason.off());

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

assertEquals(3.0, converted.getValue().doubleValue(), EPSILON);
assertEquals(3.0, converted.getValue(), EPSILON);
assertEquals("17", converted.getVariant());
assertEquals(Reason.DISABLED.toString(), converted.getReason());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
import com.launchdarkly.sdk.ArrayBuilder;
import com.launchdarkly.sdk.LDValue;
import com.launchdarkly.sdk.ObjectBuilder;
import dev.openfeature.sdk.ImmutableStructure;
import dev.openfeature.sdk.Structure;
import dev.openfeature.sdk.Value;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static org.junit.Assert.*;

public class GivenAnLdValueConverter {
private LDValueConverter valueConverter = new LDValueConverter(LDLogger.none());
public class LdValueConverterTest {
private final LDValueConverter valueConverter = new LDValueConverter(LDLogger.none());
private final Double EPSILON = 0.00001;

@Test
Expand Down Expand Up @@ -77,13 +74,6 @@ public void itCanConvertLists() {

@Test
public void itCanConvertStructures() {
Value ofValueStructure = new Value(new ImmutableStructure(new HashMap<String, Value>(){{
put("aKey", new Value("aValue"));
put("structKey", new Value(new ImmutableStructure(new HashMap<String, Value>(){{
put("bKey", new Value("bValue"));
}})));
}}));

LDValue ldStructValue = new ObjectBuilder()
.put("aKey", "aValue")
.put("structKey", new ObjectBuilder().put("bKey", "bValue").build()).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.launchdarkly.openfeature.serverprovider;

import com.launchdarkly.logging.LDLogAdapter;
import com.launchdarkly.logging.LDLogLevel;
import com.launchdarkly.logging.LDLogger;
import com.launchdarkly.sdk.server.Components;
import com.launchdarkly.sdk.server.subsystems.LoggingConfiguration;
import org.junit.Test;

import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;


public class ProviderConfigurationTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;

public class GivenAProviderWithMockLdClient {
public class ProviderTest {
LDClientInterface mockedLdClient = mock(LDClientInterface.class);
Provider ldProvider = new Provider(mockedLdClient);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.launchdarkly.logging.LDLogAdapter;
import com.launchdarkly.logging.LDLogLevel;
import jdk.nashorn.internal.runtime.regexp.joni.Regex;

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

public TestChannel getChannel(String name) {
return channels.get(name);
}

public class TestChannel implements Channel {
private String name;
public static class TestChannel implements Channel {

private HashMap<LDLogLevel, ArrayList<String>> messages = new HashMap();
private final HashMap<LDLogLevel, ArrayList<String>> messages = new HashMap<>();

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

public boolean expectedMessageInLevel(LDLogLevel level, String regexString) {
if (messages.containsKey(level)) {
return messages.get(level).stream().anyMatch(value -> {
return value.matches(regexString);
});
return messages.get(level).stream().anyMatch(value -> value.matches(regexString));
}
return false;
}
Expand All @@ -43,12 +39,11 @@ public boolean containsAnyLogs() {
return messages.size() != 0;
}

private TestChannel(String name) {
this.name = name;
private TestChannel(String ignoredName) {
}

private void addMessage(LDLogLevel ldLogLevel, String message) {
ArrayList<String> forLevel = messages.getOrDefault(ldLogLevel, new ArrayList());
ArrayList<String> forLevel = messages.getOrDefault(ldLogLevel, new ArrayList<>());

forLevel.add(message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import static org.junit.Assert.*;

public class GivenAValueConverter {
private ValueConverter valueConverter = new ValueConverter(LDLogger.none());
public class ValueConverterTest {
private final ValueConverter valueConverter = new ValueConverter(LDLogger.none());
private final Double EPSILON = 0.00001;

@Test
Expand Down Expand Up @@ -70,7 +70,7 @@ public void itCanConvertLists() {
}});

LDValue ldValue = valueConverter.toLdValue(ofValueList);
List<LDValue> ldValueList = new ArrayList();
List<LDValue> ldValueList = new ArrayList<>();
ldValue.values().forEach(ldValueList::add);

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

LDValue ldValue = valueConverter.toLdValue(ofValueStructure);

List<String> keyList = new ArrayList();
List<String> keyList = new ArrayList<>();
ldValue.keys().forEach(keyList::add);

List<LDValue> valueList = new ArrayList();
List<LDValue> valueList = new ArrayList<>();
ldValue.values().forEach(valueList::add);

assertEquals("aKey", keyList.get(0));
Expand Down