Skip to content

Commit

Permalink
chore: Add unit tests for missing branches
Browse files Browse the repository at this point in the history
  • Loading branch information
en-milie committed Oct 9, 2024
1 parent d8c1ee6 commit 16d7655
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ quarkus.native.additional-build-args=\
--initialize-at-run-time=com.endava.cats.util.CatsUtil, \
-DmaxYamlCodePoints=99999999
quarkus.native.enable-dashboard-dump=false
quarkus.native.resources.includes=en/company.yml,en/chuck_norris.yml,en/address.yml,en/name.yml,chart.js,draw_chart.js,assets.zip,summary.mustache,pl4j-*.properties,pl4j.properties,test-case.mustache,LICENSE,script.js,styles.css,version.properties,SpringExpressions.g
quarkus.native.resources.includes=ro.yml,chart.js,draw_chart.js,assets.zip,summary.mustache,pl4j-*.properties,pl4j.properties,test-case.mustache,LICENSE,script.js,styles.css,version.properties,SpringExpressions.g
app.timestamp=@maven.build.timestamp@
quarkus.log.level=ERROR
quarkus.log.category."com.endava.cats".level=INFO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ void shouldGenerateWithIntegerMinInt() {
Assertions.assertThat(generated).asString().isEmpty();
}

@Test
void shouldNotGenerateWhenInvalidRegex() {
Schema<String> schema = new StringSchema();
TestCaseListener testCaseListener = Mockito.mock(TestCaseListener.class);
myBaseBoundaryFuzzer = new MyExactMinValueFuzzer(null, testCaseListener, filesArguments);
schema.setPattern("[0-9][sss-000]+");
schema.setMaxLength(4);
schema.setMinLength(2);
Object generated = myBaseBoundaryFuzzer.getBoundaryValue(schema);
Mockito.verify(testCaseListener).recordError("Fuzzer %s could not generate a value for patten %s, min %s, max %s"
.formatted(myBaseBoundaryFuzzer.getClass().getSimpleName(), schema.getPattern(), schema.getMinLength(), schema.getMaxLength()));
}

static class MyExactValueFuzzer extends ExactValuesInFieldsFuzzer {

public MyExactValueFuzzer(ServiceCaller sc, TestCaseListener lr, FilesArguments cp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ void shouldApply(String format, boolean expected) {
TimestampGenerator timestampGenerator = new TimestampGenerator();
Assertions.assertThat(timestampGenerator.appliesTo(format, "")).isEqualTo(expected);
}

@Test
void shouldReturnAlmostValidValue() {
Assertions.assertThat(new TimestampGenerator().getAlmostValidValue()).isEqualTo("2021-07-21-T10:22:1Z");
}

@Test
void shouldReturnWrongValue() {
Assertions.assertThat(new TimestampGenerator().getTotallyWrongValue()).isEqualTo("1111-07-21T88:32:28Z");
}
}

0 comments on commit 16d7655

Please sign in to comment.