* tests are now in the default build path

* a few compilation errors fixed related to Java 5 transition
* StateMachine is now tested

git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@138 375186e5-ef17-0410-b0b6-91563547dcda
This commit is contained in:
angryziber 2007-06-24 20:25:52 +00:00
parent 43df609c1b
commit 8d86971da3
6 changed files with 110 additions and 10 deletions

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="src" path="ext/rocksaw/src/java"/>
<classpathentry kind="src" path="ext/vserv-tcpip/src/java"/>
<classpathentry kind="src" path="resources"/>
@ -14,5 +15,7 @@
<classpathentry kind="lib" path="ext/swt/swt-gtk.jar"/>
<classpathentry kind="lib" path="ext/swt/swt-mac.jar"/>
<classpathentry kind="lib" path="ext/swt/swt-win32.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="ext/easymock/easymock.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -35,6 +35,10 @@ public enum ScanningState {
listeners.add(listener);
}
public void clearListeners() {
listeners.clear();
}
/**
* Notifies all registered listeners of the transition to this state.
*/

View File

@ -42,8 +42,10 @@ public class StateMachine {
* @param newState
*/
public void transitionTo(ScanningState newState) {
state = newState;
state.notifyOnEntry();
if (state != newState) {
state = newState;
state.notifyOnEntry();
}
}
/**

View File

@ -0,0 +1,90 @@
/**
* This file is a part of Angry IP Scanner source code,
* see http://www.azib.net/ for more information.
* Licensed under GPLv2.
*/
package net.azib.ipscan.core.state;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
/**
* StateMachineTest
*
* @author Anton Keks
*/
public class StateMachineTest {
private StateMachine stateMachine;
@Before
public void createStateMachine() {
stateMachine = new StateMachine();
}
@Test
public void inState() throws Exception {
assertTrue(stateMachine.inState(ScanningState.IDLE));
assertFalse(stateMachine.inState(ScanningState.KILLING));
stateMachine.transitionTo(ScanningState.KILLING);
assertTrue(stateMachine.inState(ScanningState.KILLING));
}
@Test
public void transitionTo() throws Exception {
final boolean[] called = {false};
ScanningState.IDLE.addTransitionListener(new StateTransitionListener() {
public void transitionTo(ScanningState state) {
fail("no transition if changing to the same state");
}
});
ScanningState.STOPPING.addTransitionListener(new StateTransitionListener() {
public void transitionTo(ScanningState state) {
called[0] = true;
}
});
assertEquals(ScanningState.IDLE, stateMachine.getState());
stateMachine.transitionTo(ScanningState.IDLE);
assertEquals(ScanningState.IDLE, stateMachine.getState());
stateMachine.transitionTo(ScanningState.STOPPING);
assertEquals(ScanningState.STOPPING, stateMachine.getState());
assertTrue(called[0]);
ScanningState.IDLE.clearListeners();
ScanningState.STOPPING.clearListeners();
}
@Test
public void transitionToNext() throws Exception {
assertEquals(ScanningState.IDLE, stateMachine.getState());
stateMachine.transitionToNext();
assertEquals(ScanningState.SCANNING, stateMachine.getState());
stateMachine.transitionToNext();
assertEquals(ScanningState.STOPPING, stateMachine.getState());
stateMachine.transitionToNext();
assertEquals(ScanningState.KILLING, stateMachine.getState());
stateMachine.transitionToNext();
assertEquals(ScanningState.KILLING, stateMachine.getState());
}
@Test
public void stop() throws Exception {
stateMachine.transitionTo(ScanningState.SCANNING);
stateMachine.stop();
assertEquals(ScanningState.STOPPING, stateMachine.getState());
}
@Test
public void complete() throws Exception {
stateMachine.transitionTo(ScanningState.STOPPING);
stateMachine.complete();
assertEquals(ScanningState.IDLE, stateMachine.getState());
stateMachine.transitionTo(ScanningState.KILLING);
stateMachine.complete();
assertEquals(ScanningState.IDLE, stateMachine.getState());
}
}

View File

@ -19,12 +19,12 @@ public class NumericListValueTest {
@Test
public void testToString() {
assertEquals("", new NumericListValue(Collections.EMPTY_LIST, true).toString());
assertEquals("1", new NumericListValue(Arrays.asList(new Object[] {1}), true).toString());
assertEquals("1-3", new NumericListValue(Arrays.asList(new Object[] {1, 2, 3}), true).toString());
assertEquals("1-3", new NumericListValue(new TreeSet<Integer>(Arrays.asList(new Integer[] {2, 3, 1})), true).toString());
assertEquals("1,2,3", new NumericListValue(Arrays.asList(new Object[] {1, 2, 3}), false).toString());
assertEquals("1,5-6,15", new NumericListValue(Arrays.asList(new Object[] {1, 5, 6, 15}), true).toString());
assertEquals("103,85,89,1", new NumericListValue(Arrays.asList(new Object[] {103, 85, 89, 1}), true).toString());
assertEquals("", new NumericListValue(Collections.<Integer>emptyList(), true).toString());
assertEquals("1", new NumericListValue(Arrays.asList(1), true).toString());
assertEquals("1-3", new NumericListValue(Arrays.asList(1, 2, 3), true).toString());
assertEquals("1-3", new NumericListValue(new TreeSet<Integer>(Arrays.asList(2, 3, 1)), true).toString());
assertEquals("1,2,3", new NumericListValue(Arrays.asList(1, 2, 3), false).toString());
assertEquals("1,5-6,15", new NumericListValue(Arrays.asList(1, 5, 6, 15), true).toString());
assertEquals("103,85,89,1", new NumericListValue(Arrays.asList(103, 85, 89, 1), true).toString());
}
}

View File

@ -21,6 +21,7 @@ import net.azib.ipscan.config.Labels;
import net.azib.ipscan.core.ScanningResult;
import net.azib.ipscan.core.ScanningResultList;
import net.azib.ipscan.exporters.ExportProcessor.ScanningResultSelector;
import net.azib.ipscan.fetchers.Fetcher;
import net.azib.ipscan.fetchers.FetcherRegistry;
import net.azib.ipscan.fetchers.IPFetcher;
@ -41,7 +42,7 @@ public class ExportProcessorTest {
public void setUp() {
fetcherRegistry = createMock(FetcherRegistry.class);
expect(fetcherRegistry.getSelectedFetchers())
.andReturn(Collections.singletonList(new IPFetcher())).anyTimes();
.andReturn(Collections.<Fetcher>singletonList(new IPFetcher())).anyTimes();
replay(fetcherRegistry);
}