-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #60 Add property for Double values
- Loading branch information
Showing
9 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/ch/jalu/configme/properties/DoubleProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ch.jalu.configme.properties; | ||
|
||
import ch.jalu.configme.resource.PropertyReader; | ||
|
||
public class DoubleProperty extends BaseProperty<Double> { | ||
|
||
public DoubleProperty(String path, double defaultValue) { | ||
super(path, defaultValue); | ||
} | ||
|
||
@Override | ||
protected Double getFromResource(PropertyReader reader) { | ||
return reader.getDouble(getPath()); | ||
} | ||
|
||
@Override | ||
public Object toExportValue(Double value) { | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/test/java/ch/jalu/configme/properties/DoublePropertyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package ch.jalu.configme.properties; | ||
|
||
import ch.jalu.configme.resource.PropertyReader; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
/** | ||
* Test for {@link DoubleProperty}. | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class DoublePropertyTest { | ||
|
||
@Mock | ||
private PropertyReader reader; | ||
|
||
@Test | ||
public void shouldReturnDoubleFromResource() { | ||
// given | ||
Property<Double> property = new DoubleProperty("test.path", 3.4); | ||
given(reader.getDouble("test.path")).willReturn(-2508.346); | ||
|
||
// when | ||
double result = property.determineValue(reader); | ||
|
||
// then | ||
assertThat(result, equalTo(-2508.346)); | ||
} | ||
|
||
@Test | ||
public void shouldReturnDefaultValue() { | ||
// given | ||
Property<Double> property = new DoubleProperty("property.path", 5.9); | ||
given(reader.getDouble("property.path")).willReturn(null); | ||
|
||
// when | ||
double result = property.determineValue(reader); | ||
|
||
// then | ||
assertThat(result, equalTo(5.9)); | ||
} | ||
|
||
@Test | ||
public void shouldReturnValueAsExportValue() { | ||
// given | ||
Property<Double> property = new DoubleProperty("property.path", 4); | ||
double givenValue = 4.3456; | ||
|
||
// when | ||
Object exportValue = property.toExportValue(givenValue); | ||
|
||
// then | ||
assertThat(exportValue, equalTo(givenValue)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ features: | |
colors: | ||
- 'beige' | ||
- 'gray' | ||
dustLevel: 2 | ||
dustLevel: 2.4 | ||
cool: | ||
enabled: true | ||
options: | ||
|