Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
9ade355
docs(readme): document the test naming convention
EdgarEldy Sep 20, 2026
6610c50
test(naming): rename tests to the _NN_Should_When convention on featu…
EdgarEldy Sep 20, 2026
c75333f
Merge branch 'feature/core-architecture' into feature/auth
EdgarEldy Sep 20, 2026
4f0fc08
test(naming): rename tests to the _NN_Should_When convention on featu…
EdgarEldy Sep 20, 2026
7ca8eae
Merge branch 'feature/auth' into feature/rbac
EdgarEldy Sep 20, 2026
9b31428
test(naming): rename tests to the _NN_Should_When convention on featu…
EdgarEldy Sep 20, 2026
ff287b9
Merge branch 'feature/rbac' into feature/categories
EdgarEldy Sep 20, 2026
09ee9a3
test(naming): rename tests to the _NN_Should_When convention on featu…
EdgarEldy Sep 20, 2026
d495c23
Merge branch 'feature/categories' into feature/products
EdgarEldy Sep 20, 2026
f59379c
test(naming): rename tests to the _NN_Should_When convention on featu…
EdgarEldy Sep 20, 2026
965be91
Merge branch 'feature/products' into feature/customers
EdgarEldy Sep 20, 2026
2e0a935
test(naming): rename tests to the _NN_Should_When convention on featu…
EdgarEldy Sep 20, 2026
4aa8c82
Merge branch 'feature/customers' into feature/orders
EdgarEldy Sep 20, 2026
62321d8
test(naming): rename tests to the _NN_Should_When convention on featu…
EdgarEldy Sep 20, 2026
93cc106
Merge branch 'feature/orders' into feature/native-build
EdgarEldy Sep 20, 2026
0806218
Merge branch 'feature/native-build' into feature/reactive-endpoints
EdgarEldy Sep 20, 2026
7398e0c
test(naming): rename tests to the _NN_Should_When convention on featu…
EdgarEldy Sep 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ Quarkus lets imperative (blocking, Panache-based) and reactive (Mutiny-based) co
- Every endpoint returns an `ApiResponse<T>` (or `ApiResponse<PageResponse<T>>` for lists)
- Permission checks are always declarative (`@PermissionsAllowed("RESOURCE:ACTION")` on the resource method), never a manual `if` inside a method body
- No JAX-RS resource method contains business logic - it validates via Bean Validation annotations on the request DTO, delegates to a service, and maps the result to an `ApiResponse<T>`
- **Test naming convention**: every test method is named `_NN_Should<Outcome>_When<Condition>`, where `NN` is a two-digit sequence number with a leading zero, restarting at `_01_` in each test class and following the order of the methods in the source (e.g. `_01_ShouldReturnCategory_WhenCategoryExists`, `_02_ShouldReturnEmpty_WhenCategoryDoesNotExist`). This applies to every kind of test (unit, repository, resource, integration, parameterized). No other style (`shouldX()`, `testX()`, `givenX_whenY_thenZ()`) is accepted.

