mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-03 03:25:28 -04:00
Code clean-up.
This commit is contained in:
parent
f54f4370c0
commit
a7ebc1b52f
@ -101,9 +101,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static void failBecause(String message, Throwable exception) {
|
protected static void failBecause(String message, Throwable exception) {
|
||||||
AssertionError error = new AssertionError(message);
|
throw new AssertionError(message, exception);
|
||||||
error.initCause(exception);
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertProviderInstalledForName(final String pFormat, final Class<? extends ImageReader> pReaderClass) {
|
protected void assertProviderInstalledForName(final String pFormat, final Class<? extends ImageReader> pReaderClass) {
|
||||||
@ -530,6 +528,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
|||||||
// TODO: Subsample all test data
|
// TODO: Subsample all test data
|
||||||
// TODO: Subsample with varying ratios and offsets
|
// TODO: Subsample with varying ratios and offsets
|
||||||
|
|
||||||
|
@SuppressWarnings("SameParameterValue")
|
||||||
protected final void assertSubsampledImageDataEquals(String message, BufferedImage expected, BufferedImage actual, ImageReadParam param) throws IOException {
|
protected final void assertSubsampledImageDataEquals(String message, BufferedImage expected, BufferedImage actual, ImageReadParam param) throws IOException {
|
||||||
assertNotNull("Expected image was null", expected);
|
assertNotNull("Expected image was null", expected);
|
||||||
assertNotNull("Actual image was null!", actual);
|
assertNotNull("Actual image was null!", actual);
|
||||||
@ -626,37 +625,50 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
|||||||
|
|
||||||
protected void assertReadWithSourceRegionParamEqualImage(final Rectangle r, final TestData data, final int imageIndex) throws IOException {
|
protected void assertReadWithSourceRegionParamEqualImage(final Rectangle r, final TestData data, final int imageIndex) throws IOException {
|
||||||
ImageReader reader = createReader();
|
ImageReader reader = createReader();
|
||||||
reader.setInput(data.getInputStream());
|
try (ImageInputStream inputStream = data.getInputStream()) {
|
||||||
|
reader.setInput(inputStream);
|
||||||
ImageReadParam param = reader.getDefaultReadParam();
|
ImageReadParam param = reader.getDefaultReadParam();
|
||||||
|
|
||||||
// Read full image and get sub image for comparison
|
// Read full image and get sub image for comparison
|
||||||
final BufferedImage roi = reader.read(imageIndex, param).getSubimage(r.x, r.y, r.width, r.height);
|
BufferedImage original = reader.read(imageIndex, param);
|
||||||
|
final BufferedImage roi = original.getSubimage(r.x, r.y, r.width, r.height);
|
||||||
|
|
||||||
param.setSourceRegion(r);
|
param.setSourceRegion(r);
|
||||||
|
|
||||||
final BufferedImage image = reader.read(imageIndex, param);
|
final BufferedImage image = reader.read(imageIndex, param);
|
||||||
|
|
||||||
// try {
|
|
||||||
// SwingUtilities.invokeAndWait(new Runnable() {
|
|
||||||
// public void run() {
|
|
||||||
// JPanel panel = new JPanel(new FlowLayout());
|
|
||||||
// panel.add(new JLabel(new BufferedImageIcon(roi, r.width * 10, r.height * 10, true)));
|
|
||||||
// panel.add(new JLabel(new BufferedImageIcon(image, r.width * 10, r.height * 10, true)));
|
|
||||||
// JOptionPane.showConfirmDialog(null, panel);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// catch (Exception e) {
|
|
||||||
// throw new RuntimeException(e);
|
|
||||||
// }
|
|
||||||
|
|
||||||
assertNotNull("Image was null!", image);
|
assertNotNull("Image was null!", image);
|
||||||
assertEquals("Read image has wrong width: " + image.getWidth(), r.width, image.getWidth());
|
assertEquals("Read image has wrong width: " + image.getWidth(), r.width, image.getWidth());
|
||||||
assertEquals("Read image has wrong height: " + image.getHeight(), r.height, image.getHeight());
|
assertEquals("Read image has wrong height: " + image.getHeight(), r.height, image.getHeight());
|
||||||
assertImageDataEquals("Images differ", roi, image);
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertImageDataEquals("Images differ", roi, image);
|
||||||
|
}
|
||||||
|
catch (AssertionError e) {
|
||||||
|
File tempExpected = File.createTempFile("junit-expected-", ".png");
|
||||||
|
System.err.println("tempExpected.getAbsolutePath(): " + tempExpected.getAbsolutePath());
|
||||||
|
|
||||||
|
Graphics2D graphics = original.createGraphics();
|
||||||
|
try {
|
||||||
|
graphics.setColor(Color.RED);
|
||||||
|
graphics.draw(r);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
graphics.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageIO.write(original, "PNG", tempExpected);
|
||||||
|
File tempActual = File.createTempFile("junit-actual-", ".png");
|
||||||
|
System.err.println("tempActual.getAbsolutePath(): " + tempActual.getAbsolutePath());
|
||||||
|
ImageIO.write(image, "PNG", tempActual);
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
reader.dispose();
|
reader.dispose();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadWithSizeAndSourceRegionParam() {
|
public void testReadWithSizeAndSourceRegionParam() {
|
||||||
@ -1336,7 +1348,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
|||||||
// Create a listener that just makes the reader abort immediately...
|
// Create a listener that just makes the reader abort immediately...
|
||||||
IIOReadProgressListener abortingListener = mock(IIOReadProgressListener.class, "Aborter");
|
IIOReadProgressListener abortingListener = mock(IIOReadProgressListener.class, "Aborter");
|
||||||
Answer<Void> abort = new Answer<Void>() {
|
Answer<Void> abort = new Answer<Void>() {
|
||||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
public Void answer(InvocationOnMock invocation) {
|
||||||
reader.abort();
|
reader.abort();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -1569,9 +1581,8 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
|||||||
reader.dispose();
|
reader.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetDestinationOffsetNull() throws IOException {
|
public void testSetDestinationOffsetNull() {
|
||||||
final ImageReader reader = createReader();
|
final ImageReader reader = createReader();
|
||||||
TestData data = getTestData().get(0);
|
TestData data = getTestData().get(0);
|
||||||
reader.setInput(data.getInputStream());
|
reader.setInput(data.getInputStream());
|
||||||
@ -1620,7 +1631,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
|||||||
assertEquals(expectedModel.getDataType(), resultModel.getDataType());
|
assertEquals(expectedModel.getDataType(), resultModel.getDataType());
|
||||||
assertEquals(expectedModel.getNumBands(), resultModel.getNumBands());
|
assertEquals(expectedModel.getNumBands(), resultModel.getNumBands());
|
||||||
assertEquals(expectedModel.getNumDataElements(), resultModel.getNumDataElements());
|
assertEquals(expectedModel.getNumDataElements(), resultModel.getNumDataElements());
|
||||||
assertTrue(Arrays.equals(expectedModel.getSampleSize(), resultModel.getSampleSize()));
|
assertArrayEquals(expectedModel.getSampleSize(), resultModel.getSampleSize());
|
||||||
assertEquals(expectedModel.getTransferType(), resultModel.getTransferType());
|
assertEquals(expectedModel.getTransferType(), resultModel.getTransferType());
|
||||||
for (int i = 0; i < expectedModel.getNumBands(); i++) {
|
for (int i = 0; i < expectedModel.getNumBands(); i++) {
|
||||||
assertEquals(expectedModel.getSampleSize(i), resultModel.getSampleSize(i));
|
assertEquals(expectedModel.getSampleSize(i), resultModel.getSampleSize(i));
|
||||||
@ -1692,13 +1703,13 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
|||||||
|
|
||||||
@Ignore("TODO: Implement")
|
@Ignore("TODO: Implement")
|
||||||
@Test
|
@Test
|
||||||
public void testSetDestinationBands() throws IOException {
|
public void testSetDestinationBands() {
|
||||||
throw new UnsupportedOperationException("Method testSetDestinationBands not implemented"); // TODO: Implement
|
throw new UnsupportedOperationException("Method testSetDestinationBands not implemented"); // TODO: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore("TODO: Implement")
|
@Ignore("TODO: Implement")
|
||||||
@Test
|
@Test
|
||||||
public void testSetSourceBands() throws IOException {
|
public void testSetSourceBands() {
|
||||||
throw new UnsupportedOperationException("Method testSetDestinationBands not implemented"); // TODO: Implement
|
throw new UnsupportedOperationException("Method testSetDestinationBands not implemented"); // TODO: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1826,7 +1837,7 @@ public abstract class ImageReaderAbstractTest<T extends ImageReader> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getSimpleName() + ": " + String.valueOf(input);
|
return String.format("%s: %s", getClass().getSimpleName(), input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user