@Test public void testReplaceCaption() throws Exception { ImageCaptionImpl caption = (ImageCaptionImpl) TestHelperDoc.genElem("imgcaption"); l.setCaption(caption); ImageCaptionImpl newCaption = (ImageCaptionImpl) TestHelperDoc.genElem("imgcaption"); l.replaceChild(newCaption, caption); assertTrue(newCaption == l.getCaption()); assertTrue(newCaption == l.getFirstChild()); assertTrue(newCaption == l.getLastChild()); }
@Test(expected = MalformedURLException.class) public void testEmptyExtLinkStringThrows() throws Throwable { try { l.setAttribute("extlink", ""); } catch (WrappedException e) { throw e.getCause(); } }
@Test public void testCaptionSetterAndGetter() throws Exception { assertNull(l.getCaption()); ImageCaptionImpl caption = (ImageCaptionImpl) TestHelperDoc.genElem("imgcaption"); l.setCaption(caption); assertTrue(caption == l.getCaption()); assertTrue(caption == l.getFirstChild()); assertTrue(caption == l.getLastChild()); l.setCaption(null); assertNull(l.getCaption()); assertNull(l.getFirstChild()); assertNull(l.getLastChild()); }
@Test public void testGetLinkTargetGetter() throws Exception { assertEquals(l.getSource(), l.getLinkTarget()); String intLink = "Some other target"; l.setIntLink(intLink); assertEquals(intLink, l.getLinkTarget()); l.setIntLink(null); assertEquals(l.getSource(), l.getLinkTarget()); }
@Test @Ignore public void testGetLinkTitleGetter() throws Exception { assertEquals(l.getSource(), l.getLinkTitle().getFirstChild().getNodeValue()); String alt = "Some alt text"; l.setAlt(alt); assertEquals(alt, l.getLinkTitle().getFirstChild().getNodeValue()); l.setAlt(null); assertEquals(l.getSource(), l.getLinkTitle().getFirstChild().getNodeValue()); }
private void checkVAlign(Wom3ImageVAlign valign, String value) { l.setVAlign(valign); assertEquals(valign, l.getVAlign()); assertEquals(value, l.getAttribute("valign")); l.setVAlign(null); assertEquals("", l.getAttribute("valign")); assertNull(l.getVAlign()); l.setAttribute("valign", value); assertEquals(valign, l.getVAlign()); assertEquals(value, l.getAttribute("valign")); l.setAttribute("valign", null); assertEquals("", l.getAttribute("valign")); assertNull(l.getVAlign()); }
private void checkFormat(Wom3ImageFormat format, String value) { l.setFormat(format); assertEquals(format, l.getFormat()); assertEquals(value, l.getAttribute("format")); l.setFormat(null); assertEquals("", l.getAttribute("format")); assertNull(l.getFormat()); l.setAttribute("format", value); assertEquals(format, l.getFormat()); assertEquals(value, l.getAttribute("format")); l.setAttribute("format", null); assertEquals("", l.getAttribute("format")); assertNull(l.getFormat()); }
@Test(expected = IllegalArgumentException.class) public void testSetUnknownAttributeThrows() throws Exception { l.setAttribute("I don't exist", "Doesn't matter"); }
@Test public void testCanSetSourceAttribute() throws Exception { l.setSource("Some Other Page"); }
@Test public void testExtLinkAttribute() throws Exception { l.setExtLink(new URL("http://example.com")); assertEquals(new URL("http://example.com"), l.getExtLink()); assertEquals("http://example.com", l.getAttribute("extlink")); l.setExtLink(null); assertEquals("", l.getAttribute("extlink")); assertNull(l.getExtLink()); l.setAttribute("extlink", "http://example.com"); assertEquals(new URL("http://example.com"), l.getExtLink()); assertEquals("http://example.com", l.getAttribute("extlink")); l.setAttribute("extlink", null); assertEquals("", l.getAttribute("extlink")); assertNull(l.getExtLink()); }
@Test public void testUprightAttribute() throws Exception { assertFalse(l.isUpright()); l.setUpright(true); assertTrue(l.isUpright()); assertEquals("upright", l.getAttribute("upright")); l.removeAttribute("upright"); assertFalse(l.isUpright()); l.setAttribute("upright", "Doesn't matter"); assertTrue(l.isUpright()); assertEquals("upright", l.getAttribute("upright")); l.setUpright(false); assertFalse(l.isUpright()); assertEquals("", l.getAttribute("upright")); }
@Test(expected = IllegalArgumentException.class) public void testNegativeHeightStringThrows() throws Exception { l.setAttribute("height", "-10"); }
@Test(expected = IllegalArgumentException.class) public void testIllegalHeightStringThrows() throws Exception { l.setAttribute("height", "Onehundredtwentyeight"); }
@Test public void testHeightAttribute() throws Exception { l.setHeight(128); assertEquals((Integer) 128, l.getHeight()); assertEquals("128", l.getAttribute("height")); l.setHeight(null); assertEquals("", l.getAttribute("height")); assertNull(l.getHeight()); l.setAttribute("height", "128"); assertEquals((Integer) 128, l.getHeight()); assertEquals("128", l.getAttribute("height")); l.setAttribute("height", null); assertEquals("", l.getAttribute("height")); assertNull(l.getHeight()); }
@Test public void testWidthAttribute() throws Exception { l.setWidth(128); assertEquals((Integer) 128, l.getWidth()); assertEquals("128", l.getAttribute("width")); l.setWidth(null); assertEquals("", l.getAttribute("width")); assertNull(l.getWidth()); l.setAttribute("width", "128"); assertEquals((Integer) 128, l.getWidth()); assertEquals("128", l.getAttribute("width")); l.setAttribute("width", null); assertEquals("", l.getAttribute("width")); assertNull(l.getWidth()); }
@Test public void testIntLinkAttribute() throws Exception { l.setIntLink("Some Page"); assertEquals("Some Page", l.getIntLink()); assertEquals("Some Page", l.getAttribute("intlink")); l.setIntLink(null); assertEquals("", l.getAttribute("intlink")); assertNull(l.getIntLink()); l.setAttribute("intlink", "Some Page"); assertEquals("Some Page", l.getIntLink()); assertEquals("Some Page", l.getAttribute("intlink")); l.setAttribute("intlink", null); assertEquals("", l.getAttribute("intlink")); assertNull(l.getIntLink()); }
@Test(expected = IllegalArgumentException.class) public void testCreateIMageLinkWithEmptyPageThrows() throws Exception { l.setSource(""); }
@Test public void testSetIntLinkAcceptsEmptyString() throws Exception { l.setIntLink(""); l.setAttribute("intlink", ""); }
@Test(expected = IllegalArgumentException.class) public void testCreateImageLinkWithInvalidPageThrows() throws Exception { l.setSource("{}"); }
@Test public void testCreateAndSetSourceWorks() throws Exception { l.setSource("Some Page"); assertEquals("Some Page", l.getSource()); }
@Test(expected = UnsupportedOperationException.class) public void testCannotRemoveSourceAttribute() throws Exception { l.setSource(null); }
@Test(expected = IllegalArgumentException.class) public void testIllegalIntLinkStringThrows() throws Exception { l.setAttribute("intlink", "{}"); }
@Test(expected = IllegalArgumentException.class) public void testIllegalFormatStringThrows() throws Exception { l.setAttribute("format", "I'm illegal ..."); }
@Test public void testAltAttribute() throws Exception { l.setAlt("Some text"); assertEquals("Some text", l.getAlt()); assertEquals("Some text", l.getAttribute("alt")); l.setAlt(null); assertEquals("", l.getAttribute("alt")); assertNull(l.getAlt()); l.setAttribute("alt", "Some text"); assertEquals("Some text", l.getAlt()); assertEquals("Some text", l.getAttribute("alt")); l.setAttribute("alt", null); assertEquals("", l.getAttribute("alt")); assertNull(l.getAlt()); }
@Test public void testBorderAttribute() throws Exception { assertFalse(l.isBorder()); l.setBorder(true); assertTrue(l.isBorder()); assertEquals("border", l.getAttribute("border")); l.removeAttribute("border"); assertFalse(l.isBorder()); l.setAttribute("border", "Doesn't matter"); assertTrue(l.isBorder()); assertEquals("border", l.getAttribute("border")); l.setBorder(false); assertFalse(l.isBorder()); assertEquals("", l.getAttribute("border")); }
@Test(expected = IllegalArgumentException.class) public void testIllegalVAlignStringThrows() throws Exception { l.setAttribute("valign", "I'm illegal ..."); }