test written for prepareText in StatisticsDialog

git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@393 375186e5-ef17-0410-b0b6-91563547dcda
This commit is contained in:
angryziber 2008-04-12 21:29:13 +00:00
parent f597e582f0
commit 30f04aa82d
3 changed files with 49 additions and 9 deletions

View File

@ -289,14 +289,14 @@ public class ScanningResultList implements Iterable<ScanningResult> {
*/
public static class ScanInfo {
boolean scanFinished;
boolean scanAborted;
protected boolean scanFinished;
protected boolean scanAborted;
long startTime = System.currentTimeMillis();
long endTime;
int numScanned;
int numAlive;
int numWithPorts;
protected long startTime = System.currentTimeMillis();
protected long endTime;
protected int numScanned;
protected int numAlive;
protected int numWithPorts;
/**
* @return total scan time, in milliseconds.

View File

@ -81,7 +81,7 @@ public class StatisticsDialog extends AbstractModalDialog {
Text statsText = new Text(shell, SWT.MULTI | SWT.READ_ONLY);
statsText.setBackground(currentDisplay.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
statsText.setLayoutData(LayoutHelper.formData(new FormAttachment(iconLabel), null, new FormAttachment(titleLabel), null));
statsText.setText(prepareText(scanningResults.getScanInfo()));
statsText.setText(prepareText());
statsText.pack();
Button button = createCloseButton();
@ -92,7 +92,8 @@ public class StatisticsDialog extends AbstractModalDialog {
shell.pack();
}
private String prepareText(ScanInfo scanInfo) {
String prepareText() {
ScanInfo scanInfo = scanningResults.getScanInfo();
String ln = System.getProperty("line.separator");
StringBuilder text = new StringBuilder();
text.append(Labels.getLabel("text.scan.time.total"))

View File

@ -6,11 +6,19 @@
package net.azib.ipscan.gui;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Locale;
import net.azib.ipscan.config.Labels;
import net.azib.ipscan.core.ScanningResultList;
import net.azib.ipscan.core.ScanningResultList.ScanInfo;
import org.junit.Test;
@ -33,4 +41,35 @@ public class StatisticsDialogTest {
assertEquals("1\u00A0h", StatisticsDialog.timeToText(3600000));
assertEquals("2.5\u00A0h", StatisticsDialog.timeToText(9036000));
}
@Test
public void testname() throws Exception {
ScanningResultList results = createMock(ScanningResultList.class);
ScanInfo scanInfo = new ScanInfo() {
{
this.startTime = System.currentTimeMillis();
this.endTime = this.startTime + 10000;
this.numScanned = 20;
this.numAlive = 10;
this.numWithPorts = 5;
}
};
expect(results.getScanInfo()).andReturn(scanInfo);
expect(results.getFeederName()).andReturn("SomeFeeder");
expect(results.getFeederInfo()).andReturn("SomeInfoHere");
replay(results);
String text = new StatisticsDialog(results).prepareText();
assertNotNull(text);
assertTrue(text.contains(Labels.getLabel("text.scan.time.total") + "10"));
assertTrue(text.contains(Labels.getLabel("text.scan.time.average") + "0.5"));
assertTrue(text.contains("SomeFeeder"));
assertTrue(text.contains("SomeInfoHere"));
assertTrue(text.contains(Labels.getLabel("text.scan.hosts.total") + "20"));
assertTrue(text.contains(Labels.getLabel("text.scan.hosts.alive") + "10"));
assertTrue(text.contains(Labels.getLabel("text.scan.hosts.ports") + "5"));
verify(results);
}
}