Commit 99914daa authored by Rajiv Prabhakar's avatar Rajiv Prabhakar
Browse files

v2.0.12: DynamicConstant.isSet bug fix

parent 7dcaea16
Pipeline #34902792 passed with stage
in 1 minute and 43 seconds
......@@ -6,7 +6,7 @@
<groupId>com.rajivprab</groupId>
<artifactId>cava</artifactId>
<version>2.0.11</version>
<version>2.0.12</version>
<name>Cava: Clean Java</name>
<description>A library that enables users to write minimal, clean and simple Java</description>
......
......@@ -61,7 +61,7 @@ public class DynamicConstant<T> {
// Returns true if the value has been permanently set to any user-supplied value, or the default
// If value has never been set, the default is not invoked
public boolean isSet() {
return value.get() == null;
return value.get() != null;
}
// If set is called with data that is incompatible with the previous get/set calls,
......
......@@ -19,14 +19,19 @@ public class DynamicConstantTest extends TestBase {
@Test
public void lazyDefaultShouldNeverGetCalled_ifSetIsInvoked() {
DynamicConstant<String> dynamicConstant = DynamicConstant.lazyDefault(() -> LandmineHolder.VAL);
assertThat(dynamicConstant.isSet()).isFalse();
assertThat(dynamicConstant.isSet()).isFalse();
dynamicConstant.set("override");
assertThat(dynamicConstant.isSet()).isTrue();
assertThat(dynamicConstant.get()).isEqualTo("override");
}
@Test
public void lazyDefaultShouldBeUsed_multipleTimes_ifSetIsNotInvoked() {
DynamicConstant<String> dynamicConstant = DynamicConstant.lazyDefault(() -> SafeHolder.VAL);
assertThat(dynamicConstant.isSet()).isFalse();
assertThat(dynamicConstant.get()).isEqualTo(SafeHolder.VAL);
assertThat(dynamicConstant.isSet()).isTrue();
assertThat(dynamicConstant.get()).isEqualTo(SafeHolder.VAL);
assertThat(dynamicConstant.get()).isEqualTo(SafeHolder.VAL);
}
......@@ -35,7 +40,9 @@ public class DynamicConstantTest extends TestBase {
public void defaultShouldBeUsed_multipleTimes_ifSetIsNotInvoked() {
String myDefault = "my default";
DynamicConstant<String> dynamicConstant = DynamicConstant.withDefault(myDefault);
assertThat(dynamicConstant.isSet()).isFalse();
assertThat(dynamicConstant.get()).isEqualTo(myDefault);
assertThat(dynamicConstant.isSet()).isTrue();
assertThat(dynamicConstant.get()).isEqualTo(myDefault);
assertThat(dynamicConstant.get()).isEqualTo(myDefault);
}
......@@ -94,7 +101,9 @@ public class DynamicConstantTest extends TestBase {
@Test
public void noDefault_followedBySet_shouldSucceed() {
DynamicConstant<Integer> dynamicConstant = DynamicConstant.noDefault();
assertThat(dynamicConstant.isSet()).isFalse();
dynamicConstant.set(29);
assertThat(dynamicConstant.isSet()).isTrue();
assertThat(dynamicConstant.get()).isEqualTo(29);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment