@@ -57,15 +57,11 @@ void givenCreate_whenBookIsInvalid_thenShouldNeverSaveBookIntoRepositoryAndRetur
5757 // Arrange
5858 boolean result = false ;
5959 BookDTO bookDTO = BookDTOsBuilder .buildOneInvalid ();
60- Book book = BooksBuilder .buildOneInvalid ();
6160 // Simplify creation of ConstraintViolationExceptions
6261 // https://hibernate.atlassian.net/browse/BVAL-198
63- Set <? extends ConstraintViolation <?>> errors = new HashSet <ConstraintViolation <Book >>();
62+ Set <? extends ConstraintViolation <?>> errors = new HashSet <ConstraintViolation <BookDTO >>();
6463 Mockito
65- .when (mapper .map (bookDTO , Book .class ))
66- .thenReturn (book );
67- Mockito
68- .when (validator .validate (any (Book .class )))
64+ .when (validator .validate (any (BookDTO .class )))
6965 .thenThrow (new ConstraintViolationException (errors ));
7066 // Act
7167 try {
@@ -74,7 +70,6 @@ void givenCreate_whenBookIsInvalid_thenShouldNeverSaveBookIntoRepositoryAndRetur
7470 // Assert
7571 assertThat (exception ).isInstanceOf (ConstraintViolationException .class );
7672 } finally {
77- verify (mapper , times (1 )).map (bookDTO , Book .class );
7873 verify (repository , never ()).save (any (Book .class ));
7974 assertThat (result ).isFalse ();
8075 }
@@ -85,21 +80,16 @@ void givenCreate_whenBookIsValidButAlreadyExistsInRepository_thenShouldNeverSave
8580 // Arrange
8681 boolean result = false ;
8782 BookDTO bookDTO = BookDTOsBuilder .buildOneValid ();
88- Book book = BooksBuilder .buildOneValid ();
89- Set <ConstraintViolation <Book >> errors = new HashSet <ConstraintViolation <Book >>();
83+ Set <ConstraintViolation <BookDTO >> errors = new HashSet <ConstraintViolation <BookDTO >>();
9084 Mockito
91- .when (mapper .map (bookDTO , Book .class ))
92- .thenReturn (book );
93- Mockito
94- .when (validator .validate (any (Book .class )))
85+ .when (validator .validate (any (BookDTO .class )))
9586 .thenReturn (errors );
9687 Mockito
9788 .when (repository .existsById (anyString ()))
9889 .thenReturn (true );
9990 // Act
10091 result = service .create (bookDTO );
10192 // Assert
102- verify (mapper , times (1 )).map (bookDTO , Book .class );
10393 assertThat (errors ).isEmpty ();
10494 verify (repository , never ()).save (any (Book .class ));
10595 assertThat (result ).isFalse ();
@@ -111,12 +101,12 @@ void givenCreate_whenBookIsValidAndDoesNotExistInRepository_thenShouldSaveBookIn
111101 boolean result = false ;
112102 BookDTO bookDTO = BookDTOsBuilder .buildOneValid ();
113103 Book book = BooksBuilder .buildOneValid ();
114- Set <ConstraintViolation <Book >> errors = new HashSet <ConstraintViolation <Book >>();
104+ Set <ConstraintViolation <BookDTO >> errors = new HashSet <ConstraintViolation <BookDTO >>();
115105 Mockito
116106 .when (mapper .map (bookDTO , Book .class ))
117107 .thenReturn (book );
118108 Mockito
119- .when (validator .validate (any (Book .class )))
109+ .when (validator .validate (any (BookDTO .class )))
120110 .thenReturn (errors );
121111 Mockito
122112 .when (repository .existsById (anyString ()))
@@ -200,15 +190,11 @@ void givenUpdate_whenBookIsInvalid_thenShouldNeverSaveBookIntoRepositoryAndRetur
200190 // Arrange
201191 boolean result = false ;
202192 BookDTO bookDTO = BookDTOsBuilder .buildOneInvalid ();
203- Book book = BooksBuilder .buildOneInvalid ();
204193 // Simplify creation of ConstraintViolationExceptions
205194 // https://hibernate.atlassian.net/browse/BVAL-198
206- Set <? extends ConstraintViolation <?>> errors = new HashSet <ConstraintViolation <Book >>();
195+ Set <? extends ConstraintViolation <?>> errors = new HashSet <ConstraintViolation <BookDTO >>();
207196 Mockito
208- .when (mapper .map (bookDTO , Book .class ))
209- .thenReturn (book );
210- Mockito
211- .when (validator .validate (any (Book .class )))
197+ .when (validator .validate (any (BookDTO .class )))
212198 .thenThrow (new ConstraintViolationException (errors ));
213199 // Act
214200 try {
@@ -217,7 +203,6 @@ void givenUpdate_whenBookIsInvalid_thenShouldNeverSaveBookIntoRepositoryAndRetur
217203 // Assert
218204 assertThat (exception ).isInstanceOf (ConstraintViolationException .class );
219205 } finally {
220- verify (mapper , times (1 )).map (bookDTO , Book .class );
221206 verify (repository , never ()).save (any (Book .class ));
222207 assertThat (result ).isFalse ();
223208 }
@@ -229,12 +214,12 @@ void givenUpdate_whenBookIsValidAndExistInRepository_thenShouldSaveBookIntoRepos
229214 boolean result = false ;
230215 BookDTO bookDTO = BookDTOsBuilder .buildOneValid ();
231216 Book book = BooksBuilder .buildOneValid ();
232- Set <ConstraintViolation <Book >> errors = new HashSet <ConstraintViolation <Book >>();
217+ Set <ConstraintViolation <BookDTO >> errors = new HashSet <ConstraintViolation <BookDTO >>();
233218 Mockito
234219 .when (mapper .map (bookDTO , Book .class ))
235220 .thenReturn (book );
236221 Mockito
237- .when (validator .validate (any (Book .class )))
222+ .when (validator .validate (any (BookDTO .class )))
238223 .thenReturn (errors );
239224 Mockito
240225 .when (repository .existsById (anyString ()))
@@ -253,21 +238,16 @@ void givenUpdate_whenBookIsValidButDoesNotExistInRepository_thenShouldNeverSaveB
253238 // Arrange
254239 boolean result = false ;
255240 BookDTO bookDTO = BookDTOsBuilder .buildOneValid ();
256- Book book = BooksBuilder .buildOneValid ();
257- Set <ConstraintViolation <Book >> errors = new HashSet <ConstraintViolation <Book >>();
241+ Set <ConstraintViolation <BookDTO >> errors = new HashSet <ConstraintViolation <BookDTO >>();
258242 Mockito
259- .when (mapper .map (bookDTO , Book .class ))
260- .thenReturn (book );
261- Mockito
262- .when (validator .validate (any (Book .class )))
243+ .when (validator .validate (any (BookDTO .class )))
263244 .thenReturn (errors );
264245 Mockito
265246 .when (repository .existsById (anyString ()))
266247 .thenReturn (false );
267248 // Act
268249 result = service .update (bookDTO );
269250 // Assert
270- verify (mapper , times (1 )).map (bookDTO , Book .class );
271251 assertThat (errors ).isEmpty ();
272252 verify (repository , never ()).save (any (Book .class ));
273253 assertThat (result ).isFalse ();
0 commit comments