1 package com.atlassian.core.util;
2
3 import org.apache.commons.io.IOUtils;
4
5 import java.io.InputStream;
6
7 import junit.framework.TestCase;
8
9 public class TestImageInfo extends TestCase
10 {
11
12 public void testCheckJPeg() throws Exception
13 {
14 assertTrue(checkImage("/image.jpg"));
15 }
16
17 public void testCheckPng() throws Exception
18 {
19 assertTrue(checkImage("/image.png"));
20 }
21
22 public void testCheckGif() throws Exception
23 {
24 assertTrue(checkImage("/image.gif"));
25 }
26
27 public void testCheckJPegWithInvalidData() throws Exception
28 {
29 assertFalse(checkImage("/image_invalid.jpg"));
30 }
31
32 private boolean checkImage(String filename)
33 {
34 ImageInfo imageInfo = new ImageInfo();
35 InputStream stream = this.getClass().getResourceAsStream(filename);
36 try
37 {
38 imageInfo.setInput(stream);
39 return imageInfo.check();
40 }
41 finally
42 {
43 IOUtils.closeQuietly(stream);
44 }
45 }
46
47 }