public void testIteration() throws Exception { Blip blip = newBlip("\naaa 012 aaa 345 aaa 322", Collections.<Annotation>emptyList()); Range[] expectedRanges = {new Range(1, 4), new Range(9, 12), new Range(17, 20)}; BlipContentRefs blipRefs = blip.all("aaa"); int index = 0; for (Range range : blipRefs) { assertEquals(expectedRanges[index++], range); } assertEquals(3, index); // Now let's make sure that we can iterate again. index = 0; for (Range range : blipRefs) { assertEquals(expectedRanges[index++], range); } assertEquals(3, index); // Assert iteration with blip refs that has no match. assertFalse(blip.all("invalid").iterator().hasNext()); }
public void testIteration() throws Exception { Blip blip = newBlip("\naaa 012 aaa 345 aaa 322", Collections.<Annotation>emptyList()); Range[] expectedRanges = {new Range(1, 4), new Range(9, 12), new Range(17, 20)}; BlipContentRefs blipRefs = blip.all("aaa"); int index = 0; for (Range range : blipRefs) { assertEquals(expectedRanges[index++], range); } assertEquals(3, index); // Now let's make sure that we can iterate again. index = 0; for (Range range : blipRefs) { assertEquals(expectedRanges[index++], range); } assertEquals(3, index); // Assert iteration with blip refs that has no match. assertFalse(blip.all("invalid").iterator().hasNext()); }
public void testDocumentModifyParametersForInsertInsertAfterAndReplace() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.at(0).insert(new Image("http://a/b.gif", 100, 100, "Foo"), Plaintext.of("bold"), Plaintext.of("text")); List<OperationRequest> ops = blip.getOperationQueue().getPendingOperations(); DocumentModifyAction action = (DocumentModifyAction) ops.get(ops.size() - 1).getParameter( ParamsProperty.MODIFY_ACTION); assertEquals(3, action.getValues().size()); assertFalse(action.hasTextAt(0)); assertNull(action.getValues().get(0)); assertTrue(action.hasTextAt(1)); assertEquals("bold", action.getValues().get(1)); assertTrue(action.hasTextAt(2)); assertEquals("text", action.getValues().get(2)); assertEquals(3, action.getElements().size()); Element el = action.getElements().get(0); assertTrue(el instanceof Image); assertEquals("http://a/b.gif", ((Image) el).getUrl()); assertNull(action.getElements().get(1)); assertNull(action.getElements().get(2)); }
public void testDocumentModifyParametersForInsertInsertAfterAndReplace() throws Exception { Blip blip = newBlip(ROOT_BLIP_ID, Arrays.asList(CHILD_BLIP_ID), null); blip.at(0).insert(new Image("http://a/b.gif", 100, 100, "Foo"), Plaintext.of("bold"), Plaintext.of("text")); List<OperationRequest> ops = blip.getOperationQueue().getPendingOperations(); DocumentModifyAction action = (DocumentModifyAction) ops.get(ops.size() - 1).getParameter( ParamsProperty.MODIFY_ACTION); assertEquals(3, action.getValues().size()); assertFalse(action.hasTextAt(0)); assertNull(action.getValues().get(0)); assertTrue(action.hasTextAt(1)); assertEquals("bold", action.getValues().get(1)); assertTrue(action.hasTextAt(2)); assertEquals("text", action.getValues().get(2)); assertEquals(3, action.getElements().size()); Element el = action.getElements().get(0); assertTrue(el instanceof Image); assertEquals("http://a/b.gif", ((Image) el).getUrl()); assertNull(action.getElements().get(1)); assertNull(action.getElements().get(2)); }