Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #243 from launchdarkly/eb/ch77639/int-double-non-null
Browse files Browse the repository at this point in the history
(5.0 - #7) make intVariation and doubleVariation non-nullable
  • Loading branch information
eli-darkly authored May 29, 2020
2 parents bd2162e + b3f313c commit daf04c4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/launchdarkly/sdk/server/LDClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ public boolean boolVariation(String featureKey, LDUser user, boolean defaultValu
}

@Override
public Integer intVariation(String featureKey, LDUser user, int defaultValue) {
public int intVariation(String featureKey, LDUser user, int defaultValue) {
return evaluate(featureKey, user, LDValue.of(defaultValue), true).intValue();
}

@Override
public Double doubleVariation(String featureKey, LDUser user, Double defaultValue) {
public double doubleVariation(String featureKey, LDUser user, double defaultValue) {
return evaluate(featureKey, user, LDValue.of(defaultValue), true).doubleValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public interface LDClientInterface extends Closeable {
* @param defaultValue the default value of the flag
* @return the variation for the given user, or {@code defaultValue} if the flag is disabled in the LaunchDarkly control panel
*/
Integer intVariation(String featureKey, LDUser user, int defaultValue);
int intVariation(String featureKey, LDUser user, int defaultValue);

/**
* Calculates the floating point numeric value of a feature flag for a given user.
Expand All @@ -115,7 +115,7 @@ public interface LDClientInterface extends Closeable {
* @param defaultValue the default value of the flag
* @return the variation for the given user, or {@code defaultValue} if the flag is disabled in the LaunchDarkly control panel
*/
Double doubleVariation(String featureKey, LDUser user, Double defaultValue);
double doubleVariation(String featureKey, LDUser user, double defaultValue);

/**
* Calculates the String value of a feature flag for a given user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public void boolVariationReturnsDefaultValueForWrongType() throws Exception {
public void intVariationReturnsFlagValue() throws Exception {
upsertFlag(dataStore, flagWithValue("key", LDValue.of(2)));

assertEquals(new Integer(2), client.intVariation("key", user, 1));
assertEquals(2, client.intVariation("key", user, 1));
}

@Test
public void intVariationReturnsFlagValueEvenIfEncodedAsDouble() throws Exception {
upsertFlag(dataStore, flagWithValue("key", LDValue.of(2.0)));

assertEquals(new Integer(2), client.intVariation("key", user, 1));
assertEquals(2, client.intVariation("key", user, 1));
}

@Test
Expand All @@ -92,48 +92,48 @@ public void intVariationFromDoubleRoundsTowardZero() throws Exception {
upsertFlag(dataStore, flagWithValue("flag3", LDValue.of(-2.25)));
upsertFlag(dataStore, flagWithValue("flag4", LDValue.of(-2.75)));

assertEquals(new Integer(2), client.intVariation("flag1", user, 1));
assertEquals(new Integer(2), client.intVariation("flag2", user, 1));
assertEquals(new Integer(-2), client.intVariation("flag3", user, 1));
assertEquals(new Integer(-2), client.intVariation("flag4", user, 1));
assertEquals(2, client.intVariation("flag1", user, 1));
assertEquals(2, client.intVariation("flag2", user, 1));
assertEquals(-2, client.intVariation("flag3", user, 1));
assertEquals(-2, client.intVariation("flag4", user, 1));
}

@Test
public void intVariationReturnsDefaultValueForUnknownFlag() throws Exception {
assertEquals(new Integer(1), client.intVariation("key", user, 1));
assertEquals(1, client.intVariation("key", user, 1));
}

@Test
public void intVariationReturnsDefaultValueForWrongType() throws Exception {
upsertFlag(dataStore, flagWithValue("key", LDValue.of("wrong")));

assertEquals(new Integer(1), client.intVariation("key", user, 1));
assertEquals(1, client.intVariation("key", user, 1));
}

@Test
public void doubleVariationReturnsFlagValue() throws Exception {
upsertFlag(dataStore, flagWithValue("key", LDValue.of(2.5d)));

assertEquals(new Double(2.5d), client.doubleVariation("key", user, 1.0d));
assertEquals(2.5d, client.doubleVariation("key", user, 1.0d), 0d);
}

@Test
public void doubleVariationReturnsFlagValueEvenIfEncodedAsInt() throws Exception {
upsertFlag(dataStore, flagWithValue("key", LDValue.of(2)));

assertEquals(new Double(2.0d), client.doubleVariation("key", user, 1.0d));
assertEquals(2.0d, client.doubleVariation("key", user, 1.0d), 0d);
}

@Test
public void doubleVariationReturnsDefaultValueForUnknownFlag() throws Exception {
assertEquals(new Double(1.0d), client.doubleVariation("key", user, 1.0d));
assertEquals(1.0d, client.doubleVariation("key", user, 1.0d), 0d);
}

@Test
public void doubleVariationReturnsDefaultValueForWrongType() throws Exception {
upsertFlag(dataStore, flagWithValue("key", LDValue.of("wrong")));

assertEquals(new Double(1.0d), client.doubleVariation("key", user, 1.0d));
assertEquals(1.0d, client.doubleVariation("key", user, 1.0d), 0d);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public void evaluationUsesStoreIfStoreIsInitializedButClientIsNot() throws Excep
client = createMockClient(config);

upsertFlag(testDataStore, flagWithValue("key", LDValue.of(1)));
assertEquals(new Integer(1), client.intVariation("key", new LDUser("user"), 0));
assertEquals(1, client.intVariation("key", new LDUser("user"), 0));

verifyAll();
}
Expand Down

0 comments on commit daf04c4

Please sign in to comment.