@@ -338,7 +338,7 @@ public void getStableWeight_ReturnsWeight() throws ScaleException, ExecutionExce
338
338
//arrange
339
339
FormattedWeight expected = new FormattedWeight (3 );
340
340
when (mockCompletableFutureFormattedWeight .get (30000 , TimeUnit .MILLISECONDS )).thenReturn (expected );
341
-
341
+ when ( mockScaleDevice . tryLock ()). thenReturn ( true );
342
342
//act
343
343
FormattedWeight actual = scaleManager .getStableWeight (mockCompletableFutureFormattedWeight );
344
344
@@ -348,12 +348,28 @@ public void getStableWeight_ReturnsWeight() throws ScaleException, ExecutionExce
348
348
assertEquals (expected , actual );
349
349
}
350
350
351
+ @ Test
352
+ public void getStableWeight_ReturnsBusy () throws ScaleException , ExecutionException , InterruptedException , TimeoutException {
353
+ //arrange
354
+ when (mockScaleDevice .tryLock ()).thenReturn (false );
355
+ //act
356
+ try {
357
+ scaleManager .getStableWeight (mockCompletableFutureFormattedWeight );
358
+ }
359
+ catch (ScaleException scaleException ) {
360
+ //assert
361
+ assertEquals ("DEVICE_BUSY" , scaleException .getDeviceError ().getCode ());
362
+ return ;
363
+ }
364
+ fail ("Expected Exception, but got none" );
365
+ }
366
+
351
367
@ Test
352
368
public void getStableWeight_ThrowsExecutionException () throws ExecutionException , InterruptedException , TimeoutException {
353
369
//arrange
354
370
ExecutionException executionException = new ExecutionException (new JposException (ScaleConst .JPOS_ESCAL_UNDER_ZERO ));
355
371
when (mockCompletableFutureFormattedWeight .get (30000 , TimeUnit .MILLISECONDS )).thenThrow (executionException );
356
-
372
+ when ( mockScaleDevice . tryLock ()). thenReturn ( true );
357
373
//act
358
374
try {
359
375
scaleManager .getStableWeight (mockCompletableFutureFormattedWeight );
@@ -372,7 +388,7 @@ public void getStableWeight_ThrowsInterruptedException() throws ExecutionExcepti
372
388
//arrange
373
389
InterruptedException interruptedException = new InterruptedException ();
374
390
when (mockCompletableFutureFormattedWeight .get (30000 , TimeUnit .MILLISECONDS )).thenThrow (interruptedException );
375
-
391
+ when ( mockScaleDevice . tryLock ()). thenReturn ( true );
376
392
//act
377
393
try {
378
394
scaleManager .getStableWeight (mockCompletableFutureFormattedWeight );
@@ -391,7 +407,7 @@ public void getStableWeight_ThrowsTimeoutException() throws ExecutionException,
391
407
//arrange
392
408
TimeoutException timeoutException = new TimeoutException ();
393
409
when (mockCompletableFutureFormattedWeight .get (30000 , TimeUnit .MILLISECONDS )).thenThrow (timeoutException );
394
-
410
+ when ( mockScaleDevice . tryLock ()). thenReturn ( true );
395
411
//act
396
412
try {
397
413
scaleManager .getStableWeight (mockCompletableFutureFormattedWeight );
0 commit comments