-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adr: Fluent assertions * test: Refactor tests
- Loading branch information
1 parent
3a11792
commit 4a5845f
Showing
29 changed files
with
363 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 13 additions & 7 deletions
20
core/src/test/java/org/projectcheckins/core/QuestionSaveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
package org.projectcheckins.core; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
import io.micronaut.core.type.Argument; | ||
import io.micronaut.serde.SerdeIntrospections; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import io.micronaut.validation.validator.Validator; | ||
import org.junit.jupiter.api.Test; | ||
import org.projectcheckins.core.forms.QuestionSave; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@MicronautTest | ||
class QuestionSaveTest { | ||
|
||
@Test | ||
void titleIsRequired(Validator validator) { | ||
assertFalse(validator.validate(new QuestionSave(null)).isEmpty()); | ||
assertFalse(validator.validate(new QuestionSave("")).isEmpty()); | ||
assertTrue(validator.validate(new QuestionSave("What are you working on")).isEmpty()); | ||
assertThat(validator.validate(new QuestionSave(null))) | ||
.isNotEmpty(); | ||
assertThat(validator.validate(new QuestionSave(""))) | ||
.anyMatch(x -> x.getPropertyPath().toString().equals("title") && x.getMessage().equals("must not be blank")); | ||
assertThat(validator.validate(new QuestionSave("What are you working on"))) | ||
.isEmpty(); | ||
} | ||
|
||
@Test | ||
void questionSaveIsAnnotatedWithSerdeableDeserializable(SerdeIntrospections serdeIntrospections) { | ||
assertDoesNotThrow(() -> serdeIntrospections.getDeserializableIntrospection(Argument.of(QuestionSave.class))); | ||
assertThatCode(() -> serdeIntrospections.getDeserializableIntrospection(Argument.of(QuestionSave.class))) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
void questionSaveIsAnnotatedWithSerdeableSerializable(SerdeIntrospections serdeIntrospections) { | ||
assertDoesNotThrow(() -> serdeIntrospections.getSerializableIntrospection(Argument.of(QuestionSave.class))); | ||
assertThatCode(() -> serdeIntrospections.getSerializableIntrospection(Argument.of(QuestionSave.class))) | ||
.doesNotThrowAnyException(); | ||
} | ||
} |
29 changes: 19 additions & 10 deletions
29
core/src/test/java/org/projectcheckins/core/QuestionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,47 @@ | ||
package org.projectcheckins.core; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
import io.micronaut.core.type.Argument; | ||
import io.micronaut.serde.SerdeIntrospections; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import io.micronaut.validation.validator.Validator; | ||
import org.junit.jupiter.api.Test; | ||
import org.projectcheckins.core.forms.Question; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@MicronautTest | ||
class QuestionTest { | ||
|
||
@Test | ||
void idCannotBeBlank(Validator validator) { | ||
assertFalse(validator.validate(new Question(null, "What are you working on")).isEmpty()); | ||
assertFalse(validator.validate(new Question("", "What are you working on")).isEmpty()); | ||
assertTrue(validator.validate(new Question("xxx", "What are you working on")).isEmpty()); | ||
assertThat(validator.validate(new Question(null, "What are you working on"))) | ||
.isNotEmpty(); | ||
assertThat(validator.validate(new Question("", "What are you working on"))) | ||
.anyMatch(x -> x.getPropertyPath().toString().equals("id") && x.getMessage().equals("must not be blank")); | ||
assertThat(validator.validate(new Question("xxx", "What are you working on"))) | ||
.isEmpty(); | ||
} | ||
|
||
@Test | ||
void titleCannotBeBlank(Validator validator) { | ||
assertFalse(validator.validate(new Question("xxx", null)).isEmpty()); | ||
assertFalse(validator.validate(new Question("xxx", "")).isEmpty()); | ||
assertTrue(validator.validate(new Question("xxx", "What are you working on")).isEmpty()); | ||
assertThat(validator.validate(new Question("xxx", null))) | ||
.isNotEmpty(); | ||
assertThat(validator.validate(new Question("xxx", ""))) | ||
.anyMatch(x -> x.getPropertyPath().toString().equals("title") && x.getMessage().equals("must not be blank")); | ||
assertThat(validator.validate(new Question("xxx", "What are you working on"))) | ||
.isEmpty(); | ||
} | ||
|
||
@Test | ||
void questionSaveIsAnnotatedWithSerdeableDeserializable(SerdeIntrospections serdeIntrospections) { | ||
assertDoesNotThrow(() -> serdeIntrospections.getDeserializableIntrospection(Argument.of(Question.class))); | ||
assertThatCode(() -> serdeIntrospections.getDeserializableIntrospection(Argument.of(Question.class))) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
void questionSaveIsAnnotatedWithSerdeableSerializable(SerdeIntrospections serdeIntrospections) { | ||
assertDoesNotThrow(() -> serdeIntrospections.getSerializableIntrospection(Argument.of(Question.class))); | ||
assertThatCode(() -> serdeIntrospections.getSerializableIntrospection(Argument.of(Question.class))) | ||
.doesNotThrowAnyException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 19. Fluent Assertions | ||
|
||
Date: 2024-02-28 | ||
Creator: Guillermo Calvo | ||
Reviewer: Sergio del Amo | ||
|
||
|
||
## Status | ||
|
||
Accepted | ||
|
||
|
||
## Context | ||
|
||
We would like to make the development of tests as easy as possible. | ||
|
||
This will allow us to keep a high code coverage percentage to avoid obvious errors. | ||
|
||
Fluent assertions provide a lightway DSL that can save us from most boilerplate code. | ||
|
||
|
||
## Decision | ||
|
||
We will use [AssertJ](https://assertj.github.io/doc/) consistently in all parts of the project where it makes sense. | ||
|
||
|
||
## Consequences | ||
|
||
- Code that tests parts of the application will be shorter, more concise, and easier to read. | ||
- We will be able to have more tests to cover more scenarios with less effort. | ||
- Tests that fail will yield a meaningful error message. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.