/** * Constructs an external image given a url, image dimensions, and a caption. * * @param url the url for the external image. * @param width the width of the image. * @param height the height of the image. * @param caption the caption for the image. */ public Image(String url, int width, int height, String caption) { this(); setUrl(url); setWidth(width); setHeight(height); setCaption(caption); }
@Override public Element fromXml(Document doc, E element, Wavelet wavelet) { Image image = new Image(); if (doc.getAttribute(element, "src") != null) { image.setUrl(doc.getAttribute(element, "src")); } if (doc.getAttribute(element, "alt") != null) { image.setCaption(doc.getAttribute(element, "alt")); } if (doc.getAttribute(element, "width") != null) { image.setWidth(Integer.parseInt(doc.getAttribute(element, "width"))); } if (doc.getAttribute(element, "height") != null) { image.setHeight(Integer.parseInt(doc.getAttribute(element, "height"))); } return image; } });
public void testGetHeight() { Image image = new Image(); image.setHeight(HEIGHT); assertEquals(HEIGHT, image.getHeight()); image = new Image(); try { image.getHeight(); fail("Should have failed with IllegalStateException. Calling getHeight() is not allowed if " + "the image doesn't have a height."); } catch (IllegalStateException e) { // Expected. } } }
public void testGetHeight() { Image image = new Image(); image.setHeight(HEIGHT); assertEquals(HEIGHT, image.getHeight()); image = new Image(); try { image.getHeight(); fail("Should have failed with IllegalStateException. Calling getHeight() is not allowed if " + "the image doesn't have a height."); } catch (IllegalStateException e) { // Expected. } } }
public void testGettersAndSetters() { Image image = new Image(); image.setAttachmentId(ATTACHMENT_ID); image.setCaption(CAPTION); image.setUrl(URL); image.setWidth(WIDTH); image.setHeight(HEIGHT); assertEquals(ATTACHMENT_ID, image.getAttachmentId()); assertEquals(CAPTION, image.getCaption()); assertEquals(URL, image.getUrl()); assertEquals(WIDTH, image.getWidth()); assertEquals(HEIGHT, image.getHeight()); }
public void testGettersAndSetters() { Image image = new Image(); image.setAttachmentId(ATTACHMENT_ID); image.setCaption(CAPTION); image.setUrl(URL); image.setWidth(WIDTH); image.setHeight(HEIGHT); assertEquals(ATTACHMENT_ID, image.getAttachmentId()); assertEquals(CAPTION, image.getCaption()); assertEquals(URL, image.getUrl()); assertEquals(WIDTH, image.getWidth()); assertEquals(HEIGHT, image.getHeight()); }