Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Fix warnings reported by Intellij Idea code inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
fmbenhassine committed Mar 13, 2020
1 parent 27e7bd8 commit 6134008
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 38 deletions.
10 changes: 4 additions & 6 deletions src/main/java/org/jeasy/states/api/AbstractEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/jeasy/states/api/StateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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 { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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 { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<State> states = new HashSet<>();
Expand Down Expand Up @@ -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 { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -129,6 +129,6 @@ public void targetStateMustBeDeclaredInFSMStates() throws Exception {
// expected exception
}

private class DummyEvent extends AbstractEvent { }
private static class DummyEvent extends AbstractEvent { }

}
14 changes: 7 additions & 7 deletions src/test/java/org/jeasy/states/core/TransitionImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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 { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void main(String[] args) throws FiniteStateMachineException {
State locked = new State("locked");
State unlocked = new State("unlocked");

Set<State> states = new HashSet<State>();
Set<State> states = new HashSet<>();
states.add(locked);
states.add(unlocked);

Expand Down

0 comments on commit 6134008

Please sign in to comment.