Skip to content

Commit 00be383

Browse files
WeltraumschafManuelNeuer
authored andcommitted
#36 Test that default implementations pass an empty options array
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent 99b039f commit 00be383

File tree

2 files changed

+68
-16
lines changed

2 files changed

+68
-16
lines changed

src/test/java/io/securecodebox/persistence/defectdojo/service/DefaultImportScanServiceTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,6 @@ void generateApiUrl() {
5555
assertThat(sut.generateApiUrl("foo"), is("http://localhost/api/v2/foo/"));
5656
}
5757

58-
@Test
59-
@Disabled("Fails due to network side effect")
60-
void importScan_withoutOptionsShouldPassEmptyMap() {
61-
final var spiedSut = spy(sut);
62-
63-
sut.importScan(new ScanFile("content"),42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
64-
65-
verify(spiedSut, times(1))
66-
.importScan(new ScanFile("content"),42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L, new HashMap<>());
67-
}
68-
6958
@Test
7059
@Disabled("Not implemented yet")
7160
void importScan_shouldPassImportScanAsEndpoint() {
@@ -76,11 +65,6 @@ void importScan_shouldPassImportScanAsEndpoint() {
7665
void importScan_shouldPassEngagementIdAsEngagement() {
7766
}
7867

79-
@Test
80-
@Disabled("Not implemented yet")
81-
void reimportScan_withoutOptionsShouldPassEmptyMap() {
82-
}
83-
8468
@Test
8569
@Disabled("Not implemented yet")
8670
void reimportScan_shouldPassReimportScanAsEndpoint() {

src/test/java/io/securecodebox/persistence/defectdojo/service/ImportScanServiceTest.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
package io.securecodebox.persistence.defectdojo.service;
22

3+
import io.securecodebox.persistence.defectdojo.ScanType;
34
import io.securecodebox.persistence.defectdojo.config.DefectDojoConfig;
5+
import io.securecodebox.persistence.defectdojo.models.ScanFile;
6+
import lombok.Getter;
7+
import org.junit.jupiter.api.Disabled;
48
import org.junit.jupiter.api.Test;
59

10+
import java.util.Collections;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
614
import static org.junit.jupiter.api.Assertions.*;
715
import static org.hamcrest.MatcherAssert.assertThat;
816
import static org.hamcrest.Matchers.*;
17+
import static org.mockito.Mockito.*;
18+
import static org.mockito.Mockito.times;
919

1020
/**
1121
* Tests for {@link ImportScanService}.
1222
*/
1323
class ImportScanServiceTest {
1424

25+
private final ImportScanServiceStub sut = new ImportScanServiceStub();
26+
1527
@Test
1628
void createDefault_throwsExceptionIfNullPassedIn() {
1729
assertThrows(NullPointerException.class, () -> {
@@ -35,4 +47,60 @@ void createDefault_passesConfig() {
3547
() -> assertThat(sut.getDefectDojoUrl(), is(config.getUrl())),
3648
() -> assertThat(sut.getDefectDojoApiKey(), is(config.getApiKey())));
3749
}
50+
51+
@Test
52+
void importScan_withoutOptionsShouldPassEmptyMap() {
53+
assertThat(sut.getOptions(), is(nullValue()));
54+
55+
sut.importScan(new ScanFile("content"),42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
56+
57+
assertThat(sut.getOptions(), equalTo(Collections.EMPTY_MAP));
58+
}
59+
60+
@Test
61+
void importScan_withoutOptionsShouldPassModifiableMap() {
62+
assertThat(sut.getOptions(), is(nullValue()));
63+
64+
sut.importScan(new ScanFile("content"),42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
65+
sut.getOptions().put("foo", "bar");
66+
67+
assertThat(sut.getOptions(), hasEntry("foo", "bar"));
68+
}
69+
70+
@Test
71+
void reimportScan_withoutOptionsShouldPassEmptyMap() {
72+
assertThat(sut.getOptions(), is(nullValue()));
73+
74+
sut.reimportScan(new ScanFile("content"),42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
75+
76+
assertThat(sut.getOptions(), equalTo(Collections.EMPTY_MAP));
77+
}
78+
79+
@Test
80+
void reimportScan_withoutOptionsShouldPassModifiableMap() {
81+
assertThat(sut.getOptions(), is(nullValue()));
82+
83+
sut.reimportScan(new ScanFile("content"),42L, 43L, "1.1.2023", ScanType.AUDIT_JS_SCAN, 23L);
84+
sut.getOptions().put("foo", "bar");
85+
86+
assertThat(sut.getOptions(), hasEntry("foo", "bar"));
87+
}
88+
89+
private static final class ImportScanServiceStub implements ImportScanService {
90+
91+
@Getter
92+
private Map<String, String> options;
93+
94+
@Override
95+
public ImportScanResponse importScan(ScanFile scanFile, long engagementId, long lead, String currentDate, ScanType scanType, long testType, Map<String, String> options) {
96+
this.options = options;
97+
return null;
98+
}
99+
100+
@Override
101+
public ImportScanResponse reimportScan(ScanFile scanFile, long testId, long lead, String currentDate, ScanType scanType, long testType, Map<String, String> options) {
102+
this.options = options;
103+
return null;
104+
}
105+
}
38106
}

0 commit comments

Comments
 (0)