Skip to content

Commit

Permalink
added ImageLoaderBarcodeTest
Browse files Browse the repository at this point in the history
  • Loading branch information
SingingBush committed Jul 23, 2024
1 parent 09151d3 commit 8a514f0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class ImageBarcode extends AbstractImage {

static final Object MESSAGE = "Message";

private Configuration barcodeXML;
private BarcodeDimension bardim;
private final Configuration barcodeXML;
private final BarcodeDimension bardim;

/**
* Main constructor.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.krysalis.barcode4j.image.loader;

import org.apache.xmlgraphics.image.loader.Image;
import org.apache.xmlgraphics.image.loader.ImageException;
import org.apache.xmlgraphics.image.loader.ImageFlavor;
import org.apache.xmlgraphics.image.loader.ImageInfo;
import org.apache.xmlgraphics.image.loader.spi.ImageLoader;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class ImageLoaderBarcodeTest {

@Test
@DisplayName("Should load original ImageBarcode when instantiated with BARCODE_IMAGE_FLAVOR target")
void testSupportedTargetFlavor_Barcode4jImageFlavor() throws ImageException, IOException {
final ImageBarcode originalImage = mock(ImageBarcode.class);

final ImageInfo info = mock(ImageInfo.class);
when(info.getOriginalImage()).thenReturn(originalImage);

final ImageLoader loader = new ImageLoaderBarcode(ImageBarcode.BARCODE_IMAGE_FLAVOR);

final Image result = loader.loadImage(info, null, null);

assertNotNull(result);
assertEquals(originalImage, result);
}

@Test
@DisplayName("Should throw IllegalArgumentException with target flavor: BUFFERED_IMAGE")
void testUnsupportedTargetFlavor_BufferedImage() {
assertThrows(IllegalArgumentException.class, () -> {
new ImageLoaderBarcode(ImageFlavor.BUFFERED_IMAGE);
});
}

@Test
@DisplayName("Should throw IllegalArgumentException with target flavor: RENDERED_IMAGE")
void testUnsupportedTargetFlavor_RenderedImage() {
assertThrows(IllegalArgumentException.class, () -> {
new ImageLoaderBarcode(ImageFlavor.RENDERED_IMAGE);
});
}
}

0 comments on commit 8a514f0

Please sign in to comment.