3636import static org .junit .jupiter .api .Assertions .assertFalse ;
3737import static org .junit .jupiter .api .Assertions .assertNotNull ;
3838import static org .junit .jupiter .api .Assertions .assertTrue ;
39+ import static org .mockito .ArgumentMatchers .any ;
3940import static org .mockito .Mockito .mock ;
4041import static org .mockito .Mockito .when ;
4142
4445import java .util .Vector ;
4546
4647import megamek .client .ui .clientGUI .boardview .CollapseWarning ;
48+ import megamek .common .Hex ;
4749import megamek .common .board .Board ;
4850import megamek .common .board .Coords ;
4951import megamek .common .enums .GamePhase ;
@@ -118,6 +120,7 @@ void testConstructionFactorWarningFindMovementWarnings() {
118120 IBuilding bld = createMockBuildingWith (buildingPosition , 20 );
119121
120122 Board b = createMockBoardWith (buildingPosition , bld );
123+ when (g .getBoard ()).thenReturn (b );
121124
122125 List <Coords > warnList = CollapseWarning .findCFWarningsMovement (g , e , b );
123126
@@ -216,6 +219,7 @@ void testConstructionFactorWarningFindDeploymentWarnings() {
216219 when (b .isLegalDeployment (expectedHex , e )).thenReturn (true );
217220
218221 Game g = mock (Game .class );
222+ when (g .getBoard ()).thenReturn (b );
219223
220224 List <Coords > warnList = CollapseWarning .findCFWarningsDeployment (g , e , b );
221225
@@ -347,6 +351,8 @@ void testConstructionFactorWarningCalcTotalWeightWithUnit() {
347351 entities .add (onBuilding );
348352
349353 when (g .getEntitiesVector (new Coords (3 , 7 ), true )).thenReturn (entities );
354+ Board b = createSimpleMockBoard ();
355+ when (g .getBoard ()).thenReturn (b );
350356
351357 double totalWeight = CollapseWarning .calculateTotalTonnage (g , e , new Coords (3 , 7 ));
352358
@@ -368,6 +374,8 @@ void testConstructionFactorWarningCalcTotalWeightEntityOnBuilding() {
368374 entities .add (e );
369375
370376 when (g .getEntitiesVector (new Coords (3 , 3 ), true )).thenReturn (entities );
377+ Board b = createSimpleMockBoard ();
378+ when (g .getBoard ()).thenReturn (b );
371379
372380 double totalWeight = CollapseWarning .calculateTotalTonnage (g , e , new Coords (3 , 3 ));
373381
@@ -391,6 +399,8 @@ void testConstructionFactorWarningCalcTotalWeightVTOLOverHex() {
391399 entities .add (vtol );
392400
393401 when (g .getEntitiesVector (new Coords (3 , 7 ), true )).thenReturn (entities );
402+ Board b = createSimpleMockBoard ();
403+ when (g .getBoard ()).thenReturn (b );
394404
395405 double totalWeight = CollapseWarning .calculateTotalTonnage (g , e , new Coords (3 , 7 ));
396406
@@ -413,6 +423,8 @@ void testConstructionFactorWarningCalcTotalWeightAeroOverHex() {
413423 entities .add (aero );
414424
415425 when (g .getEntitiesVector (new Coords (3 , 7 ), true )).thenReturn (entities );
426+ Board b = createSimpleMockBoard ();
427+ when (g .getBoard ()).thenReturn (b );
416428
417429 double totalWeight = CollapseWarning .calculateTotalTonnage (g , e , new Coords (3 , 7 ));
418430
@@ -447,6 +459,16 @@ private IBuilding createMockBuildingWith(Coords pos, int cf) {
447459 private Board createMockBoardWith (Coords pos , IBuilding bld ) {
448460 Board b = mock (Board .class );
449461 when (b .getBuildingAt (pos )).thenReturn (bld );
462+ Hex hex = mock (Hex .class );
463+ when (hex .hasBridge ()).thenReturn (false );
464+ return b ;
465+ }
466+
467+ private Board createSimpleMockBoard () {
468+ Board b = mock (Board .class );
469+ Hex hex = mock (Hex .class );
470+ when (hex .hasBridge ()).thenReturn (false );
471+ when (b .getHex (any ())).thenReturn (hex );
450472 return b ;
451473 }
452474}
0 commit comments