protected String readField (InputStreamReader r, String fieldName, int len, String type, String separator) throws IOException { String fieldValue = read (r, len, type, separator); if (isBinary(type)) fieldValue = ISOUtil.hexString (fieldValue.getBytes (charset)); fields.put (fieldName, fieldValue); // System.out.println ("++++ "+fieldName + ":" + fieldValue + " " + type + "," + isBinary(type)); return fieldValue; }
@Test( expected = EOFException.class) public void testReadThrowsEOFException() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath"); when(is.read(new char[] { (char) 00 })).thenReturn(Integer.valueOf(1)); when(is.read(new char[] { (char) 00 })).thenReturn(Integer.valueOf(1)); when(is.read(new char[] { (char) 00 })).thenReturn(Integer.valueOf(-1)); fSDMsg.read(is, 100, " ", null); fail("Expected EOFException to be thrown"); }
@Test public void testRead() throws Throwable { ByteArrayInputStream bais = new ByteArrayInputStream(new byte[3]); FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath"); String result = fSDMsg.read(new InputStreamReader(bais), 1, "", null); assertEquals("result", "\u0000", result); }
@Test public void testRead1() throws Throwable { ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2]); FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath"); String result = fSDMsg.read(new InputStreamReader(bais), 0, " ", null); assertEquals("result", "", result); }
@Test public void testReadThrowsRuntimeException() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); InputStream is = new ByteArrayInputStream(new byte[2]); InputStreamReader r = new InputStreamReader(is); try { fSDMsg.read(r, 100, "3Ch", "Ch"); fail("Expected RuntimeException to be thrown"); } catch (RuntimeException ex) { assertEquals("ex.getMessage()", "Invalid separator 'Ch'", ex.getMessage()); assertEquals("(ByteArrayInputStream) is.available()", 2, is.available()); } }
@Test public void testRead2() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); String result = fSDMsg.read(is, 0, "2C", null); assertEquals("result", "", result); }
@Test public void testReadMoreThanInputThrowsEOFException() throws Throwable { FSDMsg fSDMsg = new FSDMsg("testFSDMsgBasePath", "testFSDMsgBaseSchema"); InputStream is = new ByteArrayInputStream(new byte[2]); InputStreamReader r = new InputStreamReader(is); try { fSDMsg.read(r, 100, null, null); fail("Expected EOFException to be thrown"); } catch (EOFException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertEquals("(ByteArrayInputStream) is.available()", 0, is.available()); } }