33import static org .assertj .core .api .Assertions .assertThat ;
44import static org .assertj .core .api .Assertions .assertThatCode ;
55import static org .assertj .core .api .Assertions .assertThatThrownBy ;
6+ import static org .mockito .ArgumentMatchers .any ;
7+ import static org .mockito .Mockito .doNothing ;
68import static org .mockito .Mockito .doThrow ;
79import static org .mockito .Mockito .mock ;
810import static org .mockito .Mockito .never ;
@@ -105,9 +107,10 @@ private Delete prepareDelete() {
105107 }
106108
107109 @ Test
108- public void get_GetGiven_ShouldCallCrudHandlerGet () throws CrudException {
110+ public void get_GetGiven_ShouldCallCrudHandlerGet () throws CrudException , ExecutionException {
109111 // Arrange
110112 Get get = prepareGet ();
113+ doNothing ().when (operationChecker ).check (get , context );
111114 TransactionResult result = mock (TransactionResult .class );
112115 when (crud .get (get , context )).thenReturn (Optional .of (result ));
113116
@@ -116,13 +119,32 @@ public void get_GetGiven_ShouldCallCrudHandlerGet() throws CrudException {
116119
117120 // Assert
118121 assertThat (actual ).isPresent ();
122+ verify (operationChecker ).check (get , context );
119123 verify (crud ).get (get , context );
120124 }
121125
122126 @ Test
123- public void scan_ScanGiven_ShouldCallCrudHandlerScan () throws CrudException {
127+ public void get_OperationCheckerThrowsExecutionException_ShouldThrowCrudException ()
128+ throws ExecutionException , CrudException {
129+ // Arrange
130+ Get get = prepareGet ();
131+ ExecutionException exception = new ExecutionException ("operation check failed" );
132+ doThrow (exception ).when (operationChecker ).check (get , context );
133+
134+ // Act Assert
135+ assertThatThrownBy (() -> transaction .get (get ))
136+ .isInstanceOf (CrudException .class )
137+ .hasMessage ("operation check failed. Transaction ID: " + ANY_TX_ID )
138+ .hasCause (exception );
139+ verify (operationChecker ).check (get , context );
140+ verify (crud , never ()).get (any (), any ());
141+ }
142+
143+ @ Test
144+ public void scan_ScanGiven_ShouldCallCrudHandlerScan () throws CrudException , ExecutionException {
124145 // Arrange
125146 Scan scan = prepareScan ();
147+ doNothing ().when (operationChecker ).check (scan , context );
126148 TransactionResult result = mock (TransactionResult .class );
127149 List <Result > results = Collections .singletonList (result );
128150 when (crud .scan (scan , context )).thenReturn (results );
@@ -132,14 +154,33 @@ public void scan_ScanGiven_ShouldCallCrudHandlerScan() throws CrudException {
132154
133155 // Assert
134156 assertThat (actual .size ()).isEqualTo (1 );
157+ verify (operationChecker ).check (scan , context );
135158 verify (crud ).scan (scan , context );
136159 }
137160
161+ @ Test
162+ public void scan_OperationCheckerThrowsExecutionException_ShouldThrowCrudException ()
163+ throws ExecutionException , CrudException {
164+ // Arrange
165+ Scan scan = prepareScan ();
166+ ExecutionException exception = new ExecutionException ("operation check failed" );
167+ doThrow (exception ).when (operationChecker ).check (scan , context );
168+
169+ // Act Assert
170+ assertThatThrownBy (() -> transaction .scan (scan ))
171+ .isInstanceOf (CrudException .class )
172+ .hasMessage ("operation check failed. Transaction ID: " + ANY_TX_ID )
173+ .hasCause (exception );
174+ verify (operationChecker ).check (scan , context );
175+ verify (crud , never ()).scan (any (), any ());
176+ }
177+
138178 @ Test
139179 public void getScannerAndScannerOne_ShouldCallCrudHandlerGetScannerAndScannerOne ()
140- throws CrudException {
180+ throws CrudException , ExecutionException {
141181 // Arrange
142182 Scan scan = prepareScan ();
183+ doNothing ().when (operationChecker ).check (scan , context );
143184 TransactionCrudOperable .Scanner scanner = mock (TransactionCrudOperable .Scanner .class );
144185 Result result = mock (Result .class );
145186 when (scanner .one ()).thenReturn (Optional .of (result ));
@@ -151,15 +192,17 @@ public void getScannerAndScannerOne_ShouldCallCrudHandlerGetScannerAndScannerOne
151192
152193 // Assert
153194 assertThat (actualResult ).hasValue (result );
195+ verify (operationChecker ).check (scan , context );
154196 verify (crud ).getScanner (scan , context );
155197 verify (scanner ).one ();
156198 }
157199
158200 @ Test
159201 public void getScannerAndScannerAll_ShouldCallCrudHandlerGetScannerAndScannerAll ()
160- throws CrudException {
202+ throws CrudException , ExecutionException {
161203 // Arrange
162204 Scan scan = prepareScan ();
205+ doNothing ().when (operationChecker ).check (scan , context );
163206 TransactionCrudOperable .Scanner scanner = mock (TransactionCrudOperable .Scanner .class );
164207 Result result1 = mock (Result .class );
165208 Result result2 = mock (Result .class );
@@ -172,10 +215,28 @@ public void getScannerAndScannerAll_ShouldCallCrudHandlerGetScannerAndScannerAll
172215
173216 // Assert
174217 assertThat (actualResults ).containsExactly (result1 , result2 );
218+ verify (operationChecker ).check (scan , context );
175219 verify (crud ).getScanner (scan , context );
176220 verify (scanner ).all ();
177221 }
178222
223+ @ Test
224+ public void getScanner_OperationCheckerThrowsExecutionException_ShouldThrowCrudException ()
225+ throws ExecutionException , CrudException {
226+ // Arrange
227+ Scan scan = prepareScan ();
228+ ExecutionException exception = new ExecutionException ("operation check failed" );
229+ doThrow (exception ).when (operationChecker ).check (scan , context );
230+
231+ // Act Assert
232+ assertThatThrownBy (() -> transaction .getScanner (scan ))
233+ .isInstanceOf (CrudException .class )
234+ .hasMessage ("operation check failed. Transaction ID: " + ANY_TX_ID )
235+ .hasCause (exception );
236+ verify (operationChecker ).check (scan , context );
237+ verify (crud , never ()).getScanner (any (), any ());
238+ }
239+
179240 @ Test
180241 public void put_PutGiven_ShouldCallCrudHandlerPut () throws ExecutionException , CrudException {
181242 // Arrange
@@ -589,7 +650,9 @@ public void commit_ShouldCommitStateAndRecords()
589650
590651 @ Test
591652 public void commit_SerializableUsedAndValidatedState_ShouldCommitProperly ()
592- throws CommitException , UnknownTransactionStatusException , PreparationException ,
653+ throws CommitException ,
654+ UnknownTransactionStatusException ,
655+ PreparationException ,
593656 ValidationException {
594657 // Arrange
595658 transaction .prepare ();
0 commit comments