@Test public void testWithNameTypeAndInvalidData() { try (NameSampleDataStream sampleStream = new NameSampleDataStream( ObjectStreamUtils.createObjectStream("<START:> Name <END>"))) { sampleStream.read(); fail(); } catch (IOException expected) { // the read above is expected to throw an exception } try (NameSampleDataStream sampleStream = new NameSampleDataStream( ObjectStreamUtils.createObjectStream( "<START:street> <START:person> Name <END> <END>"))) { sampleStream.read(); fail(); } catch (IOException expected) { // the read above is expected to throw an exception } }
/** * Checks that invalid spans cause an {@link ObjectStreamException} to be thrown. */ @Test public void testWithoutNameTypeAndInvalidData() { try (NameSampleDataStream sampleStream = new NameSampleDataStream( ObjectStreamUtils.createObjectStream("<START> <START> Name <END>"))) { sampleStream.read(); fail(); } catch (IOException expected) { // the read above is expected to throw an exception } try (NameSampleDataStream sampleStream = new NameSampleDataStream( ObjectStreamUtils.createObjectStream("<START> Name <END> <END>"))) { sampleStream.read(); fail(); } catch (IOException expected) { // the read above is expected to throw an exception } try (NameSampleDataStream sampleStream = new NameSampleDataStream( ObjectStreamUtils.createObjectStream( "<START> <START> Person <END> Street <END>"))) { sampleStream.read(); fail(); } catch (IOException expected) { // the read above is expected to throw an exception } }
while ((ns = ds.read()) != null) { Span[] nameSpans = ns.getNames();
NameSample ns = ds.read(); ns = ds.read(); assertEquals(1, ns.getSentence().length); assertEquals("<head/>", ns.getSentence()[0]); ns = ds.read(); assertEquals(1, ns.getSentence().length); assertEquals("<body>", ns.getSentence()[0]); ns = ds.read(); assertEquals(1, ns.getSentence().length); assertEquals("<ul>", ns.getSentence()[0]); ns = ds.read(); assertEquals(6, ns.getSentence().length); assertEquals("<li>", ns.getSentence()[0]); ns = ds.read(); assertEquals(7, ns.getSentence().length); assertEquals("<li>", ns.getSentence()[0]); ns = ds.read(); assertEquals(1, ns.getSentence().length); assertEquals("</ul>", ns.getSentence()[0]); ns = ds.read(); assertEquals(1, ns.getSentence().length); assertEquals("</body>", ns.getSentence()[0]);