Skip to content

Commit aef72b8

Browse files
author
Flurb
committed
Coverage
Signed-off-by: Flurb <[email protected]>
1 parent 8275f1a commit aef72b8

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

validator/src/test/java/org/lfenergy/compas/scl/validator/xsd/SclInfoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ void getSclInfo_WhenCalledWithValidSclFile_ThenSclInfoFromFileReturned() throws
3030
@Test
3131
void getSclInfo_WhenCalledWithInvalidSclFile_ThenExceptionThrownDuringConstruction() throws IOException {
3232
var scdFile = new File(getClass().getResource("/scl/invalid.scd").getFile());
33-
33+
3434
var path = scdFile.toPath();
3535
var content = Files.readString(path);
3636

3737
var exception = assertThrows(SclValidatorException.class, () -> new SclInfo(content));
38-
assertNotNull(LOADING_SCL_FILE_ERROR_CODE, exception.getErrorCode());
38+
assertEquals(LOADING_SCL_FILE_ERROR_CODE, exception.getErrorCode());
3939
}
4040
}

validator/src/test/java/org/lfenergy/compas/scl/validator/xsd/resourceresolver/ResourceInputTest.java

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,58 @@
33
// SPDX-License-Identifier: Apache-2.0
44
package org.lfenergy.compas.scl.validator.xsd.resourceresolver;
55

6+
import org.junit.jupiter.api.BeforeEach;
67
import org.junit.jupiter.api.Test;
8+
import org.lfenergy.compas.scl.validator.exception.SclValidatorException;
79

810
import java.io.IOException;
911
import java.nio.charset.StandardCharsets;
1012

1113
import static org.junit.jupiter.api.Assertions.*;
14+
import static org.lfenergy.compas.scl.validator.exception.SclValidatorErrorCode.RESOURCE_RESOLVER_FAILED;
1215

1316
class ResourceInputTest {
17+
18+
private ResourceInput resourceInput;
19+
20+
@BeforeEach
21+
void beforeEach() {
22+
var inputStream = this.getClass().getResourceAsStream("/scl/example.scd");
23+
resourceInput = new ResourceInput("1", "2", inputStream);
24+
}
25+
1426
@Test
1527
void allGetters_WhenCalled_ThenCorrectValueIsReturned() throws IOException {
16-
var firstInputStream = this.getClass().getResourceAsStream("/scl/example.scd");
1728
var secondInputStream = this.getClass().getResourceAsStream("/scl/example.scd");
1829

19-
var input = new ResourceInput("1", "2", firstInputStream);
20-
21-
assertEquals("1", input.getPublicId());
22-
assertEquals("2", input.getSystemId());
23-
assertNull(input.getBaseURI());
24-
assertNull(input.getByteStream());
25-
assertFalse(input.getCertifiedText());
26-
assertNull(input.getCharacterStream());
27-
assertNull(input.getEncoding());
30+
assertEquals("1", resourceInput.getPublicId());
31+
assertEquals("2", resourceInput.getSystemId());
32+
assertNull(resourceInput.getBaseURI());
33+
assertNull(resourceInput.getByteStream());
34+
assertFalse(resourceInput.getCertifiedText());
35+
assertNull(resourceInput.getCharacterStream());
36+
assertNull(resourceInput.getEncoding());
2837

2938
var expectedStringData = new String(secondInputStream.readAllBytes(), StandardCharsets.UTF_8);
30-
assertEquals(expectedStringData.hashCode(), input.getStringData().hashCode());
39+
assertEquals(expectedStringData.hashCode(), resourceInput.getStringData().hashCode());
40+
}
41+
@Test
42+
void getStringData_WhenCalledWithInvalidInputStream_ThenExceptionIsThrown() {
43+
var input = new ResourceInput("1", "2", null);
44+
45+
var exception = assertThrows(SclValidatorException.class, input::getStringData);
46+
assertEquals(RESOURCE_RESOLVER_FAILED, exception.getErrorCode());
47+
}
48+
49+
@Test
50+
void setPublicId_WhenCalled_ThenCorrectValueIsSet() {
51+
resourceInput.setPublicId("10");
52+
assertEquals("10", resourceInput.getPublicId());
53+
}
54+
55+
@Test
56+
void setSystemId_WhenCalled_ThenCorrectValueIsSet() {
57+
resourceInput.setSystemId("10");
58+
assertEquals("10", resourceInput.getSystemId());
3159
}
3260
}

0 commit comments

Comments
 (0)