Skip to content

Commit 71357f7

Browse files
committed
refactor(tests): improve test clarity and fix stale documentation
1 parent e9ca527 commit 71357f7

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

src/main/java/ar/com/nanotaboada/java/samples/spring/boot/repositories/PlayersRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
*
2525
* <h3>Query Strategies:</h3>
2626
* <ul>
27-
* <li><b>@Query:</b> Explicit JPQL for complex searches (findByLeagueContainingIgnoreCase)</li>
28-
* <li><b>Method Names:</b> Spring Data derives queries from method names (Query Creation)</li>
27+
* <li><b>Derived Queries:</b> Spring Data derives queries from method names (findBySquadNumber,
28+
* findByLeagueContainingIgnoreCase)</li>
2929
* </ul>
3030
*
3131
* @see Player
@@ -55,7 +55,7 @@ public interface PlayersRepository extends JpaRepository<Player, Long> {
5555
/**
5656
* Finds players by league name using case-insensitive wildcard matching.
5757
* <p>
58-
* This method uses a custom JPQL query with LIKE operator for partial matches.
58+
* This method uses Spring Data's derived query mechanism to perform partial matching.
5959
* For example, searching for "Premier" will match "Premier League".
6060
* </p>
6161
*

src/test/java/ar/com/nanotaboada/java/samples/spring/boot/test/controllers/PlayersControllerTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ void givenPlayersExist_whenGetAll_thenReturnsOkWithAllPlayers()
184184
then(response.getContentType()).contains("application/json");
185185
verify(playersServiceMock, times(1)).retrieveAll();
186186
then(response.getStatus()).isEqualTo(HttpStatus.OK.value());
187-
then(actual).hasSize(26);
188187
then(actual).usingRecursiveComparison().isEqualTo(expected);
189188
}
190189

@@ -331,7 +330,6 @@ void givenPlayersExist_whenSearchByLeague_thenReturnsOk()
331330
then(response.getContentType()).contains("application/json");
332331
verify(playersServiceMock, times(1)).searchByLeague(any());
333332
then(response.getStatus()).isEqualTo(HttpStatus.OK.value());
334-
then(actual).hasSize(7);
335333
then(actual).usingRecursiveComparison().isEqualTo(expected);
336334
}
337335

src/test/java/ar/com/nanotaboada/java/samples/spring/boot/test/repositories/PlayersRepositoryTests.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ void givenPlayerExists_whenFindById_thenReturnsPlayer() {
5050
@Test
5151
void givenPlayerDoesNotExist_whenFindById_thenReturnsEmpty() {
5252
// Given
53-
Long expected = 999L;
53+
Long nonExistentId = 999L;
5454
// When
55-
Optional<Player> actual = repository.findById(expected);
55+
Optional<Player> actual = repository.findById(nonExistentId);
5656
// Then
5757
then(actual).isEmpty();
5858
}
@@ -65,12 +65,12 @@ void givenPlayerDoesNotExist_whenFindById_thenReturnsEmpty() {
6565
@Test
6666
void givenPlayersExist_whenFindByLeague_thenReturnsList() {
6767
// Given
68-
String expected = "Premier";
68+
String leagueName = "Premier";
6969
// When
70-
List<Player> actual = repository.findByLeagueContainingIgnoreCase(expected);
70+
List<Player> actual = repository.findByLeagueContainingIgnoreCase(leagueName);
7171
// Then
7272
then(actual).isNotEmpty()
73-
.allMatch(player -> player.getLeague().toLowerCase().contains(expected.toLowerCase()));
73+
.allMatch(player -> player.getLeague().toLowerCase().contains(leagueName.toLowerCase()));
7474
}
7575

7676
/**
@@ -81,9 +81,9 @@ void givenPlayersExist_whenFindByLeague_thenReturnsList() {
8181
@Test
8282
void givenNoPlayersExist_whenFindByLeague_thenReturnsEmptyList() {
8383
// Given
84-
String expected = "Expected League";
84+
String nonExistentLeague = "Nonexistent League";
8585
// When
86-
List<Player> actual = repository.findByLeagueContainingIgnoreCase(expected);
86+
List<Player> actual = repository.findByLeagueContainingIgnoreCase(nonExistentLeague);
8787
// Then
8888
then(actual).isEmpty();
8989
}
@@ -96,13 +96,14 @@ void givenNoPlayersExist_whenFindByLeague_thenReturnsEmptyList() {
9696
@Test
9797
void givenPlayerExists_whenFindBySquadNumber_thenReturnsPlayer() {
9898
// Given
99-
Integer expectedSquadNumber = 10; // Messi's squad number from pre-seeded data
99+
Integer messiSquadNumber = 10; // Pre-seeded from dml.sql
100+
String expectedLastName = "Messi";
100101
// When
101-
Optional<Player> actual = repository.findBySquadNumber(expectedSquadNumber);
102+
Optional<Player> actual = repository.findBySquadNumber(messiSquadNumber);
102103
// Then
103104
then(actual).isPresent();
104-
then(actual.get().getSquadNumber()).isEqualTo(expectedSquadNumber);
105-
then(actual.get().getLastName()).isEqualTo("Messi");
105+
then(actual.get().getSquadNumber()).isEqualTo(messiSquadNumber);
106+
then(actual.get().getLastName()).isEqualTo(expectedLastName);
106107
}
107108

108109
/**
@@ -113,9 +114,9 @@ void givenPlayerExists_whenFindBySquadNumber_thenReturnsPlayer() {
113114
@Test
114115
void givenPlayerDoesNotExist_whenFindBySquadNumber_thenReturnsEmpty() {
115116
// Given
116-
Integer expected = 99;
117+
Integer nonExistentSquadNumber = 99;
117118
// When
118-
Optional<Player> actual = repository.findBySquadNumber(expected);
119+
Optional<Player> actual = repository.findBySquadNumber(nonExistentSquadNumber);
119120
// Then
120121
then(actual).isEmpty();
121122
}

src/test/java/ar/com/nanotaboada/java/samples/spring/boot/test/services/PlayersServiceTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ void givenAllPlayersExist_whenRetrieveAll_thenReturns26Players() {
159159
List<PlayerDTO> actual = playersService.retrieveAll();
160160
// Then
161161
verify(playersRepositoryMock, times(1)).findAll();
162-
then(actual).hasSize(26);
163162
then(actual).usingRecursiveComparison().isEqualTo(dtos);
164163
}
165164

0 commit comments

Comments
 (0)