diff --git a/.gradle/7.5/executionHistory/executionHistory.bin b/.gradle/7.5/executionHistory/executionHistory.bin index a6d789a..6242998 100644 Binary files a/.gradle/7.5/executionHistory/executionHistory.bin and b/.gradle/7.5/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.5/executionHistory/executionHistory.lock b/.gradle/7.5/executionHistory/executionHistory.lock index 9bc67d4..8f955d7 100644 Binary files a/.gradle/7.5/executionHistory/executionHistory.lock and b/.gradle/7.5/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.5/fileHashes/fileHashes.bin b/.gradle/7.5/fileHashes/fileHashes.bin index 0680dad..2cf79ba 100644 Binary files a/.gradle/7.5/fileHashes/fileHashes.bin and b/.gradle/7.5/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.5/fileHashes/fileHashes.lock b/.gradle/7.5/fileHashes/fileHashes.lock index 860331c..f16f9ec 100644 Binary files a/.gradle/7.5/fileHashes/fileHashes.lock and b/.gradle/7.5/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.5/fileHashes/resourceHashesCache.bin b/.gradle/7.5/fileHashes/resourceHashesCache.bin index 24ab66a..1fd2209 100644 Binary files a/.gradle/7.5/fileHashes/resourceHashesCache.bin and b/.gradle/7.5/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 78e846f..7a00fcd 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 20f6f0e..1f587f0 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/build/intermediates/compile_library_classes_jar/debug/classes.jar b/build/intermediates/compile_library_classes_jar/debug/classes.jar index 7c79889..dd31502 100644 Binary files a/build/intermediates/compile_library_classes_jar/debug/classes.jar and b/build/intermediates/compile_library_classes_jar/debug/classes.jar differ diff --git a/build/intermediates/javac/debug/classes/org/gentrifiedApps/statemachineftc/ParallelRunSM$Builder.class b/build/intermediates/javac/debug/classes/org/gentrifiedApps/statemachineftc/ParallelRunSM$Builder.class index aaf45f1..1ea6f91 100644 Binary files a/build/intermediates/javac/debug/classes/org/gentrifiedApps/statemachineftc/ParallelRunSM$Builder.class and b/build/intermediates/javac/debug/classes/org/gentrifiedApps/statemachineftc/ParallelRunSM$Builder.class differ diff --git a/build/intermediates/javac/debug/classes/org/gentrifiedApps/statemachineftc/ParallelRunSM.class b/build/intermediates/javac/debug/classes/org/gentrifiedApps/statemachineftc/ParallelRunSM.class index c6f461a..a0554d6 100644 Binary files a/build/intermediates/javac/debug/classes/org/gentrifiedApps/statemachineftc/ParallelRunSM.class and b/build/intermediates/javac/debug/classes/org/gentrifiedApps/statemachineftc/ParallelRunSM.class differ diff --git a/build/intermediates/javac/debug/classes/tests/ParallelRunSMTestCases.class b/build/intermediates/javac/debug/classes/tests/ParallelRunSMTestCases.class index 0e0e0e4..586d42f 100644 Binary files a/build/intermediates/javac/debug/classes/tests/ParallelRunSMTestCases.class and b/build/intermediates/javac/debug/classes/tests/ParallelRunSMTestCases.class differ diff --git a/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin b/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin index 71589ad..2176676 100644 Binary files a/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin and b/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin differ diff --git a/src/main/java/org/gentrifiedApps/statemachineftc/ParallelRunSM.java b/src/main/java/org/gentrifiedApps/statemachineftc/ParallelRunSM.java index 66e168c..fcd993c 100644 --- a/src/main/java/org/gentrifiedApps/statemachineftc/ParallelRunSM.java +++ b/src/main/java/org/gentrifiedApps/statemachineftc/ParallelRunSM.java @@ -1,9 +1,5 @@ package org.gentrifiedApps.statemachineftc; -import android.util.Pair; - -import org.junit.jupiter.api.DisplayNameGenerator; - import java.util.AbstractMap; import java.util.ArrayList; import java.util.HashMap; @@ -83,6 +79,11 @@ public ParallelRunSM.Builder stopRunning(T state, Supplier exitComma public ParallelRunSM build(Boolean useTimeout, Integer timeout) { this.timeout = new AbstractMap.SimpleEntry<>(useTimeout, timeout); + + if (timeout < 0) { + throw new IllegalArgumentException("Timeout must be a positive integer"); + } + if (states == null || states.isEmpty()) { throw new IllegalArgumentException("States cannot be null or empty"); } @@ -91,6 +92,13 @@ public ParallelRunSM build(Boolean useTimeout, Integer timeout) { throw new IllegalArgumentException("States cannot have duplicates"); } + if (onEnterCommands.isEmpty()) { + throw new IllegalArgumentException("States must have corresponding onEnter commands"); + } + if (onEnterCommands.size() != states.size()) { + throw new IllegalArgumentException("Not all states have corresponding onEnter commands"); + } + if (onEnterCommands.get(states.get(0)) == null) { throw new IllegalArgumentException("Initial state must have a corresponding onEnter command"); } diff --git a/src/main/java/tests/ParallelRunSMTestCases.java b/src/main/java/tests/ParallelRunSMTestCases.java index 9f77100..e131e1a 100644 --- a/src/main/java/tests/ParallelRunSMTestCases.java +++ b/src/main/java/tests/ParallelRunSMTestCases.java @@ -278,4 +278,35 @@ public void testStopRunningTiming2() { assertFalse(map[2]); assertFalse(stateMachine.isRunning()); } + // mismatch states and onenters + @Test + public void testMismatchStatesAndOnEnters() { + ParallelRunSM.Builder builder = new ParallelRunSM.Builder<>(); + builder.state(States.STATE1) + .onEnter(States.STATE1, () -> System.out.println("Entering STATE1")) + .state(States.STATE2) + .stopRunning(States.STOP,()->true); + try { + ParallelRunSM stateMachine = builder.build(false,100); + } catch (IllegalArgumentException e) { + assertEquals("Not all states have corresponding onEnter commands", e.getMessage()); + } + } + // test a negative timeout + @Test + public void testNegativeTimeout() { + ParallelRunSM.Builder builder = new ParallelRunSM.Builder<>(); + builder.state(States.STATE1) + .onEnter(States.STATE1, () -> System.out.println("Entering STATE1")) + .state(States.STATE2) + .onEnter(States.STATE2, () -> System.out.println("Entering STATE2")) + .state(States.STATE3) + .onEnter(States.STATE3, () -> System.out.println("Entering STATE3")) + .stopRunning(States.STOP,()->true); + try { + ParallelRunSM stateMachine = builder.build(false,-100); + } catch (IllegalArgumentException e) { + assertEquals("Timeout must be a positive integer", e.getMessage()); + } + } }