public void testRead() throws IOException { UnsyncStringReader unsyncStringReader = new UnsyncStringReader("abc"); assertEquals('a', unsyncStringReader.read()); assertEquals('b', unsyncStringReader.read()); assertEquals('c', unsyncStringReader.read()); assertEquals(-1, unsyncStringReader.read()); }
public void testSkip() throws IOException { UnsyncStringReader unsyncStringReader = new UnsyncStringReader("abcdef"); assertEquals('a', unsyncStringReader.read()); assertEquals(2, unsyncStringReader.skip(2)); assertEquals('d', unsyncStringReader.read()); assertEquals(2, unsyncStringReader.skip(3)); assertEquals(-1, unsyncStringReader.read()); }
public void testBlockRead() throws IOException { UnsyncStringReader unsyncStringReader = new UnsyncStringReader("abcdefg"); char[] chars = new char[4]; assertEquals(4, unsyncStringReader.read(chars)); assertEquals(4, unsyncStringReader.index); assertTrue(Arrays.equals("abcd".toCharArray(), chars)); assertEquals(3, unsyncStringReader.read(chars)); assertEquals('e', chars[0]); assertEquals('f', chars[1]); assertEquals('g', chars[2]); assertEquals(-1, unsyncStringReader.read(chars)); }
public void testMarkAndReset() throws IOException { UnsyncStringReader unsyncStringReader = new UnsyncStringReader("abc"); assertEquals('a', unsyncStringReader.read()); unsyncStringReader.mark(-1); assertEquals('b', unsyncStringReader.read()); assertEquals('c', unsyncStringReader.read()); assertEquals(-1, unsyncStringReader.read()); unsyncStringReader.reset(); assertEquals('b', unsyncStringReader.read()); assertEquals('c', unsyncStringReader.read()); assertEquals(-1, unsyncStringReader.read()); }
public void testClose() { UnsyncStringReader unsyncStringReader = new UnsyncStringReader("abcdefg"); unsyncStringReader.close(); assertTrue(unsyncStringReader.string == null); try { unsyncStringReader.mark(0); fail(); } catch (IOException ioe) { } try { unsyncStringReader.read(); fail(); } catch (IOException ioe) { } try { unsyncStringReader.read(new char[5]); fail(); } catch (IOException ioe) { } try { unsyncStringReader.ready(); fail(); } catch (IOException ioe) { } try { unsyncStringReader.reset(); fail(); } catch (IOException ioe) { } unsyncStringReader.close(); }