-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add structured logging * feat: Add redux * feat: Add flow * feat: Add error handling * feat: Add misceallenous * feat: Revise tests * chore: Update archery commons * feat: Revise tests --------- Co-authored-by: Romuald Rousseau <[email protected]>
- Loading branch information
1 parent
fc24cfc
commit 8d24901
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...ry-commons/src/test/java/com/github/romualdrousseau/archery/commons/redux/Test_Redux.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,56 @@ | ||
package com.github.romualdrousseau.archery.commons.redux; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class Test_Redux { | ||
|
||
@Test | ||
@Tag("unit") | ||
public void testStoreNoReducerNoSbuscriber() { | ||
final var state = new HashMap<String, Integer>(); | ||
final var store = new Store<HashMap<String, Integer>, Action>(state); | ||
final var testAction = new Action("test"); | ||
store.dispatch(testAction); | ||
} | ||
|
||
@Test | ||
|
||
public void testStoreNoReducerWithSubscriber() { | ||
final var state = new HashMap<String, Integer>(); | ||
final var store = new Store<HashMap<String, Integer>, Action>(state); | ||
final var testAction = new Action("test"); | ||
store.addSubscriber(testAction, (s, a) -> assertEquals("test", a.getType())); | ||
store.dispatch(testAction); | ||
} | ||
|
||
@Test | ||
@Tag("unit") | ||
public void testStoreWithReducerAndSubscribers() { | ||
final var state = new HashMap<String, Integer>(); | ||
state.put("counter", 0); | ||
|
||
final var store = new Store<HashMap<String, Integer>, Action>(state); | ||
store.addReducer((s, a) -> { | ||
if (a.getType().equals("inc")) { | ||
s.computeIfPresent("counter", (x, y) -> y + 1); | ||
} | ||
if (a.getType().equals("dec")) { | ||
s.computeIfPresent("counter", (x, y) -> y - 1); | ||
} | ||
return s; | ||
}); | ||
|
||
final var incAction = new Action("inc"); | ||
final var decAction = new Action("dec"); | ||
|
||
store.addSubscriber(incAction, (s, a) -> assertEquals(Integer.valueOf(1), s.getState().get("counter"))); | ||
store.addSubscriber(decAction, (s, a) -> assertEquals(Integer.valueOf(0), s.getState().get("counter"))); | ||
store.dispatch(incAction); | ||
store.dispatch(decAction); | ||
} | ||
} |