XmlDataReader implements DataReader { @Override public Data read(@Nonnull final String data) { Check.notNull(data, "data"); return readXml(new ByteArrayInputStream(data.getBytes(DEFAULT_CHARSET)), DEFAULT_CHARSET); }  @Override Data read(@Nonnull final String data); @Override Data read(@Nonnull final URL url, @Nonnull final Charset charset);  }
@Test(expected = IllegalNullArgumentException.class) public void read_charset_null() throws MalformedURLException { new XmlDataReader().read(new URL("http: }
@Test(expected = IllegalNullArgumentException.class) public void read_data_isNull() throws MalformedURLException { new XmlDataReader().read(null); }
@Test(expected = IllegalNullArgumentException.class) public void read_url_null() { new XmlDataReader().read((URL) null, CHARSET); }
@Test public void read_url_unreachable() throws MalformedURLException { final Data data = new XmlDataReader().read(new URL("http: assertThat(data).isSameAs(Data.EMPTY); }
@Test public void readByString_parsingOfCorruptedData() throws IOException { final XmlDataReader reader = new XmlDataReader(); final String dataAsString = CharStreams.toString(new InputStreamReader(CORRUPTED_DATA_URL.openStream())); final Data data = reader.read(dataAsString); assertThat(data).isSameAs(Data.EMPTY); }
@Test public void readByString_parsingOfDirtyData() throws IOException { final XmlDataReader reader = new XmlDataReader(); final String dataAsString = CharStreams.toString(new InputStreamReader(DIRTY_DATA_URL.openStream())); final Data data = reader.read(dataAsString); assertThat(data).isSameAs(Data.EMPTY); }
@Test public void readByString_parsingSuccessful() throws IOException { final XmlDataReader reader = new XmlDataReader(); final String dataAsString = CharStreams.toString(new InputStreamReader(DATA_URL.openStream())); final Data data = reader.read(dataAsString); assertThat(data.getVersion()).isEqualTo(TestXmlDataStore.VERSION_OLDER); }
@Test public void readByUrl_parsingOfCorruptedData() throws IOException { final XmlDataReader reader = new XmlDataReader(); final Data data = reader.read(CORRUPTED_DATA_URL, CHARSET); assertThat(data).isSameAs(Data.EMPTY); }
@Test public void readByUrl_parsingOfDirtyData() throws IOException { final XmlDataReader reader = new XmlDataReader(); final Data data = reader.read(DIRTY_DATA_URL, CHARSET); assertThat(data).isSameAs(Data.EMPTY); }
@Test public void readByUrl_versionParsing() throws IOException { final DataReader reader = new XmlDataReader(); final Data data = reader.read(DATA_URL, CHARSET); assertThat(data.getVersion()).isEqualTo(TestXmlDataStore.VERSION_OLDER); }