Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up testing with Github Actions. #3

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -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

78 changes: 40 additions & 38 deletions test/net/sf/image4j/codec/bmp/BMPDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}
}
}

}