@Test //(expected = IllegalArgumentException.class) public void testFromNullInputStream() throws Exception{ try { InputStream is = null; Image img = Image.from_STREAM("leo.png", is); throw new Exception("It shouldn't get here"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("Can't create image - null input stream")); } }
@Test //(expected = IllegalArgumentException.class) public void testFromSmallFilenameInputStream() throws Exception{ try { InputStream is = new BufferedInputStream( new FileInputStream(Utils.getAppRoot() + "/src/test/resources/dtpick.gif")); Image img = Image.from_STREAM("12", is); throw new Exception("It shouldn't get here"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("Can't create image - invalid filename")); } }
@Test public void testFromInputStream() throws FileNotFoundException{ InputStream is = new BufferedInputStream( new FileInputStream(Utils.getAppRoot() + "/src/test/resources/dtpick.gif")); Image img = Image.from_STREAM("leo.png", is); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*w:pict>")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shapetype")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shape[ >]")); //white space or > assertEquals(2, TestUtils.regexCount(img.getContent(), "wordml")); assertEquals(1, TestUtils.regexCount(img.getContent(), "width:16pt;height:16pt")); assertEquals(1, TestUtils.regexCount(img.getContent(), "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAAD")); }