LineFeed1LineReader implements LineReader { @Override public String readLine() { StringBuilder currentLineStringBuilder = new StringBuilder(); char currentChar = Character.MIN_VALUE; char lineFeedChar1 = lineFeedChar.charAt(0); int chr = 0; try { while ((chr = reader.read()) != -1) { currentChar = (char) chr; if (currentChar == lineFeedChar1) { break; } currentLineStringBuilder.append(currentChar); } } catch (IOException e) { throw new FileException("Reader control operation was failed.", e); } return currentLineStringBuilder.toString(); } LineFeed1LineReader(Reader reader, String lineFeedChar); @Override String readLine();  }
@Test public void testReadLine01() throws Exception { Reader reader = mock(Reader.class); when(reader.read()).thenThrow(new IOException()); String tempLineFeedChar = "\r"; LineFeed1LineReader lineFeed1LineReader = new LineFeed1LineReader(reader, tempLineFeedChar); try { lineFeed1LineReader.readLine(); fail("FileExceptionが発生しませんでした。"); } catch (FileException e) { assertTrue(e instanceof FileException); assertEquals("Reader control operation was failed.", e .getMessage()); assertTrue(e.getCause() instanceof IOException); } }
@Test public void testReadLine02() throws Exception { String str = ""; StringReader stringReader = new StringReader(str); BufferedReader bufReader = new BufferedReader(stringReader); String tempLineFeedChar = "\r"; LineFeed1LineReader lineFeed1LineReader = new LineFeed1LineReader(bufReader, tempLineFeedChar); String lineFeedChar = "\r"; ReflectionTestUtils.setField(lineFeed1LineReader, "lineFeedChar", lineFeedChar); String resutl = lineFeed1LineReader.readLine(); assertEquals("", resutl); }
@Test public void testReadLine03() throws Exception { String str = "aaa,aaa,aaa\r"; StringReader stringReader = new StringReader(str); BufferedReader bufReader = new BufferedReader(stringReader); String tempLineFeedChar = "\r"; LineFeed1LineReader lineFeed1LineReader = new LineFeed1LineReader(bufReader, tempLineFeedChar); String resutl = lineFeed1LineReader.readLine(); assertEquals("aaa,aaa,aaa", resutl); }
@Test public void testReadLine04() throws Exception { String str = "\"aaa\",\"aaa\",\"aaa\"\r"; StringReader stringReader = new StringReader(str); BufferedReader bufReader = new BufferedReader(stringReader); String tempLineFeedChar = "\r"; LineFeed1LineReader lineFeed1LineReader = new LineFeed1LineReader(bufReader, tempLineFeedChar); String resutl = lineFeed1LineReader.readLine(); assertEquals("\"aaa\",\"aaa\",\"aaa\"", resutl); }
@Test public void testReadLine05() throws Exception { String str = "\"aa,a\",\"aa\"\"a\",\"aaa\"\r"; StringReader stringReader = new StringReader(str); BufferedReader bufReader = new BufferedReader(stringReader); String tempLineFeedChar = "\r"; LineFeed1LineReader lineFeed1LineReader = new LineFeed1LineReader(bufReader, tempLineFeedChar); String result = lineFeed1LineReader.readLine(); assertEquals("\"aa,a\",\"aa\"\"a\",\"aaa\"", result); }
@Test public void testReadLine06() throws Exception { String str = "\"aaa\",\"aaa\",\"aa\ra\"\r"; StringReader stringReader = new StringReader(str); BufferedReader bufReader = new BufferedReader(stringReader); String tempLineFeedChar = "\r"; LineFeed1LineReader lineFeed1LineReader = new LineFeed1LineReader(bufReader, tempLineFeedChar); String result = lineFeed1LineReader.readLine(); assertEquals("\"aaa\",\"aaa\",\"aa", result); }
@Test public void testReadLine07() throws Exception { String str = "\"aaa\",\"aaa\",\"aaa\"aaa\r"; StringReader stringReader = new StringReader(str); BufferedReader bufReader = new BufferedReader(stringReader); String tempLineFeedChar = "\r"; LineFeed1LineReader lineFeed1LineReader = new LineFeed1LineReader(bufReader, tempLineFeedChar); String resutl = lineFeed1LineReader.readLine(); assertEquals("\"aaa\",\"aaa\",\"aaa\"aaa", resutl); }
@Test public void testReadLine08() throws Exception { String str = "aaa,aaa,aaa"; StringReader stringReader = new StringReader(str); BufferedReader bufReader = new BufferedReader(stringReader); String tempLineFeedChar = "\r"; LineFeed1LineReader lineFeed1LineReader = new LineFeed1LineReader(bufReader, tempLineFeedChar); String resutl = lineFeed1LineReader.readLine(); assertEquals("aaa,aaa,aaa", resutl); }
@Test public void testReadLine09() throws Exception { String str = "\"ａａ,ａ\",\"ａａ\"\"ａ\",\"ａａａ\"\r"; StringReader stringReader = new StringReader(str); BufferedReader bufReader = new BufferedReader(stringReader); String tempLineFeedChar = "\r"; LineFeed1LineReader lineFeed1LineReader = new LineFeed1LineReader(bufReader, tempLineFeedChar); String resutl = lineFeed1LineReader.readLine(); assertEquals("\"ａａ,ａ\",\"ａａ\"\"ａ\",\"ａａａ\"", resutl); }
@Test public void testReadLine10() throws Exception { String str = "aaa,aaa,aaa\raaa,aaa,aaa\raaa,aaa,aaa\r"; StringReader stringReader = new StringReader(str); BufferedReader bufReader = new BufferedReader(stringReader); String tempLineFeedChar = "\r"; LineFeed1LineReader lineFeed1LineReader = new LineFeed1LineReader(bufReader, tempLineFeedChar); String resutl = lineFeed1LineReader.readLine(); assertEquals("aaa,aaa,aaa", resutl); }