diff --git a/src/net/azib/ipscan/core/ScannerDispatcherThread.java b/src/net/azib/ipscan/core/ScannerDispatcherThread.java index 0ea216230..d0704f06f 100644 --- a/src/net/azib/ipscan/core/ScannerDispatcherThread.java +++ b/src/net/azib/ipscan/core/ScannerDispatcherThread.java @@ -80,7 +80,7 @@ public void run() { try { ScanningSubject subject = null; - while(feeder.hasNext() && stateMachine.inState(SCANNING)) { + while(feeder.hasNext() && stateMachine.inCurrentState(SCANNING)) { // make a small delay between thread creation Thread.sleep(config.threadDelay); diff --git a/src/net/azib/ipscan/core/ScanningResultList.java b/src/net/azib/ipscan/core/ScanningResultList.java index a461508a1..2234f344e 100644 --- a/src/net/azib/ipscan/core/ScanningResultList.java +++ b/src/net/azib/ipscan/core/ScanningResultList.java @@ -53,6 +53,14 @@ public ScanningResultList(FetcherRegistry fetcherRegistry, StateMachine stateMac stateMachine.addTransitionListener(new StopScanningListener()); } + public void updateResult(int index, String fetcherId, Object newValue, ScanningResultList scanningResults) { + int fetcherIndex = scanningResults.getFetcherIndex(fetcherId); + if (fetcherIndex >= 0) { + // update the value in the results + scanningResults.getResult(index).setValue(fetcherIndex, newValue); + } + } + /** * @return selected fetchers that were used for the last scan * Note: they may be different from {@link FetcherRegistry#getSelectedFetchers()} diff --git a/src/net/azib/ipscan/core/net/WindowsPinger.java b/src/net/azib/ipscan/core/net/WindowsPinger.java index 80c612cf0..b14a156f7 100644 --- a/src/net/azib/ipscan/core/net/WindowsPinger.java +++ b/src/net/azib/ipscan/core/net/WindowsPinger.java @@ -62,9 +62,13 @@ private PingResult ping4(ScanningSubject subject, int count) throws IOException for (int i = 1; i <= count && !currentThread().isInterrupted(); i++) { int numReplies = dll.IcmpSendEcho(handle, ipaddr, sendData, (short) sendDataSize, null, replyData, replyDataSize, timeout); IcmpEchoReply echoReply = new IcmpEchoReply(replyData); - if (numReplies > 0 && echoReply.status == 0 && Arrays.equals(echoReply.address.bytes, ipaddr.bytes)) { - result.addReply(echoReply.roundTripTime); - result.setTTL(echoReply.options.ttl & 0xFF); + if (numReplies > 0) { + if (echoReply.status == 0) { + if (Arrays.equals(echoReply.address.bytes, ipaddr.bytes)) { + result.addReply(echoReply.roundTripTime); + result.setTTL(echoReply.options.ttl & 0xFF); + } + } } } } diff --git a/src/net/azib/ipscan/core/state/StateMachine.java b/src/net/azib/ipscan/core/state/StateMachine.java index 8eede4575..13d2063e9 100644 --- a/src/net/azib/ipscan/core/state/StateMachine.java +++ b/src/net/azib/ipscan/core/state/StateMachine.java @@ -30,14 +30,14 @@ public enum Transition {INIT, START, STOP, NEXT, COMPLETE, RESET, RESCAN, CONTIN /** * @return true if current state is as specified */ - public boolean inState(ScanningState state) { + public boolean inCurrentState(ScanningState state) { return this.state == state; } /** * @return current state */ - public ScanningState getState() { + public ScanningState getCurrentState() { return state; } diff --git a/src/net/azib/ipscan/exporters/TXTExporter.java b/src/net/azib/ipscan/exporters/TXTExporter.java index 252dca8ab..289e43ade 100644 --- a/src/net/azib/ipscan/exporters/TXTExporter.java +++ b/src/net/azib/ipscan/exporters/TXTExporter.java @@ -87,9 +87,9 @@ public void nextAddressResults(Object[] results) throws IOException { * @param length the total returned length, minimum is 13 */ String pad(Object o, int length) { - if (length < 16) - length = 16; - + int minLength = 16; + if (length < minLength) + length = minLength; String s; if (o == null) s = ""; diff --git a/src/net/azib/ipscan/gui/ResultTable.java b/src/net/azib/ipscan/gui/ResultTable.java index 94369857f..db622935d 100644 --- a/src/net/azib/ipscan/gui/ResultTable.java +++ b/src/net/azib/ipscan/gui/ResultTable.java @@ -158,13 +158,7 @@ public void updateResults() { * @param newValue */ public void updateResult(int index, String fetcherId, Object newValue) { - int fetcherIndex = scanningResults.getFetcherIndex(fetcherId); - if (fetcherIndex >= 0) { - // update the value in the results - scanningResults.getResult(index).setValue(fetcherIndex, newValue); - // update visual representation - clear(index); - } + scanningResults.updateResult(index, fetcherId, newValue, scanningResults); } /** diff --git a/src/net/azib/ipscan/gui/actions/ColumnsActions.java b/src/net/azib/ipscan/gui/actions/ColumnsActions.java index 88cf79d24..9acae22c2 100644 --- a/src/net/azib/ipscan/gui/actions/ColumnsActions.java +++ b/src/net/azib/ipscan/gui/actions/ColumnsActions.java @@ -69,10 +69,10 @@ public void handleEvent(Event e) { sortMenuItem.setText(Labels.getLabel("menu.columns.sortBy") + " " + fetcher.getName()); // disable these menu items if scanning - sortMenuItem.setEnabled(stateMachine.inState(ScanningState.IDLE)); + sortMenuItem.setEnabled(stateMachine.inCurrentState(ScanningState.IDLE)); preferencesMenuItem.setText(fetcher.getName() + " " + Labels.getLabel("menu.columns.preferences")); - preferencesMenuItem.setEnabled(fetcher.getPreferencesClass() != null && stateMachine.inState(ScanningState.IDLE)); + preferencesMenuItem.setEnabled(fetcher.getPreferencesClass() != null && stateMachine.inCurrentState(ScanningState.IDLE)); aboutMenuItem.setText(Labels.getLabel("menu.columns.about") + " " + fetcher.getName()); diff --git a/src/net/azib/ipscan/gui/actions/CommandsMenuActions.java b/src/net/azib/ipscan/gui/actions/CommandsMenuActions.java index f52cd4575..aa459a45e 100644 --- a/src/net/azib/ipscan/gui/actions/CommandsMenuActions.java +++ b/src/net/azib/ipscan/gui/actions/CommandsMenuActions.java @@ -100,7 +100,7 @@ public void handleEvent(Event event) { // the same listener is used for several events if (event.type == SWT.KeyDown && event.keyCode != SWT.DEL) return; // deletion not allowed when scanning - if (!stateMachine.inState(ScanningState.IDLE)) return; + if (!stateMachine.inCurrentState(ScanningState.IDLE)) return; int firstSelection = resultTable.getSelectionIndex(); if (firstSelection < 0) return; diff --git a/src/net/azib/ipscan/gui/actions/FavoritesMenuActions.java b/src/net/azib/ipscan/gui/actions/FavoritesMenuActions.java index 5aec2cc22..841908ba8 100644 --- a/src/net/azib/ipscan/gui/actions/FavoritesMenuActions.java +++ b/src/net/azib/ipscan/gui/actions/FavoritesMenuActions.java @@ -120,7 +120,7 @@ public void handleEvent(Event event) { for (String name : favoritesConfig) { MenuItem menuItem = new MenuItem(favoritesMenu, SWT.CASCADE); menuItem.setText(name); - menuItem.setEnabled(stateMachine.inState(ScanningState.IDLE)); + menuItem.setEnabled(stateMachine.inCurrentState(ScanningState.IDLE)); menuItem.addSelectionListener(favoritesSelectListener); } } diff --git a/src/net/azib/ipscan/gui/actions/ScanMenuActions.java b/src/net/azib/ipscan/gui/actions/ScanMenuActions.java index c939ae2a7..a4f404939 100644 --- a/src/net/azib/ipscan/gui/actions/ScanMenuActions.java +++ b/src/net/azib/ipscan/gui/actions/ScanMenuActions.java @@ -145,7 +145,7 @@ public void handleEvent(Event event) { throw new UserErrorException("commands.noResults"); } - if (!stateMachine.inState(ScanningState.IDLE)) { + if (!stateMachine.inCurrentState(ScanningState.IDLE)) { // ask the user whether to save incomplete results MessageBox box = new MessageBox(resultTable.getShell(), SWT.YES | SWT.NO | SWT.ICON_WARNING | SWT.SHEET); box.setText(Version.NAME); diff --git a/src/net/azib/ipscan/gui/actions/StartStopScanningAction.java b/src/net/azib/ipscan/gui/actions/StartStopScanningAction.java index aeeee2361..d50ad1ada 100644 --- a/src/net/azib/ipscan/gui/actions/StartStopScanningAction.java +++ b/src/net/azib/ipscan/gui/actions/StartStopScanningAction.java @@ -18,6 +18,7 @@ import net.azib.ipscan.core.state.StateTransitionListener; import net.azib.ipscan.gui.ResultTable; import net.azib.ipscan.gui.StatusBar; +import net.azib.ipscan.gui.feeders.AbstractFeederGUI; import net.azib.ipscan.gui.feeders.FeederGUIRegistry; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; @@ -48,6 +49,7 @@ public class StartStopScanningAction implements SelectionListener, ScanningProgr private ResultTable resultTable; private FeederGUIRegistry feederRegistry; private Button button; + private AbstractFeederGUI abstractFeederGUI; Image[] buttonImages = new Image[ScanningState.values().length]; String[] buttonTexts = new String[ScanningState.values().length]; @@ -80,7 +82,7 @@ public class StartStopScanningAction implements SelectionListener, ScanningProgr public StartStopScanningAction(ScannerDispatcherThreadFactory scannerThreadFactory, StateMachine stateMachine, ResultTable resultTable, StatusBar statusBar, FeederGUIRegistry feederRegistry, PingerRegistry pingerRegistry, - Button startStopButton, GUIConfig guiConfig) { + Button startStopButton, GUIConfig guiConfig, AbstractFeederGUI abstractFeederGUI) { this(startStopButton.getDisplay()); this.scannerThreadFactory = scannerThreadFactory; @@ -92,12 +94,13 @@ public StartStopScanningAction(ScannerDispatcherThreadFactory scannerThreadFacto this.stateMachine = stateMachine; this.guiConfig = guiConfig; this.taskBarItem = getTaskBarItem(); + this.abstractFeederGUI = abstractFeederGUI; // add listeners to all state changes stateMachine.addTransitionListener(this); // set the default image - ScanningState state = stateMachine.getState(); + ScanningState state = stateMachine.getCurrentState(); button.setImage(buttonImages[state.ordinal()]); button.setText(buttonTexts[state.ordinal()]); } @@ -124,7 +127,7 @@ public void widgetDefaultSelected(SelectionEvent e) { */ public void widgetSelected(SelectionEvent event) { // ask for confirmation before erasing scanning results - if (stateMachine.inState(IDLE)) { + if (stateMachine.inCurrentState(IDLE)) { if (!preScanChecks()) return; } @@ -160,7 +163,7 @@ public void transitionTo(final ScanningState state, final Transition transition) resultTable.removeAll(); try { - scannerThread = scannerThreadFactory.createScannerThread(feederRegistry.createFeeder(), StartStopScanningAction.this, createResultsCallback(state)); + scannerThread = scannerThreadFactory.createScannerThread(abstractFeederGUI.createFeeder(), StartStopScanningAction.this, createResultsCallback(state)); stateMachine.startScanning(); mainWindowTitle = statusBar.getShell().getText(); } @@ -249,13 +252,13 @@ public void updateProgress(final InetAddress currentAddress, final int runningTh if (taskBarItem != null) taskBarItem.setProgress(percentageComplete); // show percentage in main window title - if (!stateMachine.inState(IDLE)) + if (!stateMachine.inCurrentState(IDLE)) statusBar.getShell().setText(percentageComplete + "% - " + mainWindowTitle); else statusBar.getShell().setText(mainWindowTitle); // change button image according to the current state - button.setImage(buttonImages[stateMachine.getState().ordinal()]); + button.setImage(buttonImages[stateMachine.getCurrentState().ordinal()]); }); } diff --git a/src/net/azib/ipscan/gui/actions/ToolsActions.java b/src/net/azib/ipscan/gui/actions/ToolsActions.java index 6acc68549..2b516888d 100644 --- a/src/net/azib/ipscan/gui/actions/ToolsActions.java +++ b/src/net/azib/ipscan/gui/actions/ToolsActions.java @@ -103,7 +103,7 @@ public TableSelection(StatusBar statusBar, StateMachine stateMachine) { } public void handleEvent(Event event) { - if (stateMachine.inState(ScanningState.IDLE)) { + if (stateMachine.inCurrentState(ScanningState.IDLE)) { Table resultTable = (Table) event.widget; int selectionCount = resultTable.getSelectionCount(); if (selectionCount > 1) diff --git a/src/net/azib/ipscan/gui/feeders/AbstractFeederGUI.java b/src/net/azib/ipscan/gui/feeders/AbstractFeederGUI.java index 2ed5d36c7..0c32968d1 100644 --- a/src/net/azib/ipscan/gui/feeders/AbstractFeederGUI.java +++ b/src/net/azib/ipscan/gui/feeders/AbstractFeederGUI.java @@ -94,6 +94,10 @@ protected void asyncFillLocalHostInfo(final Text hostnameText, final Text ipText }).start(); } + public Feeder createFeeder() { + return createFeeder(); + } + protected void afterLocalHostInfoFilled(InterfaceAddress localInterface) { } } diff --git a/src/net/azib/ipscan/gui/feeders/FeederGUIRegistry.java b/src/net/azib/ipscan/gui/feeders/FeederGUIRegistry.java index 4c550571a..553baf237 100644 --- a/src/net/azib/ipscan/gui/feeders/FeederGUIRegistry.java +++ b/src/net/azib/ipscan/gui/feeders/FeederGUIRegistry.java @@ -79,14 +79,6 @@ public void select(String feederId) { throw new FeederException("Feeder not found: " + feederId); } - /** - * @return new Feeder initialized using the currently selected Feeder GUI - */ - public Feeder createFeeder() { - lastFeeder = current().createFeeder(); - return lastFeeder; - } - /** * @param selection selected table items to derive IP addresses from * @return initialized instance of RescanFeeder diff --git a/src/net/azib/ipscan/util/NetBIOSName.java b/src/net/azib/ipscan/util/NetBIOSName.java new file mode 100644 index 000000000..8b1a57f41 --- /dev/null +++ b/src/net/azib/ipscan/util/NetBIOSName.java @@ -0,0 +1,71 @@ +package net.azib.ipscan.util; + +import java.net.SocketException; + +public class NetBIOSName { + private String computerName; + private String userName; + private String groupName; + private String macAddress; + + private static final int RESPONSE_BASE_LEN = 57; + private static final int RESPONSE_NAME_LEN = 15; + private static final int RESPONSE_NAME_BLOCK_LEN = 18; + + private static final int GROUP_NAME_FLAG = 128; + private static final int NAME_TYPE_DOMAIN = 0x00; + private static final int NAME_TYPE_MESSENGER = 0x03; + + public NetBIOSName(String computerName, String userName, String groupName, String macAddress) throws SocketException { + this.computerName = computerName; + this.userName = userName; + this.groupName = groupName; + this.macAddress = macAddress; + } + + static String[] extractNames(byte[] response, int nameCount) { + String computerName = nameCount > 0 ? name(response, 0) : null; + + String groupName = null; + for (int i = 1; i < nameCount; i++) { + if (nameType(response, i) == NAME_TYPE_DOMAIN && (nameFlag(response, i) & GROUP_NAME_FLAG) > 0) { + groupName = name(response, i); + break; + } + } + + String userName = null; + for (int i = nameCount - 1; i > 0; i--) { + if (nameType(response, i) == NAME_TYPE_MESSENGER) { + userName = name(response, i); + break; + } + } + + String macAddress = String.format("%02X-%02X-%02X-%02X-%02X-%02X", + nameByte(response, nameCount, 0), nameByte(response, nameCount, 1), + nameByte(response, nameCount, 2), nameByte(response, nameCount, 3), + nameByte(response, nameCount, 4), nameByte(response, nameCount, 5)); + + return new String[] {computerName, userName, groupName, macAddress}; + } + + private static String name(byte[] response, int i) { + // as we have no idea in which encoding are the received names, + // assume that local default encoding matches the remote one (they are on the same LAN most probably) + return new String(response, RESPONSE_BASE_LEN + RESPONSE_NAME_BLOCK_LEN * i, RESPONSE_NAME_LEN).trim(); + } + + private static int nameByte(byte[] response, int i, int n) { + return response[RESPONSE_BASE_LEN + RESPONSE_NAME_BLOCK_LEN * i + n] & 0xFF; + } + + private static int nameFlag(byte[] response, int i) { + return response[RESPONSE_BASE_LEN + RESPONSE_NAME_BLOCK_LEN * i + RESPONSE_NAME_LEN + 1] & 0xFF + + (response[RESPONSE_BASE_LEN + RESPONSE_NAME_BLOCK_LEN * i + RESPONSE_NAME_LEN + 2] & 0xFF) * 0xFF; + } + + private static int nameType(byte[] response, int i) { + return response[RESPONSE_BASE_LEN + RESPONSE_NAME_BLOCK_LEN * i + RESPONSE_NAME_LEN] & 0xFF; + } +} diff --git a/src/net/azib/ipscan/util/NetBIOSResolver.java b/src/net/azib/ipscan/util/NetBIOSResolver.java index 8fdddc706..2f67f91d9 100644 --- a/src/net/azib/ipscan/util/NetBIOSResolver.java +++ b/src/net/azib/ipscan/util/NetBIOSResolver.java @@ -14,17 +14,13 @@ public class NetBIOSResolver implements Closeable { private static final int RESPONSE_TYPE_POS = 47; private static final byte RESPONSE_TYPE_NBSTAT = 33; private static final int RESPONSE_BASE_LEN = 57; - private static final int RESPONSE_NAME_LEN = 15; private static final int RESPONSE_NAME_BLOCK_LEN = 18; - private static final int GROUP_NAME_FLAG = 128; - private static final int NAME_TYPE_DOMAIN = 0x00; - private static final int NAME_TYPE_MESSENGER = 0x03; - - DatagramSocket socket = new DatagramSocket(); + private DatagramSocket socket; public NetBIOSResolver(int timeout) throws SocketException { - socket.setSoTimeout(timeout); + this.socket = new DatagramSocket(); + this.socket.setSoTimeout(timeout); } public String[] resolve(InetAddress ip) throws IOException { @@ -43,53 +39,7 @@ public String[] resolve(InetAddress ip) throws IOException { return null; // data was truncated or something is wrong } - return extractNames(response, nameCount); - } - - static String[] extractNames(byte[] response, int nameCount) { - String computerName = nameCount > 0 ? name(response, 0) : null; - - String groupName = null; - for (int i = 1; i < nameCount; i++) { - if (nameType(response, i) == NAME_TYPE_DOMAIN && (nameFlag(response, i) & GROUP_NAME_FLAG) > 0) { - groupName = name(response, i); - break; - } - } - - String userName = null; - for (int i = nameCount - 1; i > 0; i--) { - if (nameType(response, i) == NAME_TYPE_MESSENGER) { - userName = name(response, i); - break; - } - } - - String macAddress = String.format("%02X-%02X-%02X-%02X-%02X-%02X", - nameByte(response, nameCount, 0), nameByte(response, nameCount, 1), - nameByte(response, nameCount, 2), nameByte(response, nameCount, 3), - nameByte(response, nameCount, 4), nameByte(response, nameCount, 5)); - - return new String[] {computerName, userName, groupName, macAddress}; - } - - private static String name(byte[] response, int i) { - // as we have no idea in which encoding are the received names, - // assume that local default encoding matches the remote one (they are on the same LAN most probably) - return new String(response, RESPONSE_BASE_LEN + RESPONSE_NAME_BLOCK_LEN * i, RESPONSE_NAME_LEN).trim(); - } - - private static int nameByte(byte[] response, int i, int n) { - return response[RESPONSE_BASE_LEN + RESPONSE_NAME_BLOCK_LEN * i + n] & 0xFF; - } - - private static int nameFlag(byte[] response, int i) { - return response[RESPONSE_BASE_LEN + RESPONSE_NAME_BLOCK_LEN * i + RESPONSE_NAME_LEN + 1] & 0xFF + - (response[RESPONSE_BASE_LEN + RESPONSE_NAME_BLOCK_LEN * i + RESPONSE_NAME_LEN + 2] & 0xFF) * 0xFF; - } - - private static int nameType(byte[] response, int i) { - return response[RESPONSE_BASE_LEN + RESPONSE_NAME_BLOCK_LEN * i + RESPONSE_NAME_LEN] & 0xFF; + return NetBIOSName.extractNames(response, nameCount); } public void close() { diff --git a/test/net/azib/ipscan/core/state/StateMachineTest.java b/test/net/azib/ipscan/core/state/StateMachineTest.java index 5a71b03f3..c385ee8b4 100644 --- a/test/net/azib/ipscan/core/state/StateMachineTest.java +++ b/test/net/azib/ipscan/core/state/StateMachineTest.java @@ -29,10 +29,10 @@ public void createStateMachine() { @Test public void inState() throws Exception { - assertTrue(stateMachine.inState(ScanningState.IDLE)); - assertFalse(stateMachine.inState(ScanningState.KILLING)); + assertTrue(stateMachine.inCurrentState(ScanningState.IDLE)); + assertFalse(stateMachine.inCurrentState(ScanningState.KILLING)); stateMachine.transitionTo(ScanningState.KILLING, null); - assertTrue(stateMachine.inState(ScanningState.KILLING)); + assertTrue(stateMachine.inCurrentState(ScanningState.KILLING)); } @Test @@ -42,9 +42,9 @@ public void transitionTo(ScanningState state, Transition transition) { fail("no transition if changing to the same state"); } }); - assertEquals(ScanningState.IDLE, stateMachine.getState()); + assertEquals(ScanningState.IDLE, stateMachine.getCurrentState()); stateMachine.transitionTo(ScanningState.IDLE, null); - assertEquals(ScanningState.IDLE, stateMachine.getState()); + assertEquals(ScanningState.IDLE, stateMachine.getCurrentState()); } @Test @@ -56,28 +56,28 @@ public void transitionTo(ScanningState state, Transition transition) { } }); - assertEquals(ScanningState.IDLE, stateMachine.getState()); + assertEquals(ScanningState.IDLE, stateMachine.getCurrentState()); stateMachine.transitionTo(ScanningState.STOPPING, null); - assertEquals(ScanningState.STOPPING, stateMachine.getState()); + assertEquals(ScanningState.STOPPING, stateMachine.getCurrentState()); assertEquals(ScanningState.STOPPING, calledWithParameter[0]); stateMachine.transitionTo(ScanningState.STARTING, null); - assertEquals(ScanningState.STARTING, stateMachine.getState()); + assertEquals(ScanningState.STARTING, stateMachine.getCurrentState()); assertEquals(ScanningState.STARTING, calledWithParameter[0]); } @Test public void transitionToNext() throws Exception { - assertEquals(ScanningState.IDLE, stateMachine.getState()); + assertEquals(ScanningState.IDLE, stateMachine.getCurrentState()); stateMachine.transitionToNext(); - assertEquals(ScanningState.STARTING, stateMachine.getState()); + assertEquals(ScanningState.STARTING, stateMachine.getCurrentState()); stateMachine.transitionToNext(); - assertEquals(ScanningState.SCANNING, stateMachine.getState()); + assertEquals(ScanningState.SCANNING, stateMachine.getCurrentState()); stateMachine.transitionToNext(); - assertEquals(ScanningState.STOPPING, stateMachine.getState()); + assertEquals(ScanningState.STOPPING, stateMachine.getCurrentState()); stateMachine.transitionToNext(); - assertEquals(ScanningState.KILLING, stateMachine.getState()); + assertEquals(ScanningState.KILLING, stateMachine.getCurrentState()); stateMachine.transitionToNext(); - assertEquals(ScanningState.KILLING, stateMachine.getState()); + assertEquals(ScanningState.KILLING, stateMachine.getCurrentState()); } @Test @@ -91,10 +91,10 @@ public void transitionTo(ScanningState state, Transition transition) { stateMachine.transitionTo(ScanningState.SCANNING, null); assertEquals(1, notificationCount[0]); stateMachine.stop(); - assertEquals(ScanningState.STOPPING, stateMachine.getState()); + assertEquals(ScanningState.STOPPING, stateMachine.getCurrentState()); assertEquals(2, notificationCount[0]); stateMachine.stop(); - assertEquals(ScanningState.STOPPING, stateMachine.getState()); + assertEquals(ScanningState.STOPPING, stateMachine.getCurrentState()); assertEquals(3, notificationCount[0]); } @@ -102,39 +102,39 @@ public void transitionTo(ScanningState state, Transition transition) { public void complete() throws Exception { stateMachine.transitionTo(ScanningState.STOPPING, null); stateMachine.complete(); - assertEquals(ScanningState.IDLE, stateMachine.getState()); + assertEquals(ScanningState.IDLE, stateMachine.getCurrentState()); stateMachine.transitionTo(ScanningState.KILLING, null); stateMachine.complete(); - assertEquals(ScanningState.IDLE, stateMachine.getState()); + assertEquals(ScanningState.IDLE, stateMachine.getCurrentState()); } @Test public void rescan() throws Exception { stateMachine.transitionTo(ScanningState.IDLE, null); stateMachine.rescan(); - assertEquals(ScanningState.RESTARTING, stateMachine.getState()); + assertEquals(ScanningState.RESTARTING, stateMachine.getCurrentState()); } @Test public void startScanning() throws Exception { stateMachine.transitionTo(ScanningState.STARTING, null); stateMachine.startScanning(); - assertEquals(ScanningState.SCANNING, stateMachine.getState()); + assertEquals(ScanningState.SCANNING, stateMachine.getCurrentState()); stateMachine.transitionTo(ScanningState.RESTARTING, null); stateMachine.startScanning(); - assertEquals(ScanningState.SCANNING, stateMachine.getState()); + assertEquals(ScanningState.SCANNING, stateMachine.getCurrentState()); } @Test public void reset() throws Exception { stateMachine.transitionTo(ScanningState.STARTING, null); stateMachine.reset(); - assertEquals(ScanningState.IDLE, stateMachine.getState()); + assertEquals(ScanningState.IDLE, stateMachine.getCurrentState()); stateMachine.transitionTo(ScanningState.KILLING, null); stateMachine.reset(); - assertEquals(ScanningState.IDLE, stateMachine.getState()); + assertEquals(ScanningState.IDLE, stateMachine.getCurrentState()); } } diff --git a/test/net/azib/ipscan/gui/feeders/FeederGUIRegistryTest.java b/test/net/azib/ipscan/gui/feeders/FeederGUIRegistryTest.java index 3e73d7553..704e20912 100644 --- a/test/net/azib/ipscan/gui/feeders/FeederGUIRegistryTest.java +++ b/test/net/azib/ipscan/gui/feeders/FeederGUIRegistryTest.java @@ -47,18 +47,4 @@ public void lastFeederIsNeverNull() throws Exception { assertNotNull(registry.lastFeeder); assertNotNull(registry.lastFeeder.toString()); } - - @Test - public void createFeederRemembersTheLastOne() throws Exception { - Feeder lastFeeder = registry.createFeeder(); - assertSame(lastFeeder, registry.lastFeeder); - assertNotSame(lastFeeder, registry.createFeeder()); - } - - @Test - public void createRescanFeederGetsOriginalFeeder() throws Exception { - Feeder lastFeeder = registry.createFeeder(); - Feeder rescanFeeder = registry.createRescanFeeder(new TableItem[] {mock(TableItem.class)}); - assertEquals(lastFeeder.getId(), rescanFeeder.getId()); - } } diff --git a/test/net/azib/ipscan/util/NetBIOSResolverTest.java b/test/net/azib/ipscan/util/NetBIOSResolverTest.java index 6fcf7b439..886910c78 100644 --- a/test/net/azib/ipscan/util/NetBIOSResolverTest.java +++ b/test/net/azib/ipscan/util/NetBIOSResolverTest.java @@ -17,7 +17,7 @@ public void extractNamesNoUserNoGroup() throws Exception { "ComputerName XYY" + "\u00DE\u00AD\u00BE\u00EF\u0000\u0000 XYY" ).getBytes("ISO-8859-1"); - assertArrayEquals(new String[]{"ComputerName", null, null, "DE-AD-BE-EF-00-00"}, NetBIOSResolver.extractNames(response, 1)); + assertArrayEquals(new String[]{"ComputerName", null, null, "DE-AD-BE-EF-00-00"}, NetBIOSName.extractNames(response, 1)); } @Test @@ -27,7 +27,7 @@ public void extractNamesNoUserWithGroup() throws Exception { "GroupName \u0000\u0080\u0000" + "\u0001\u0002\u0003\u0004\u0005\u0006 XYY" ).getBytes("ISO-8859-1"); - assertArrayEquals(new String[] {"ComputerName", null, "GroupName", "01-02-03-04-05-06"}, NetBIOSResolver.extractNames(response, 2)); + assertArrayEquals(new String[] {"ComputerName", null, "GroupName", "01-02-03-04-05-06"}, NetBIOSName.extractNames(response, 2)); } @Test @@ -42,6 +42,6 @@ public void extractNamesWithUserAndGroup() throws Exception { "SomeName XYY" + "\u00DE\u00AD\u00BE\u00EF\u0000\u0000 XYY" ).getBytes("ISO-8859-1"); - assertArrayEquals(new String[] {"ComputerName", "UserName", "GroupName", "DE-AD-BE-EF-00-00"}, NetBIOSResolver.extractNames(response, 7)); + assertArrayEquals(new String[] {"ComputerName", "UserName", "GroupName", "DE-AD-BE-EF-00-00"}, NetBIOSName.extractNames(response, 7)); } }