Skip to content

Commit

Permalink
check that returned text color is one of the expected ones defined in…
Browse files Browse the repository at this point in the history
… relevant CSS
  • Loading branch information
McFoggy committed Apr 17, 2020
1 parent bab2984 commit b726cf9
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/test/java/org/fxmisc/cssfx/test/ui/BasicUITest.java
Expand Up @@ -23,9 +23,11 @@

import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.stage.Stage;
import org.fxmisc.cssfx.CSSFX;
import org.fxmisc.cssfx.test.misc.DisabledOnMac;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testfx.api.FxRobot;
Expand All @@ -38,7 +40,11 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import static org.hamcrest.CoreMatchers.hasItem;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

Expand Down Expand Up @@ -69,7 +75,10 @@ public void checkCSSIsApplied(FxRobot robot) throws Exception {
try {
Thread.sleep(1000);
Label cssfxLabel = robot.lookup("#cssfx").queryAs(Label.class);
assertThat(cssfxLabel.getTextFill(), is(Color.BLUE));

Paint textColor = cssfxLabel.getTextFill();
assertThat("retrieved color is not one of expected", getExpectedTextColor(), hasItem(textColor));
assertThat(textColor, is(Color.BLUE));
} finally {
stopper.run();
}
Expand Down Expand Up @@ -108,7 +117,9 @@ public void checkCSSFXCanChangeTheLabelFontColor(FxRobot robot) throws Exception

// Let's check that initial launch has used the mapped
Label cssfxLabel = robot.lookup("#cssfx").queryAs(Label.class);
assertThat(cssfxLabel.getTextFill(), is(Color.BLUE));
Paint textColor = cssfxLabel.getTextFill();
assertThat("retrieved color is not one of expected", getExpectedTextColor(), hasItem(textColor));
assertThat(textColor, is(Color.BLUE));

// Copy the modified version in to the "source" file
try {
Expand All @@ -117,12 +128,18 @@ public void checkCSSFXCanChangeTheLabelFontColor(FxRobot robot) throws Exception
e.printStackTrace();
}

// We need to let CSSFX some time to detect the file change
// We TestMemoryLeaksneed to let CSSFX some time to detect the file change
Thread.sleep(1000);

assertThat(cssfxLabel.getTextFill(), is(Color.RED));
textColor = cssfxLabel.getTextFill();
assertThat("retrieved color is not one of expected", getExpectedTextColor(), hasItem(textColor));
assertThat(textColor, is(Color.RED));
} finally {
stopper.run();
}
}

private static Collection<Paint> getExpectedTextColor() {
return Arrays.asList(Color.WHITE, Color.RED, Color.BLUE);
}
}

0 comments on commit b726cf9

Please sign in to comment.