## Concepts covered

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class ApiResponseTest {

@Test
void successBuildsEnvelopeWithFlagMessageDataAndTimestamp() {
void _01_ShouldBuildEnvelopeWithAllFields_WhenCreatedWithSuccess() {
Instant before = Instant.now();
ApiResponse<String> response = ApiResponse.success("payload", "done");
Instant after = Instant.now();
Expand All @@ -29,7 +29,7 @@ void successBuildsEnvelopeWithFlagMessageDataAndTimestamp() {
}

@Test
void successAcceptsNullData() {
void _02_ShouldAcceptNullData_WhenCreatedWithSuccess() {
ApiResponse<Object> response = ApiResponse.success(null, "empty");
assertTrue(response.success());
assertNull(response.data());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@
class PageResponseTest {

@Test
void totalPagesUsesCeilingDivision() {
void _01_ShouldUseCeilingDivision_WhenComputingTotalPages() {
assertEquals(3, PageResponse.of(List.of(1, 2, 3), 0, 3, 7).totalPages());
assertEquals(2, PageResponse.of(List.of(1, 2, 3), 0, 3, 6).totalPages());
assertEquals(1, PageResponse.of(List.of(1), 0, 10, 1).totalPages());
}

@Test
void sizeZeroYieldsZeroPagesWithoutDividingByZero() {
void _02_ShouldYieldZeroPages_WhenSizeIsZero() {
assertEquals(0, PageResponse.of(List.of(), 0, 0, 5).totalPages());
}

@Test
void emptyContentYieldsZeroPages() {
void _03_ShouldYieldZeroPages_WhenContentIsEmpty() {
PageResponse<String> page = PageResponse.of(List.of(), 0, 10, 0);
assertEquals(0, page.totalPages());
assertTrue(page.content().isEmpty());
assertEquals(0, page.totalElements());
}

@Test
void keepsPassedValues() {
void _04_ShouldKeepPassedValues_WhenBuilt() {
PageResponse<Integer> page = PageResponse.of(List.of(4, 5), 2, 2, 6);
assertEquals(2, page.page());
assertEquals(2, page.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ProblemDetailsTest {
private static final String PROBLEM_JSON = "application/problem+json";

@Test
void resourceNotFoundIsProblem404() {
void _01_ShouldReturnProblem404_WhenResourceNotFound() {
given().when().get("/test-support/not-found")
.then().statusCode(404)
.contentType(PROBLEM_JSON)
Expand All @@ -34,7 +34,7 @@ void resourceNotFoundIsProblem404() {
}

@Test
void businessRuleIsProblem422() {
void _02_ShouldReturnProblem422_WhenBusinessRuleViolated() {
given().when().get("/test-support/business-rule")
.then().statusCode(422)
.contentType(PROBLEM_JSON)
Expand All @@ -46,7 +46,7 @@ void businessRuleIsProblem422() {
}

@Test
void beanValidationFailureIsProblem400WithViolations() {
void _03_ShouldReturnProblem400WithViolations_WhenBeanValidationFails() {
given().contentType("application/json").body("{\"name\":\"\"}")
.when().post("/test-support/validate")
.then().statusCode(400)
Expand All @@ -57,7 +57,7 @@ void beanValidationFailureIsProblem400WithViolations() {
}

@Test
void validRequestStillReturnsSuccessEnvelope() {
void _04_ShouldReturnSuccessEnvelope_WhenRequestIsValid() {
given().contentType("application/json").body("{\"name\":\"bob\"}")
.when().post("/test-support/validate")
.then().statusCode(200)
Expand All @@ -66,7 +66,7 @@ void validRequestStillReturnsSuccessEnvelope() {
}

@Test
void unexpectedExceptionIsGeneric500WithoutLeaks() {
void _05_ShouldReturnGeneric500WithoutLeaks_WhenUnexpectedExceptionThrown() {
String body = given().when().get("/test-support/unexpected")
.then().statusCode(500)
.contentType(PROBLEM_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FlywaySchemaTest {
DataSource dataSource;

@Test
void allExpectedTablesExistInPublicSchema() throws SQLException {
void _01_ShouldCreateAllExpectedTables_WhenMigrationsRun() throws SQLException {
Set<String> tables = new HashSet<>();
try (Connection c = dataSource.getConnection();
PreparedStatement ps = c.prepareStatement(
Expand All @@ -48,7 +48,7 @@ void allExpectedTablesExistInPublicSchema() throws SQLException {
}

@Test
void schemaHistoryShowsVersionOneSuccess() throws SQLException {
void _02_ShouldRecordVersionOneAsSuccess_WhenMigrationsRun() throws SQLException {
try (Connection c = dataSource.getConnection();
PreparedStatement ps = c.prepareStatement(
"SELECT success FROM flyway_schema_history WHERE version = '1'");
Expand All @@ -59,7 +59,7 @@ void schemaHistoryShowsVersionOneSuccess() throws SQLException {
}

@Test
void duplicateUserEmailIsRejectedByTheDatabase() throws SQLException {
void _03_ShouldRejectInsert_WhenUserEmailIsDuplicated() throws SQLException {
String sql = "INSERT INTO users (first_name, last_name, email, password) VALUES ('A', 'B', ?, 'x')";
String email = "dup-" + System.nanoTime() + "@example.com";
try (Connection c = dataSource.getConnection()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
class HealthEndpointsTest {

@Test
void readinessIsUpAndReportsDatabaseCheck() {
void _01_ShouldReportUpWithDatabaseCheck_WhenReadinessQueried() {
given().when().get("/q/health/ready")
.then().statusCode(200)
.body("status", is("UP"))
.body("checks.find { it.name == 'database' }.status", is("UP"));
}

@Test
void livenessIsUpAndReportsApplicationCheck() {
void _02_ShouldReportUpWithApplicationCheck_WhenLivenessQueried() {
given().when().get("/q/health/live")
.then().statusCode(200)
.body("status", is("UP"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ private Long persist(String name) {
}

@Test
void persistAndFind() {
void _01_ShouldFindCategory_WhenPersisted() {
categoryId = persist("Repo test");
Category found = QuarkusTransaction.requiringNew().call(() -> repository.findById(categoryId));
assertNotNull(found);
assertEquals("Repo test", found.getCategoryName());
}

@Test
void countProductsReflectsInsertedRows() {
void _02_ShouldCountInsertedProducts_WhenProductsAdded() {
categoryId = persist("Repo count");
assertEquals(0L, QuarkusTransaction.requiringNew().call(() -> productRepository.countByCategoryId(categoryId)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private Long persist(String telephone, String email, String address) {
}

@Test
void persistAndFindRoundTrip() {
void _01_ShouldRoundTripCustomer_WhenPersistedAndFound() {
customerId = persist("123", "ada@example.com", "London");
Customer found = QuarkusTransaction.requiringNew().call(() -> repository.findById(customerId));
assertNotNull(found);
Expand All @@ -65,7 +65,7 @@ void persistAndFindRoundTrip() {
}

@Test
void nullableColumnsRoundTripAsNull() {
void _02_ShouldRoundTripNulls_WhenOptionalColumnsAreNull() {
customerId = persist(null, null, null);
Customer found = QuarkusTransaction.requiringNew().call(() -> repository.findById(customerId));
assertNotNull(found);
Expand All @@ -75,7 +75,7 @@ void nullableColumnsRoundTripAsNull() {
}

@Test
void deleteRemovesRow() {
void _03_ShouldRemoveRow_WhenCustomerDeleted() {
customerId = persist(null, null, null);
QuarkusTransaction.requiringNew().run(() -> repository.deleteById(customerId));
assertNull(QuarkusTransaction.requiringNew().call(() -> repository.findById(customerId)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private List<Long> ids(Long customerId, Long productId) {
}

@Test
void persistAndFindRoundTripOnTheCustomerOrderEntity() {
void _01_ShouldRoundTripOrder_WhenPersistedAndFound() {
Long id = order(customerA, productA, 3, "7.50");

Order found = QuarkusTransaction.requiringNew().call(() -> {
Expand All @@ -132,7 +132,7 @@ void persistAndFindRoundTripOnTheCustomerOrderEntity() {
}

@Test
void searchAndCountWorkWithEveryFilterCombination() {
void _02_ShouldSearchAndCount_WhenAnyFilterCombinationUsed() {
Long o1 = order(customerA, productA, 1, "2.50");
Long o2 = order(customerA, productB, 2, "5.00");
Long o3 = order(customerB, productA, 3, "7.50");
Expand All @@ -156,7 +156,7 @@ void searchAndCountWorkWithEveryFilterCombination() {
}

@Test
void countByCustomerAndProductCountOnlyReferencingOrders() {
void _03_ShouldCountOnlyReferencingOrders_WhenCountingByCustomerAndProduct() {
order(customerA, productA, 1, "2.50");
order(customerA, productB, 1, "2.50");
order(customerB, productA, 1, "2.50");
Expand All @@ -170,7 +170,7 @@ void countByCustomerAndProductCountOnlyReferencingOrders() {
}

@Test
void foreignKeysAndChecksAreEnforced() {
void _04_ShouldEnforceForeignKeysAndChecks_WhenInvalidRowInserted() {
assertThrows(RuntimeException.class, () -> QuarkusTransaction.requiringNew().run(() -> em
.createNativeQuery("insert into orders (customer_id, product_id, quantity, total) "
+ "values (999999999, " + productA + ", 1, 1.00)").executeUpdate()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private Long product(Long categoryId, String name, String price) {
}

@Test
void findByCategoryFiltersAndOrdersById() {
void _01_ShouldFilterAndOrderById_WhenFindingByCategory() {
Long catA = category();
Long catB = category();
Long a1 = product(catA, "A1", "1.00");
Expand All @@ -92,7 +92,7 @@ void findByCategoryFiltersAndOrdersById() {
}

@Test
void countByCategoryIdCountsOnlyThatCategory() {
void _02_ShouldCountOnlyThatCategory_WhenCountingByCategoryId() {
Long catA = category();
Long catB = category();
product(catA, "A1", "1.00");
Expand All @@ -105,7 +105,7 @@ void countByCategoryIdCountsOnlyThatCategory() {
}

@Test
void unitPriceRoundTripsAsNumeric12Scale2() {
void _03_ShouldRoundTripPriceAsNumeric12Scale2_WhenProductPersisted() {
Long cat = category();
Long id = product(cat, "Precise", "79.99");
Long big = product(cat, "Big", "9999999999.99");
Expand All @@ -118,7 +118,7 @@ void unitPriceRoundTripsAsNumeric12Scale2() {
}

@Test
void missingCategoryViolatesForeignKey() {
void _04_ShouldViolateForeignKey_WhenCategoryMissing() {
assertThrows(RuntimeException.class, () -> QuarkusTransaction.requiringNew().run(() -> em
.createNativeQuery("insert into products (category_id, product_name, unit_price) "
+ "values (999999999, 'Orphan', 1.00)").executeUpdate()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private User newUser(String email) {
}

@Test
void findByEmailIsCaseInsensitive() {
void _01_ShouldFindUser_WhenEmailCaseDiffers() {
String email = "mixed" + System.nanoTime() + "@example.com";
QuarkusTransaction.requiringNew().run(() -> users.persist(newUser(email)));
QuarkusTransaction.requiringNew().run(() -> {
Expand All @@ -56,7 +56,7 @@ void findByEmailIsCaseInsensitive() {
}

@Test
void duplicateEmailViolatesUniqueConstraint() {
void _02_ShouldViolateUniqueConstraint_WhenEmailIsDuplicated() {
String email = "dup" + System.nanoTime() + "@example.com";
QuarkusTransaction.requiringNew().run(() -> users.persist(newUser(email)));
assertThrows(RuntimeException.class,
Expand All @@ -67,7 +67,7 @@ void duplicateEmailViolatesUniqueConstraint() {
}

@Test
void tokenRepositoriesFindTheirRows() {
void _03_ShouldFindTheirRows_WhenTokensSaved() {
long n = System.nanoTime();
String email = "tok" + n + "@example.com";
QuarkusTransaction.requiringNew().run(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void detachHandler() {
}

@Test
void fullFlowRegisterActivateLoginMeLogout() {
void _01_ShouldCompleteFullFlow_WhenRegisteringActivatingLoggingInAndOut() {
String email = uniqueEmail();
register(email, PASSWORD).statusCode(201)
.contentType("application/json")
Expand Down Expand Up @@ -119,7 +119,7 @@ void fullFlowRegisterActivateLoginMeLogout() {
}

@Test
void forgotAndResetPasswordFlowIsSingleUse() {
void _02_ShouldAllowSingleUse_WhenResettingPassword() {
String email = registerAndActivate();

given().contentType("application/json").body("{\"email\":\"" + email + "\"}")
Expand All @@ -139,7 +139,7 @@ void forgotAndResetPasswordFlowIsSingleUse() {
}

@Test
void registerDuplicateEmailIs422() {
void _03_ShouldReturn422_WhenRegisteringDuplicateEmail() {
String email = uniqueEmail();
register(email, PASSWORD).statusCode(201);
register(email, PASSWORD).statusCode(422)
Expand All @@ -149,7 +149,7 @@ void registerDuplicateEmailIs422() {
}

@Test
void registerWithInvalidBodyIs400WithViolations() {
void _04_ShouldReturn400WithViolations_WhenRegisterBodyInvalid() {
given().contentType("application/json")
.body("{\"firstName\":\"\",\"lastName\":\"L\",\"email\":\"not-an-email\",\"password\":\"short\"}")
.when().post(BASE + "/register")
Expand All @@ -161,7 +161,7 @@ void registerWithInvalidBodyIs400WithViolations() {
}

@Test
void loginUnknownEmailAndWrongPasswordAreIndistinguishable() {
void _05_ShouldBeIndistinguishable_WhenEmailUnknownOrPasswordWrong() {
String email = registerAndActivate();
ValidatableResponse unknown = login(uniqueEmail(), PASSWORD).statusCode(401).contentType(PROBLEM_JSON);
ValidatableResponse wrong = login(email, "WrongPassw0rd!!").statusCode(401).contentType(PROBLEM_JSON);
Expand All @@ -171,7 +171,7 @@ void loginUnknownEmailAndWrongPasswordAreIndistinguishable() {
}

@Test
void loginBeforeActivationIs401() {
void _06_ShouldReturn401_WhenLoggingInBeforeActivation() {
String email = uniqueEmail();
register(email, PASSWORD).statusCode(201);
login(email, PASSWORD).statusCode(401)
Expand All @@ -181,12 +181,12 @@ void loginBeforeActivationIs401() {
}

@Test
void meWithoutTokenIs401() {
void _07_ShouldReturn401_WhenCallingMeWithoutToken() {
given().when().get(BASE + "/me").then().statusCode(401);
}

@Test
void activateWithBadTokenIs422() {
void _08_ShouldReturn422_WhenActivatingWithBadToken() {
given().queryParam("token", "definitely-not-a-real-token").when().get(BASE + "/activate-account")
.then().statusCode(422)
.contentType(PROBLEM_JSON)
Expand Down
Loading
Loading