Skip to content

Commit e944514

Browse files
committed
Add testing and GitHub actions CI (to make it easier to build new features)
1 parent 27454f8 commit e944514

23 files changed

Lines changed: 1410 additions & 1 deletion

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-java@v4
21+
with:
22+
distribution: temurin
23+
java-version: 8
24+
cache: maven
25+
26+
- name: Run tests
27+
run: mvn test --batch-mode --fail-at-end
28+
29+
- name: Build uber JAR
30+
run: mvn package --batch-mode -DskipTests

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
<version>4.13.2</version>
5151
<scope>test</scope>
5252
</dependency>
53+
<dependency>
54+
<groupId>org.mockito</groupId>
55+
<artifactId>mockito-core</artifactId>
56+
<version>4.11.0</version>
57+
<scope>test</scope>
58+
</dependency>
5359
<dependency>
5460
<groupId>com.github.applitools</groupId>
5561
<artifactId>EyesUtilities</artifactId>
@@ -131,7 +137,10 @@
131137
<artifactId>maven-surefire-plugin</artifactId>
132138
<version>3.0.0-M4</version>
133139
<configuration>
134-
<skipTests>true</skipTests>
140+
<excludes>
141+
<exclude>Tests/**</exclude>
142+
<exclude>infra/TestBase.java</exclude>
143+
</excludes>
135144
</configuration>
136145
</plugin>
137146

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.applitools.imagetester.BatchMapper;
2+
3+
import org.junit.Test;
4+
import java.io.IOException;
5+
import java.util.List;
6+
import static org.junit.Assert.*;
7+
8+
public class BatchMapDeserializerTest {
9+
10+
private static final String FIXTURES = "src/test/resources/fixtures";
11+
12+
@Test
13+
public void readFile_parsesCorrectNumberOfRows() throws IOException {
14+
List<BatchMapPojo> result = BatchMapDeserializer.readFile(FIXTURES + "/batchmap-test.csv");
15+
assertEquals(2, result.size());
16+
}
17+
18+
@Test
19+
public void readFile_parsesFirstRowCorrectly() throws IOException {
20+
List<BatchMapPojo> result = BatchMapDeserializer.readFile(FIXTURES + "/batchmap-test.csv");
21+
BatchMapPojo first = result.get(0);
22+
assertEquals("/path/to/file.pdf", first.getFilePath());
23+
assertEquals("Test One", first.getTestName());
24+
assertEquals("MyApp", first.getApp());
25+
assertEquals("Windows", first.getOs());
26+
assertEquals("Chrome", first.getBrowser());
27+
assertEquals("1024x768", first.getViewport());
28+
assertEquals("1000x", first.getMatchsize());
29+
assertEquals("1-3", first.getPages());
30+
assertEquals("Strict", first.getMatchLevel());
31+
}
32+
33+
// NOTE: Jackson's CsvMapper uses public field access when setters are broken,
34+
// so ignoreRegions is populated correctly from the CSV even though
35+
// setIgnoreRegions() is a no-arg setter.
36+
@Test
37+
public void readFile_parsesIgnoreRegionsFromCsv() throws IOException {
38+
List<BatchMapPojo> result = BatchMapDeserializer.readFile(FIXTURES + "/batchmap-test.csv");
39+
assertEquals("10,20,100,50", result.get(0).getIgnoreRegions());
40+
}
41+
42+
@Test
43+
public void readFile_parsesSecondRowMatchLevel() throws IOException {
44+
List<BatchMapPojo> result = BatchMapDeserializer.readFile(FIXTURES + "/batchmap-test.csv");
45+
assertEquals("Layout", result.get(1).getMatchLevel());
46+
}
47+
48+
@Test(expected = IOException.class)
49+
public void readFile_missingFile_throwsIOException() throws IOException {
50+
BatchMapDeserializer.readFile("/nonexistent/path/file.csv");
51+
}
52+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package com.applitools.imagetester.BatchMapper;
2+
3+
import org.junit.Test;
4+
import static org.junit.Assert.*;
5+
6+
// NOTE: setLayoutRegions(), setIgnoreRegions(), and setContentRegions() are no-arg
7+
// setters — they do not accept a value parameter. Calling them does not update the
8+
// field. Round-trip tests for those three fields therefore verify that the field
9+
// remains null after calling the broken setter, reflecting actual behavior.
10+
// See FIXME in BatchMapPojo: setters should accept a String parameter.
11+
public class BatchMapPojoTest {
12+
13+
@Test
14+
public void getterSetterRoundTrip_filePath() {
15+
BatchMapPojo pojo = new BatchMapPojo();
16+
pojo.setFilePath("/path/to/file.pdf");
17+
assertEquals("/path/to/file.pdf", pojo.getFilePath());
18+
}
19+
20+
@Test
21+
public void getterSetterRoundTrip_testName() {
22+
BatchMapPojo pojo = new BatchMapPojo();
23+
pojo.setTestName("My Test");
24+
assertEquals("My Test", pojo.getTestName());
25+
}
26+
27+
@Test
28+
public void getterSetterRoundTrip_app() {
29+
BatchMapPojo pojo = new BatchMapPojo();
30+
pojo.setApp("MyApp");
31+
assertEquals("MyApp", pojo.getApp());
32+
}
33+
34+
@Test
35+
public void getterSetterRoundTrip_os() {
36+
BatchMapPojo pojo = new BatchMapPojo();
37+
pojo.setOs("Windows");
38+
assertEquals("Windows", pojo.getOs());
39+
}
40+
41+
@Test
42+
public void getterSetterRoundTrip_browser() {
43+
BatchMapPojo pojo = new BatchMapPojo();
44+
pojo.setBrowser("Chrome");
45+
assertEquals("Chrome", pojo.getBrowser());
46+
}
47+
48+
@Test
49+
public void getterSetterRoundTrip_viewport() {
50+
BatchMapPojo pojo = new BatchMapPojo();
51+
pojo.setViewport("1024x768");
52+
assertEquals("1024x768", pojo.getViewport());
53+
}
54+
55+
@Test
56+
public void getterSetterRoundTrip_matchsize() {
57+
BatchMapPojo pojo = new BatchMapPojo();
58+
pojo.setMatchsize("1000x");
59+
assertEquals("1000x", pojo.getMatchsize());
60+
}
61+
62+
@Test
63+
public void getterSetterRoundTrip_pages() {
64+
BatchMapPojo pojo = new BatchMapPojo();
65+
pojo.setPages("1-5");
66+
assertEquals("1-5", pojo.getPages());
67+
}
68+
69+
@Test
70+
public void getterSetterRoundTrip_matchLevel() {
71+
BatchMapPojo pojo = new BatchMapPojo();
72+
pojo.setMatchLevel("Strict");
73+
assertEquals("Strict", pojo.getMatchLevel());
74+
}
75+
76+
// CONCERN: setLayoutRegions() is a no-arg setter — it ignores its caller's value
77+
// and leaves the field null. The field can only be set by direct assignment or
78+
// via Jackson's public-field access. The test below documents actual behavior.
79+
@Test
80+
public void setter_layoutRegions_isNoArgAndLeavesFieldNull() {
81+
BatchMapPojo pojo = new BatchMapPojo();
82+
pojo.setLayoutRegions();
83+
assertNull(pojo.getLayoutRegions());
84+
}
85+
86+
// CONCERN: same broken no-arg setter for ignoreRegions.
87+
@Test
88+
public void setter_ignoreRegions_isNoArgAndLeavesFieldNull() {
89+
BatchMapPojo pojo = new BatchMapPojo();
90+
pojo.setIgnoreRegions();
91+
assertNull(pojo.getIgnoreRegions());
92+
}
93+
94+
// CONCERN: same broken no-arg setter for contentRegions.
95+
@Test
96+
public void setter_contentRegions_isNoArgAndLeavesFieldNull() {
97+
BatchMapPojo pojo = new BatchMapPojo();
98+
pojo.setContentRegions();
99+
assertNull(pojo.getContentRegions());
100+
}
101+
102+
@Test
103+
public void equals_sameValues_returnsTrue() {
104+
BatchMapPojo a = createPojo("path", "test", "app");
105+
BatchMapPojo b = createPojo("path", "test", "app");
106+
assertEquals(a, b);
107+
}
108+
109+
@Test
110+
public void equals_differentValues_returnsFalse() {
111+
BatchMapPojo a = createPojo("path1", "test", "app");
112+
BatchMapPojo b = createPojo("path2", "test", "app");
113+
assertNotEquals(a, b);
114+
}
115+
116+
@Test
117+
public void equals_null_returnsFalse() {
118+
BatchMapPojo a = createPojo("path", "test", "app");
119+
assertNotEquals(a, null);
120+
}
121+
122+
// NOTE: toString() only includes filePath, testName, app, os, browser, viewport,
123+
// matchsize, pages, and matchLevel — not layoutRegions, contentRegions, or ignoreRegions.
124+
@Test
125+
public void toString_containsFieldValues() {
126+
BatchMapPojo pojo = createPojo("/my/path", "MyTest", "MyApp");
127+
String str = pojo.toString();
128+
assertTrue(str.contains("/my/path"));
129+
assertTrue(str.contains("MyTest"));
130+
assertTrue(str.contains("MyApp"));
131+
}
132+
133+
private BatchMapPojo createPojo(String path, String testName, String app) {
134+
BatchMapPojo pojo = new BatchMapPojo();
135+
pojo.setFilePath(path);
136+
pojo.setTestName(testName);
137+
pojo.setApp(app);
138+
return pojo;
139+
}
140+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.applitools.imagetester.BatchObjects;
2+
3+
import com.applitools.imagetester.lib.Config;
4+
import com.applitools.imagetester.lib.Logger;
5+
6+
import org.junit.Test;
7+
8+
import java.io.File;
9+
10+
import static org.junit.Assert.*;
11+
12+
public class PDFFileBatchTest {
13+
14+
private static final String FIXTURES = "src/test/resources/fixtures";
15+
16+
private Config createConfig() {
17+
Config config = new Config();
18+
config.appName = "TestApp";
19+
config.logger = new Logger();
20+
config.splitSteps = true;
21+
return config;
22+
}
23+
24+
@Test
25+
public void twoPagePdf_createsTwoTests() throws Exception {
26+
Config config = createConfig();
27+
PDFFileBatch batch = new PDFFileBatch(new File(FIXTURES, "valid-2-page.pdf"), config);
28+
assertFalse(batch.isEmpty());
29+
}
30+
31+
@Test
32+
public void pageSelection_respectsConfig() throws Exception {
33+
Config config = createConfig();
34+
config.pages = "1";
35+
PDFFileBatch batch = new PDFFileBatch(new File(FIXTURES, "valid-10-page.pdf"), config);
36+
assertFalse(batch.isEmpty());
37+
}
38+
39+
@Test
40+
public void batchInfo_usesFileName() throws Exception {
41+
Config config = createConfig();
42+
PDFFileBatch batch = new PDFFileBatch(new File(FIXTURES, "valid-2-page.pdf"), config);
43+
assertEquals("valid-2-page.pdf", batch.batchInfo().getName());
44+
}
45+
46+
@Test
47+
public void passwordProtectedPdf_loadsWithPassword() throws Exception {
48+
Config config = createConfig();
49+
config.pdfPass = "test123";
50+
PDFFileBatch batch = new PDFFileBatch(new File(FIXTURES, "password-protected.pdf"), config);
51+
assertFalse(batch.isEmpty());
52+
}
53+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.applitools.imagetester;
2+
3+
import com.applitools.imagetester.lib.EyesFactory;
4+
import com.applitools.imagetester.lib.Logger;
5+
import org.junit.Test;
6+
import static org.junit.Assert.*;
7+
8+
public class EyesFactoryTest {
9+
10+
private EyesFactory createFactory() {
11+
return new EyesFactory("test", new Logger());
12+
}
13+
14+
@Test
15+
public void imageCut_fourValues() {
16+
EyesFactory factory = createFactory().imageCut(new String[]{"10", "20", "30", "40"});
17+
assertNotNull(factory);
18+
}
19+
20+
@Test
21+
public void imageCut_partialValues() {
22+
EyesFactory factory = createFactory().imageCut(new String[]{"10"});
23+
assertNotNull(factory);
24+
}
25+
26+
@Test
27+
public void imageCut_emptyStringsBecomeZero() {
28+
EyesFactory factory = createFactory().imageCut(new String[]{"", "", "10", "4"});
29+
assertNotNull(factory);
30+
}
31+
32+
@Test
33+
public void imageCut_null_isNoOp() {
34+
EyesFactory factory = createFactory().imageCut(null);
35+
assertNotNull(factory);
36+
}
37+
38+
@Test(expected = IllegalArgumentException.class)
39+
public void imageCut_moreThanFourValues_throws() {
40+
createFactory().imageCut(new String[]{"1", "2", "3", "4", "5"});
41+
}
42+
43+
@Test
44+
public void accSettings_emptyArray_usesDefaults() {
45+
EyesFactory factory = createFactory().accSettings(new String[]{});
46+
assertNotNull(factory);
47+
}
48+
49+
@Test
50+
public void accSettings_singleValue() {
51+
EyesFactory factory = createFactory().accSettings(new String[]{"AAA"});
52+
assertNotNull(factory);
53+
}
54+
55+
@Test
56+
public void accSettings_twoValues() {
57+
EyesFactory factory = createFactory().accSettings(new String[]{"AA", "WCAG_2_1"});
58+
assertNotNull(factory);
59+
}
60+
61+
@Test
62+
public void accSettings_null_isNoOp() {
63+
EyesFactory factory = createFactory().accSettings(null);
64+
assertNotNull(factory);
65+
}
66+
67+
@Test(expected = IllegalArgumentException.class)
68+
public void accSettings_moreThanTwoValues_throws() {
69+
createFactory().accSettings(new String[]{"AA", "WCAG_2_1", "extra"});
70+
}
71+
72+
@Test(expected = RuntimeException.class)
73+
public void build_parentBranchWithoutBranch_throws() {
74+
createFactory()
75+
.apiKey("fake-key")
76+
.parentBranch("parent")
77+
.build();
78+
}
79+
}

0 commit comments

Comments
 (0)