Cleaned up issues, added test for history.
This commit is contained in:
parent
4f076bdc69
commit
0933479596
13
pom.xml
13
pom.xml
|
@ -29,6 +29,19 @@
|
|||
<artifactId>javafx-fxml</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.10.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.10.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -124,4 +124,20 @@ public class RouteHistory {
|
|||
}
|
||||
return breadCrumbs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an unmodifiable view of the items in this history.
|
||||
* @return This history's items.
|
||||
*/
|
||||
public List<RouteHistoryItem> getItems() {
|
||||
return Collections.unmodifiableList(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current item index.
|
||||
* @return The current item index.
|
||||
*/
|
||||
public int getCurrentItemIndex() {
|
||||
return currentItemIndex;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
* The JavaFX-Scene-Router module. Require this to use the library.
|
||||
*/
|
||||
module com.andrewlalis.javafx_scene_router {
|
||||
requires javafx.base;
|
||||
requires javafx.controls;
|
||||
requires javafx.fxml;
|
||||
requires javafx.graphics;
|
||||
|
||||
exports com.andrewlalis.javafx_scene_router;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
package com.andrewlalis.javafx_scene_router;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class RouteHistoryTest {
|
||||
@Test
|
||||
public void testPush() {
|
||||
var history = new RouteHistory();
|
||||
assertTrue(history.getItems().isEmpty());
|
||||
assertEquals(-1, history.getCurrentItemIndex());
|
||||
history.push("test", "Hello");
|
||||
assertEquals(history.getItems().size(), 1);
|
||||
assertEquals(0, history.getCurrentItemIndex());
|
||||
assertEquals("Hello", history.getCurrentContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCurrentContext() {
|
||||
var history = new RouteHistory();
|
||||
assertNull(history.getCurrentContext());
|
||||
history.push("test", 5);
|
||||
assertEquals(Integer.valueOf(5), history.getCurrentContext());
|
||||
history.push("test2", null);
|
||||
assertNull(history.getCurrentContext());
|
||||
history.back();
|
||||
assertEquals(Integer.valueOf(5), history.getCurrentContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBack() {
|
||||
var history = new RouteHistory();
|
||||
assertFalse(history.canGoBack());
|
||||
assertTrue(history.back().isEmpty());
|
||||
history.push("a", "a");
|
||||
assertFalse(history.canGoBack());
|
||||
history.push("b", "b");
|
||||
assertTrue(history.canGoBack());
|
||||
var prev = history.back();
|
||||
assertTrue(prev.isPresent());
|
||||
assertEquals(new RouteHistoryItem("a", "a"), prev.get());
|
||||
assertFalse(history.canGoBack());
|
||||
assertTrue(history.back().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForward() {
|
||||
var history = new RouteHistory();
|
||||
assertFalse(history.canGoForward());
|
||||
assertTrue(history.forward().isEmpty());
|
||||
history.push("a", "a");
|
||||
history.push("b", "b");
|
||||
history.push("c", "c");
|
||||
assertFalse(history.canGoForward());
|
||||
assertTrue(history.forward().isEmpty());
|
||||
history.back();
|
||||
assertTrue(history.canGoForward());
|
||||
var next = history.forward();
|
||||
assertTrue(next.isPresent());
|
||||
assertEquals(new RouteHistoryItem("c", "c"), next.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() {
|
||||
var history = new RouteHistory();
|
||||
history.push("a", "a");
|
||||
history.clear();
|
||||
assertFalse(history.canGoBack());
|
||||
assertFalse(history.canGoForward());
|
||||
assertNull(history.getCurrentContext());
|
||||
assertTrue(history.getItems().isEmpty());
|
||||
assertEquals(-1, history.getCurrentItemIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBreadCrumbs() {
|
||||
var h1 = new RouteHistory();
|
||||
var b1 = h1.getBreadCrumbs();
|
||||
assertTrue(b1.isEmpty());
|
||||
|
||||
var h2 = new RouteHistory();
|
||||
h2.push("a", "a");
|
||||
var b2 = h2.getBreadCrumbs();
|
||||
assertEquals(b2.size(), 1);
|
||||
assertEquals("a", b2.get(0).route());
|
||||
assertTrue(b2.get(0).current());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue