Exemple #1
0
 private void assertAddressCount(String s, int addressCount) {
   StringReader reader = new StringReader(s);
   FileFeeder feeder = new FileFeeder(reader);
   int numAddresses = 0;
   while (feeder.hasNext()) {
     feeder.next();
     numAddresses++;
   }
   assertEquals(addressCount, numAddresses);
 }
Exemple #2
0
  @Test
  public void requestedPortsAreDetected() throws Exception {
    StringReader reader =
        new StringReader("1.2.3.4:1234\n2.3.4.5:\n 7.6.5.4:789004\n 1.2.3.5:80  1.2.3.5:3128 ");
    FileFeeder fileFeeder = new FileFeeder(reader);

    assertEquals(1234, (int) fileFeeder.next().requestedPortsIterator().next());
    assertFalse(fileFeeder.next().isAnyPortRequested());
    assertFalse(fileFeeder.next().isAnyPortRequested());

    ScanningSubject lastSubject = fileFeeder.next();
    assertEquals("1.2.3.5", lastSubject.getAddress().getHostAddress());
    Iterator<Integer> portIterator = lastSubject.requestedPortsIterator();
    assertEquals(80, (int) portIterator.next());
    assertEquals(3128, (int) portIterator.next());
  }
Exemple #3
0
 @Test
 public void testHappyPath() throws FeederException {
   StringReader reader = new StringReader("10.11.12.13 10.11.12.14 10.11.12.15");
   FileFeeder fileFeeder = new FileFeeder(reader);
   assertTrue(fileFeeder.hasNext());
   assertEquals("10.11.12.13", fileFeeder.next().getAddress().getHostAddress());
   assertTrue(fileFeeder.hasNext());
   assertEquals("10.11.12.14", fileFeeder.next().getAddress().getHostAddress());
   assertTrue(fileFeeder.hasNext());
   assertEquals("10.11.12.15", fileFeeder.next().getAddress().getHostAddress());
   assertFalse(fileFeeder.hasNext());
 }
Exemple #4
0
  @Test
  public void testGetPercentageComplete() throws Exception {
    StringReader reader = new StringReader("1.2.3.4, 2.3.4.5, mega cool 0.0.0.0");
    FileFeeder fileFeeder = new FileFeeder(reader);
    assertEquals(0, fileFeeder.percentageComplete());
    fileFeeder.next();
    assertEquals(33, fileFeeder.percentageComplete());
    fileFeeder.next();
    assertEquals(67, fileFeeder.percentageComplete());
    fileFeeder.next();
    assertEquals(100, fileFeeder.percentageComplete());

    reader = new StringReader("255.255.255.255");
    fileFeeder = new FileFeeder(reader);
    assertEquals(0, fileFeeder.percentageComplete());
    fileFeeder.next();
    assertEquals(100, fileFeeder.percentageComplete());
  }
Exemple #5
0
 @Test
 public void testGetInfo() {
   StringReader reader = new StringReader("255.255.255.255, 2.3.4.5, mega cool 0.0.0.0");
   FileFeeder fileFeeder = new FileFeeder(reader);
   assertEquals("3", fileFeeder.getInfo());
 }