-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/main/java/ch/jalu/configme/properties/FloatProperty.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,13 @@ | ||
package ch.jalu.configme.properties; | ||
|
||
import ch.jalu.configme.properties.types.PrimitivePropertyType; | ||
|
||
/** | ||
* Float property. This extension exists for convenience. | ||
*/ | ||
public class FloatProperty extends TypeBasedProperty<Float> { | ||
|
||
public FloatProperty(String path, float defaultValue) { | ||
super(path, defaultValue, PrimitivePropertyType.FLOAT); | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
src/test/java/ch/jalu/configme/properties/FloatPropertyTest.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,63 @@ | ||
package ch.jalu.configme.properties; | ||
|
||
import ch.jalu.configme.properties.convertresult.PropertyValue; | ||
import ch.jalu.configme.resource.PropertyReader; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import static ch.jalu.configme.TestUtils.isErrorValueOf; | ||
import static ch.jalu.configme.TestUtils.isValidValueOf; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
/** | ||
* Test for {@link FloatProperty}. | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
class FloatPropertyTest { | ||
|
||
@Mock | ||
private PropertyReader reader; | ||
|
||
@Test | ||
void shouldReturnFloatFromResource() { | ||
// given | ||
Property<Float> property = new FloatProperty("test.path", -4.11f); | ||
given(reader.getObject("test.path")).willReturn(-2508.346); | ||
|
||
// when | ||
PropertyValue<Float> result = property.determineValue(reader); | ||
|
||
// then | ||
assertThat(result, isValidValueOf(-2508.346f)); | ||
} | ||
|
||
@Test | ||
void shouldReturnDefaultValue() { | ||
// given | ||
Property<Float> property = new FloatProperty("property.path", 140f); | ||
given(reader.getObject("property.path")).willReturn(null); | ||
|
||
// when | ||
PropertyValue<Float> result = property.determineValue(reader); | ||
|
||
// then | ||
assertThat(result, isErrorValueOf(140f)); | ||
} | ||
|
||
@Test | ||
void shouldReturnValueAsExportValue() { | ||
// given | ||
Property<Float> property = new FloatProperty("property.path", 44f); | ||
float givenValue = 0.25f; | ||
|
||
// 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