private void testFormat(String format) { ImageReader reader = ImageIO.getImageReadersByFormatName(format).next(); ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next(); assertEquals( "getImageReader() returns an incorrect reader for " + format, ImageIO.getImageReader(writer).getClass(), reader.getClass()); assertEquals( "getImageWriter() returns an incorrect writer for " + format, ImageIO.getImageWriter(reader).getClass(), writer.getClass()); }
public void testGetNullReaderWriter() throws Exception { try { ImageIO.getImageWriter(null); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { // Ok } try { ImageIO.getImageReader(null); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { // Ok } }
public void testGetWriterMIMETypes() { Set<String> expectedMIMETypes = new HashSet<String>(Arrays.asList(new String[] {"image/x-png", "image/png", "image/jpeg"})); Set<String> actualMIMETypes = new HashSet<String>(Arrays.asList(ImageIO.getWriterMIMETypes())); assertTrue(actualMIMETypes.containsAll(expectedMIMETypes)); }
public void testReadURL() throws Exception { // Regression for HARMONY-3135 for (URL url : listImages()) { assertNotNull("Failed to load image from URL " + url, ImageIO.read(url)); assertFalse( "The current thread has been interrupted! URL: " + url, // $NON-NLS-1$ Thread.currentThread().isInterrupted()); } }
public void testGetWriterFormatNames() { Set<String> expectedFormatNames = new HashSet<String>( Arrays.asList(new String[] {"JPG", "jpg", "JPEG", "jpeg", "PNG", "png"})); Set<String> actualFormatNames = new HashSet<String>(Arrays.asList(ImageIO.getWriterFormatNames())); assertTrue(actualFormatNames.containsAll(expectedFormatNames)); }
public void testCache() throws Exception { ImageIO.setUseCache(true); assertTrue("Failed to enable cache", ImageIO.getUseCache()); ImageIO.setUseCache(false); assertFalse("Failed to disable cache", ImageIO.getUseCache()); ImageIO.setCacheDirectory(null); assertNull("Failed to set cache directory", ImageIO.getCacheDirectory()); try { ImageIO.setCacheDirectory(new File("")); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException expected) { // OK } }