diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..6cdecdb --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,31 @@ +name: Java CI with Maven + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 7 + uses: actions/setup-java@v1 + with: + java-version: 7 + - name: Compile + run: mvn -B compile + - name: Test + run: mvn -B test + - name: Package + run: mvn -B package + - uses: actions/upload-artifact@v2 + with: + name: artifacts + path: | + target/*.jar + diff --git a/test/net/sf/image4j/codec/bmp/BMPDecoderTest.java b/test/net/sf/image4j/codec/bmp/BMPDecoderTest.java index dff0970..c608585 100644 --- a/test/net/sf/image4j/codec/bmp/BMPDecoderTest.java +++ b/test/net/sf/image4j/codec/bmp/BMPDecoderTest.java @@ -2,10 +2,8 @@ import static org.junit.Assert.*; -import java.awt.Color; import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; +import java.awt.image.Raster; import java.io.InputStream; import org.junit.After; @@ -16,40 +14,44 @@ @RunWith(BlockJUnit4ClassRunner.class) public class BMPDecoderTest { - - InputStream is; - - String filename = "/monochrome.bmp"; - - @Before - public void setUp() throws Exception { - is = getClass().getResourceAsStream(filename); - } - - @After - public void tearDown() throws Exception { - if(is != null){ - is.close(); - } - } - - @Test - public void test() throws Exception { - assertNotNull("Test file missing", - getClass().getResource(filename)); - BufferedImage img = BMPDecoder.read(is); - - javax.swing.JFrame f = new javax.swing.JFrame("test"); - f.getContentPane().setBackground(Color.green); - f.getContentPane().setLayout(new java.awt.BorderLayout(0, 0)); - f.getContentPane().add( - java.awt.BorderLayout.CENTER, - new javax.swing.JLabel( - new javax.swing.ImageIcon(img))); - f.pack(); - f.setVisible(true); - - - } + + InputStream is; + + String filename = "/monochrome.bmp"; + + @Before + public void setUp() throws Exception { + is = getClass().getResourceAsStream(filename); + } + + @After + public void tearDown() throws Exception { + if (is != null) { + is.close(); + } + } + + @Test + public void testMonochromeImage() throws Exception { + assertNotNull("Test file missing", + getClass().getResource(filename)); + BufferedImage image = BMPDecoder.read(is); + + assertEquals("Wrong width", 4, image.getWidth()); + assertEquals("Wrong height", 8, image.getHeight()); + assertEquals("Wrong image type", BufferedImage.TYPE_BYTE_BINARY, image.getType()); + + Raster raster = image.getRaster(); + assertEquals("Wrong number of bands", 1, raster.getNumBands()); + for (int x = 0; x < image.getWidth(); ++x) { + for (int y = 0; y < image.getHeight(); ++y) { + if (x == y) { + assertEquals("Wrong pixel on the main diagonal", 1, raster.getSample(x, y, 0)); + } else { + assertEquals("Wrong pixel outside the main diagonal", 0, raster.getSample(x, y, 0)); + } + } + } + } }