Navigation Menu

Skip to content

Commit

Permalink
changed ObservableIntegerAssert to more general ObservableNumberAsser…
Browse files Browse the repository at this point in the history
…t so that integer, long, double and float can be used
  • Loading branch information
manuel-mauky committed Apr 15, 2014
1 parent 7d08e0f commit cb3c9e8
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,5 @@
*.iml

# Gradle
build/
build/
.gradle/

This file was deleted.

@@ -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;
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -1,27 +1,29 @@
package eu.lestard.assertj.javafx.api;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ObservableDoubleValue;
import javafx.beans.value.ObservableIntegerValue;
import javafx.beans.value.ObservableNumberValue;
import org.junit.Test;

import static org.assertj.core.api.Assertions.*;

public class ObservableIntegerValueAssert_hasValue_Test {
public class ObservableNumberValueAssert_hasValue_integer_Test {

@Test
public void should_pass_if_actual_has_given_value(){
ObservableIntegerValue actual = new SimpleIntegerProperty(10);

new ObservableIntegerValueAssert(actual).hasValue(10);
new ObservableNumberValueAssert(actual).hasValue(10);
}

@Test
public void should_fail_if_actual_has_wrong_value(){
try{
ObservableIntegerValue actual = new SimpleIntegerProperty(10);

new ObservableIntegerValueAssert(actual).hasValue(8);
new ObservableNumberValueAssert(actual).hasValue(8);
fail("Should throw an AssertionError");
}catch(AssertionError error){
assertThat(error).hasMessageContaining("<8> but was <10>");
Expand All @@ -30,6 +32,6 @@ public void should_fail_if_actual_has_wrong_value(){

@Test(expected = AssertionError.class)
public void should_fail_if_actual_is_null(){
new ObservableIntegerValueAssert(null).hasValue(10);
new ObservableNumberValueAssert(null).hasValue(10);
}
}
@@ -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);
}
}

0 comments on commit cb3c9e8

Please sign in to comment.