Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed ObservableIntegerAssert to more general ObservableNumberAsser…
…t so that integer, long, double and float can be used
- Loading branch information
1 parent
7d08e0f
commit cb3c9e8
Showing
7 changed files
with
169 additions
and
27 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
*.iml | ||
|
||
# Gradle | ||
build/ | ||
build/ | ||
.gradle/ |
21 changes: 0 additions & 21 deletions
21
src/main/java/eu/lestard/assertj/javafx/api/ObservableIntegerValueAssert.java
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
src/main/java/eu/lestard/assertj/javafx/api/ObservableNumberValueAssert.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,52 @@ | ||
package eu.lestard.assertj.javafx.api; | ||
|
||
import javafx.beans.value.ObservableNumberValue; | ||
import org.assertj.core.api.AbstractAssert; | ||
|
||
class ObservableNumberValueAssert extends AbstractAssert<ObservableNumberValueAssert, ObservableNumberValue> { | ||
|
||
protected ObservableNumberValueAssert(ObservableNumberValue actual) { | ||
super(actual, ObservableNumberValueAssert.class); | ||
} | ||
|
||
public ObservableNumberValueAssert hasValue(int expectedValue){ | ||
isNotNull(); | ||
|
||
if(actual.intValue() != expectedValue){ | ||
failWithMessage("Actual observable integer should have the value <%s> but was <%s>", expectedValue, actual.intValue()); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public ObservableNumberValueAssert hasValue(double expectedValue){ | ||
isNotNull(); | ||
|
||
if(actual.doubleValue() != expectedValue){ | ||
failWithMessage("Actual observable double should have the value <%s> but was <%s>", expectedValue, actual.doubleValue()); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public ObservableNumberValueAssert hasValue(long expectedValue){ | ||
isNotNull(); | ||
|
||
if(actual.longValue() != expectedValue){ | ||
failWithMessage("Actual observable long should have the value <%s> but was <%s>", expectedValue, actual.longValue()); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
|
||
public ObservableNumberValueAssert hasValue(float expectedValue){ | ||
isNotNull(); | ||
|
||
if(actual.floatValue() != expectedValue){ | ||
failWithMessage("Actual observable float should have the value <%s> but was <%s>", expectedValue, actual.floatValue()); | ||
} | ||
|
||
return this; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
.../java/eu/lestard/assertj/javafx/api/ObservableNumberValueAssert_hasValue_double_Test.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,36 @@ | ||
package eu.lestard.assertj.javafx.api; | ||
|
||
import javafx.beans.property.SimpleDoubleProperty; | ||
import javafx.beans.property.SimpleIntegerProperty; | ||
import javafx.beans.value.ObservableDoubleValue; | ||
import javafx.beans.value.ObservableIntegerValue; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class ObservableNumberValueAssert_hasValue_double_Test { | ||
|
||
@Test | ||
public void should_pass_if_actual_has_given_value(){ | ||
ObservableDoubleValue actual = new SimpleDoubleProperty(10.123); | ||
|
||
new ObservableNumberValueAssert(actual).hasValue(10.123); | ||
} | ||
|
||
@Test | ||
public void should_fail_if_actual_has_wrong_value(){ | ||
try{ | ||
ObservableDoubleValue actual = new SimpleDoubleProperty(10.123); | ||
|
||
new ObservableNumberValueAssert(actual).hasValue(10.12); | ||
fail("Should throw an AssertionError"); | ||
}catch(AssertionError error){ | ||
assertThat(error).hasMessageContaining("<10.12> but was <10.123>"); | ||
} | ||
} | ||
|
||
@Test(expected = AssertionError.class) | ||
public void should_fail_if_actual_is_null(){ | ||
new ObservableNumberValueAssert(null).hasValue(10.123); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...t/java/eu/lestard/assertj/javafx/api/ObservableNumberValueAssert_hasValue_float_Test.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,36 @@ | ||
package eu.lestard.assertj.javafx.api; | ||
|
||
import javafx.beans.property.SimpleFloatProperty; | ||
import javafx.beans.property.SimpleLongProperty; | ||
import javafx.beans.value.ObservableFloatValue; | ||
import javafx.beans.value.ObservableLongValue; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class ObservableNumberValueAssert_hasValue_float_Test { | ||
|
||
@Test | ||
public void should_pass_if_actual_has_given_value(){ | ||
ObservableFloatValue actual = new SimpleFloatProperty(1234.56F); | ||
|
||
new ObservableNumberValueAssert(actual).hasValue(1234.56F); | ||
} | ||
|
||
@Test | ||
public void should_fail_if_actual_has_wrong_value(){ | ||
try{ | ||
ObservableFloatValue actual = new SimpleFloatProperty(1234.56F); | ||
|
||
new ObservableNumberValueAssert(actual).hasValue(1234F); | ||
fail("Should throw an AssertionError"); | ||
}catch(AssertionError error){ | ||
assertThat(error).hasMessageContaining("<1234.0f> but was <1234.56f>"); | ||
} | ||
} | ||
|
||
@Test(expected = AssertionError.class) | ||
public void should_fail_if_actual_is_null(){ | ||
new ObservableNumberValueAssert(null).hasValue(1234.56F); | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
...st/java/eu/lestard/assertj/javafx/api/ObservableNumberValueAssert_hasValue_long_Test.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,36 @@ | ||
package eu.lestard.assertj.javafx.api; | ||
|
||
import javafx.beans.property.SimpleDoubleProperty; | ||
import javafx.beans.property.SimpleLongProperty; | ||
import javafx.beans.value.ObservableDoubleValue; | ||
import javafx.beans.value.ObservableLongValue; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class ObservableNumberValueAssert_hasValue_long_Test { | ||
|
||
@Test | ||
public void should_pass_if_actual_has_given_value(){ | ||
ObservableLongValue actual = new SimpleLongProperty(1234L); | ||
|
||
new ObservableNumberValueAssert(actual).hasValue(1234L); | ||
} | ||
|
||
@Test | ||
public void should_fail_if_actual_has_wrong_value(){ | ||
try{ | ||
ObservableLongValue actual = new SimpleLongProperty(1234L); | ||
|
||
new ObservableNumberValueAssert(actual).hasValue(123L); | ||
fail("Should throw an AssertionError"); | ||
}catch(AssertionError error){ | ||
assertThat(error).hasMessageContaining("<123L> but was <1234L>"); | ||
} | ||
} | ||
|
||
@Test(expected = AssertionError.class) | ||
public void should_fail_if_actual_is_null(){ | ||
new ObservableNumberValueAssert(null).hasValue(1234L); | ||
} | ||
} |