コード例 #1
0
  @Test
  public void testRead() {
    try (FileInput instance = new FileInput(testsFileName)) {

      String str =
          "token1,token2,token3\n\napples, oranges, pears\none , two , three\na,b,c,d,e,f\nunos, dos,tres,,quatorze\n\nlast, complete, line,\n# comment1, comment2, comment3\n\n";
      String contents = instance.read();
      assertTrue(str.equals(contents));

    } catch (IOException ex) {
      fail("Caught IOException in testReadNextLine()");
    }
  }
コード例 #2
0
  @Test
  public void testReadNextLine() {
    try (FileInput instance = new FileInput(testsFileName)) {

      String line = instance.readNextLine();
      assertTrue("token1,token2,token3".equals(line));

      line = instance.readNextLine();
      assertTrue("apples, oranges, pears".equals(line));

      line = instance.readNextLine();
      assertTrue("one , two , three".equals(line));

      line = instance.readNextLine();
      assertTrue("a,b,c,d,e,f".equals(line));

      line = instance.readNextLine();
      assertTrue("unos, dos,tres,,quatorze".equals(line));

      line = instance.readNextLine();
      assertTrue("last, complete, line,".equals(line));

      line = instance.readNextLine();
      assertNull(line);

    } catch (IOException ex) {
      fail("Caught IOException in testReadNextLine()");
    }
  }
コード例 #3
0
  @Test
  public void testReadNextLineAsTokensUsingDefaultSeparator() {
    try (FileInput instance = new FileInput(testsFileName)) {
      List<String> line = instance.readLine();
      assertTrue(Arrays.asList("token1", "token2", "token3").equals(line));

      line = instance.readLine();
      assertTrue(Arrays.asList("apples", "", "oranges", "", "pears").equals(line));

      line = instance.readLine();
      assertTrue(Arrays.asList("one", "", "", "two", "", "", "three").equals(line));

      line = instance.readLine();
      assertTrue(Arrays.asList("a", "b", "c", "d", "e", "f").equals(line));

      line = instance.readLine();
      assertTrue(Arrays.asList("unos", "", "dos", "tres", "", "quatorze").equals(line));

      line = instance.readLine();
      assertTrue(Arrays.asList("last", "", "complete", "", "line", "").equals(line));

      line = instance.readLine();
      assertTrue(line.isEmpty());
    } catch (IOException ex) {
      fail("Caught IOException in testReadNextLine()");
    }
  }
コード例 #4
0
 @Test
 public void testclose() {
   try (FileInput instance = new FileInput(testsFileName)) {
     instance.readLine();
     instance.readLine();
     instance.close();
     try {
       instance.readLine();
       fail(
           "Expected IOException to be thrown after using a method on a closed FileInput object.");
     } catch (IOException ex) {
       // we expect an IOException to be caught here because the FileInput object is closed when
       // the readLine
       // method is called.
     }
   } catch (IOException ex) {
     fail("Caught IOException in testClose()");
   }
 }