diff --git a/src/main/java/org/jeasy/states/api/AbstractEvent.java b/src/main/java/org/jeasy/states/api/AbstractEvent.java index 14233ba..8121a2c 100644 --- a/src/main/java/org/jeasy/states/api/AbstractEvent.java +++ b/src/main/java/org/jeasy/states/api/AbstractEvent.java @@ -57,12 +57,10 @@ public long getTimestamp() { @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("Event"); - sb.append("{name='").append(name).append('\''); - sb.append(", timestamp=").append(new Date(timestamp)); - sb.append('}'); - return sb.toString(); + return "Event" + + "{name='" + name + '\'' + + ", timestamp=" + new Date(timestamp) + + '}'; } } diff --git a/src/main/java/org/jeasy/states/core/FiniteStateMachineDefinitionValidator.java b/src/main/java/org/jeasy/states/core/FiniteStateMachineDefinitionValidator.java index 28303e9..56e26a2 100644 --- a/src/main/java/org/jeasy/states/core/FiniteStateMachineDefinitionValidator.java +++ b/src/main/java/org/jeasy/states/core/FiniteStateMachineDefinitionValidator.java @@ -25,12 +25,8 @@ import org.jeasy.states.api.FiniteStateMachine; import org.jeasy.states.api.State; -import org.jeasy.states.api.Transition; import org.jeasy.states.util.Utils; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; import java.util.Set; class FiniteStateMachineDefinitionValidator { diff --git a/src/test/java/org/jeasy/states/api/StateTest.java b/src/test/java/org/jeasy/states/api/StateTest.java index 8b265a5..df56562 100644 --- a/src/test/java/org/jeasy/states/api/StateTest.java +++ b/src/test/java/org/jeasy/states/api/StateTest.java @@ -29,7 +29,7 @@ public class StateTest { @Test - public void whenTwoStatesHaveTheSameName_thenTheyShouldBeEqual() throws Exception { + public void whenTwoStatesHaveTheSameName_thenTheyShouldBeEqual() { // Given State s1 = new State("s1"); State s2 = new State("s1"); @@ -42,7 +42,7 @@ public void whenTwoStatesHaveTheSameName_thenTheyShouldBeEqual() throws Exceptio } @Test - public void whenTwoStatesHaveDifferentNames_thenTheyShouldNotBeEqual() throws Exception { + public void whenTwoStatesHaveDifferentNames_thenTheyShouldNotBeEqual() { // Given State s1 = new State("s1"); State s2 = new State("s2"); diff --git a/src/test/java/org/jeasy/states/core/FiniteStateMachineBuilderTest.java b/src/test/java/org/jeasy/states/core/FiniteStateMachineBuilderTest.java index 1d89e18..b799e05 100644 --- a/src/test/java/org/jeasy/states/core/FiniteStateMachineBuilderTest.java +++ b/src/test/java/org/jeasy/states/core/FiniteStateMachineBuilderTest.java @@ -37,7 +37,7 @@ public class FiniteStateMachineBuilderTest { @Test - public void testRegisterTransition() throws Exception { + public void testRegisterTransition() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -59,7 +59,7 @@ public void testRegisterTransition() throws Exception { } @Test - public void testRegisterTransitions() throws Exception { + public void testRegisterTransitions() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -90,7 +90,7 @@ public void testRegisterTransitions() throws Exception { } @Test - public void testRegisterFinalState() throws Exception { + public void testRegisterFinalState() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -108,7 +108,7 @@ public void testRegisterFinalState() throws Exception { } @Test - public void testRegisterFinalStates() throws Exception { + public void testRegisterFinalStates() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -130,7 +130,7 @@ public void testRegisterFinalStates() throws Exception { assertThat(finiteStateMachine.getFinalStates()).contains(s2, s3); } - private class DummyEvent extends AbstractEvent { } - private class AnotherDummyEvent extends AbstractEvent { } + private static class DummyEvent extends AbstractEvent { } + private static class AnotherDummyEvent extends AbstractEvent { } } diff --git a/src/test/java/org/jeasy/states/core/FiniteStateMachineDefinitionValidatorTest.java b/src/test/java/org/jeasy/states/core/FiniteStateMachineDefinitionValidatorTest.java index 4c0aca7..beedef5 100644 --- a/src/test/java/org/jeasy/states/core/FiniteStateMachineDefinitionValidatorTest.java +++ b/src/test/java/org/jeasy/states/core/FiniteStateMachineDefinitionValidatorTest.java @@ -40,7 +40,7 @@ public class FiniteStateMachineDefinitionValidatorTest { private FiniteStateMachineDefinitionValidator validator = new FiniteStateMachineDefinitionValidator(); @Test(expected = IllegalStateException.class) - public void whenInitialStateDoesNotBelongToMachineStates_thenShouldThrowIllegalStateException() throws Exception { + public void whenInitialStateDoesNotBelongToMachineStates_thenShouldThrowIllegalStateException() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -56,7 +56,7 @@ public void whenInitialStateDoesNotBelongToMachineStates_thenShouldThrowIllegalS } @Test(expected = IllegalStateException.class) - public void whenFinalStateDoesNotBelongToMachineStates_thenShouldThrowIllegalStateException() throws Exception { + public void whenFinalStateDoesNotBelongToMachineStates_thenShouldThrowIllegalStateException() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -74,7 +74,7 @@ public void whenFinalStateDoesNotBelongToMachineStates_thenShouldThrowIllegalSta } @Test - public void whenRegisterTwoTransitionsWithSameSourceStateAndEventType_thenOnlyTheLatestOneShouldBeRegistered() throws Exception { + public void whenRegisterTwoTransitionsWithSameSourceStateAndEventType_thenOnlyTheLatestOneShouldBeRegistered() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -103,6 +103,6 @@ public void whenRegisterTwoTransitionsWithSameSourceStateAndEventType_thenOnlyTh assertThat(finiteStateMachine.getTransitions()).containsOnly(t2); // transitions are unique according to source state and event type } - private class DummyEvent extends AbstractEvent { } + private static class DummyEvent extends AbstractEvent { } } diff --git a/src/test/java/org/jeasy/states/core/FiniteStateMachineImplTest.java b/src/test/java/org/jeasy/states/core/FiniteStateMachineImplTest.java index 1870267..11b069a 100644 --- a/src/test/java/org/jeasy/states/core/FiniteStateMachineImplTest.java +++ b/src/test/java/org/jeasy/states/core/FiniteStateMachineImplTest.java @@ -50,7 +50,7 @@ public class FiniteStateMachineImplTest { private FiniteStateMachineImpl stateMachine; @Before - public void setUp() throws Exception { + public void setUp() { s1 = new State("s1"); s2 = new State("s2"); Set states = new HashSet<>(); @@ -156,7 +156,7 @@ public void whenNoRegisteredTransitionForTheFiredEvent_thenShouldNotChangeState( Assertions.assertThat(stateMachine.getCurrentState()).isEqualTo(s1); } - private class MoveEvent extends AbstractEvent { } + private static class MoveEvent extends AbstractEvent { } - private class StayEvent extends AbstractEvent { } + private static class StayEvent extends AbstractEvent { } } diff --git a/src/test/java/org/jeasy/states/core/TransitionDefinitionValidatorTest.java b/src/test/java/org/jeasy/states/core/TransitionDefinitionValidatorTest.java index 5469a77..53923af 100644 --- a/src/test/java/org/jeasy/states/core/TransitionDefinitionValidatorTest.java +++ b/src/test/java/org/jeasy/states/core/TransitionDefinitionValidatorTest.java @@ -38,7 +38,7 @@ public class TransitionDefinitionValidatorTest { private TransitionDefinitionValidator transitionDefinitionValidator = new TransitionDefinitionValidator(); @Test(expected = IllegalArgumentException.class) - public void sourceStateMustBeDefined() throws Exception { + public void sourceStateMustBeDefined() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -60,7 +60,7 @@ public void sourceStateMustBeDefined() throws Exception { } @Test(expected = IllegalArgumentException.class) - public void sourceStateMustBeDeclaredInFSMStates() throws Exception { + public void sourceStateMustBeDeclaredInFSMStates() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -84,7 +84,7 @@ public void sourceStateMustBeDeclaredInFSMStates() throws Exception { } @Test(expected = IllegalArgumentException.class) - public void targetStateMustBeDefined() throws Exception { + public void targetStateMustBeDefined() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -106,7 +106,7 @@ public void targetStateMustBeDefined() throws Exception { } @Test(expected = IllegalArgumentException.class) - public void targetStateMustBeDeclaredInFSMStates() throws Exception { + public void targetStateMustBeDeclaredInFSMStates() { // given State s1 = new State("s1"); State s2 = new State("s2"); @@ -129,6 +129,6 @@ public void targetStateMustBeDeclaredInFSMStates() throws Exception { // expected exception } - private class DummyEvent extends AbstractEvent { } + private static class DummyEvent extends AbstractEvent { } } diff --git a/src/test/java/org/jeasy/states/core/TransitionImplTest.java b/src/test/java/org/jeasy/states/core/TransitionImplTest.java index 8d6c358..a298ea0 100644 --- a/src/test/java/org/jeasy/states/core/TransitionImplTest.java +++ b/src/test/java/org/jeasy/states/core/TransitionImplTest.java @@ -32,10 +32,10 @@ public class TransitionImplTest { private State s1 = new State("s1"); - private State s2 = new State("s"); + private State s2 = new State("s2"); @Test - public void whenTwoTransitionsHaveTheSameSourceStateAndTheSameTriggeringEvent_thenTheyShouldBeEqual() throws Exception { + public void whenTwoTransitionsHaveTheSameSourceStateAndTheSameTriggeringEvent_thenTheyShouldBeEqual() { // Given Transition t1 = new TransitionBuilder().sourceState(s1).eventType(DummyEvent.class).build(); Transition t2 = new TransitionBuilder().sourceState(s1).eventType(DummyEvent.class).build(); @@ -48,7 +48,7 @@ public void whenTwoTransitionsHaveTheSameSourceStateAndTheSameTriggeringEvent_th } @Test - public void whenTwoTransitionsHaveTheSameSourceStateButDifferentTriggeringEvent_thenTheyShouldNotBeEqual() throws Exception { + public void whenTwoTransitionsHaveTheSameSourceStateButDifferentTriggeringEvent_thenTheyShouldNotBeEqual() { // Given Transition t1 = new TransitionBuilder().sourceState(s1).eventType(DummyEvent.class).build(); Transition t2 = new TransitionBuilder().sourceState(s1).eventType(AnotherDummyEvent.class).build(); @@ -61,7 +61,7 @@ public void whenTwoTransitionsHaveTheSameSourceStateButDifferentTriggeringEvent_ } @Test - public void whenTwoTransitionsHaveTheSameTriggeringEventButDifferentSourceState_thenTheyShouldNotBeEqual() throws Exception { + public void whenTwoTransitionsHaveTheSameTriggeringEventButDifferentSourceState_thenTheyShouldNotBeEqual() { // Given Transition t1 = new TransitionBuilder().sourceState(s1).eventType(DummyEvent.class).build(); Transition t2 = new TransitionBuilder().sourceState(s2).eventType(DummyEvent.class).build(); @@ -74,7 +74,7 @@ public void whenTwoTransitionsHaveTheSameTriggeringEventButDifferentSourceState_ } @Test - public void whenTwoTransitionsHaveDifferentTriggeringEventsAndDifferentSourceStates_thenTheyShouldNotBeEqual() throws Exception { + public void whenTwoTransitionsHaveDifferentTriggeringEventsAndDifferentSourceStates_thenTheyShouldNotBeEqual() { // Given Transition t1 = new TransitionBuilder().sourceState(s1).eventType(DummyEvent.class).build(); Transition t2 = new TransitionBuilder().sourceState(s2).eventType(AnotherDummyEvent.class).build(); @@ -86,7 +86,7 @@ public void whenTwoTransitionsHaveDifferentTriggeringEventsAndDifferentSourceSta Assertions.assertThat(equals).isFalse(); } - private class DummyEvent extends AbstractEvent { } - private class AnotherDummyEvent extends AbstractEvent { } + private static class DummyEvent extends AbstractEvent { } + private static class AnotherDummyEvent extends AbstractEvent { } } diff --git a/src/test/java/org/jeasy/states/samples/turnstile/Turnstile.java b/src/test/java/org/jeasy/states/samples/turnstile/Turnstile.java index ce095d3..1a2a38d 100644 --- a/src/test/java/org/jeasy/states/samples/turnstile/Turnstile.java +++ b/src/test/java/org/jeasy/states/samples/turnstile/Turnstile.java @@ -55,7 +55,7 @@ public static void main(String[] args) throws FiniteStateMachineException { State locked = new State("locked"); State unlocked = new State("unlocked"); - Set states = new HashSet(); + Set states = new HashSet<>(); states.add(locked); states.add(unlocked);