Skip to content

Commit

Permalink
Refactor insufficient Astechs dialog unit test
Browse files Browse the repository at this point in the history
Replaced direct dialog checks with contract end method in InsufficientAstechsNagDialogTest. This change improves code readability and aligns the test with recent dialog behavior updates. Removed unnecessary headless property setting and dialog initialization code.
  • Loading branch information
IllianiCBT committed Sep 15, 2024
1 parent cd7131e commit c69506a
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,27 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static mekhq.gui.dialog.nagDialogs.InsufficientAstechsNagDialog.checkAstechsNeededCount;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
* This class contains test cases for the {@link InsufficientAstechsNagDialog} class.
* It tests the different combinations of Astech requirements and verifies the behavior of the local
* {@code checkNag()} method.
* It tests the different combinations of Astech requirements and verifies the behavior of the
* {@code isContractEnded()} method.
*/
class InsufficientAstechsNagDialogTest {
// Mock objects for the tests
private Campaign campaign;
private InsufficientAstechsNagDialog dialog;

/**
* Sets up the necessary dependencies and configurations before running the test methods.
* Runs once before all tests
*/
@BeforeAll
static void setup() {
System.setProperty("java.awt.headless", "true");

try {
Systems.setInstance(Systems.loadDefault());
} catch (Exception exception) {
Expand All @@ -62,29 +60,28 @@ static void setup() {
@BeforeEach
void init() {
campaign = mock(Campaign.class);
dialog = new InsufficientAstechsNagDialog(null, campaign);
}

// In the following tests,
// Different combinations of unit states to set up desired behaviors in mock objects
// Then the checkNag() method of InsufficientAstechsNagDialog class is called,
// Then the checkAstechsNeededCount() method of InsufficientAstechsNagDialog class is called,
// and its response is checked against expected behavior

@Test
void noAstechsNeeded() {
when(campaign.getAstechNeed()).thenReturn(0);
assertFalse(dialog.checkNag());
assertFalse(checkAstechsNeededCount(campaign));
}

@Test
void oneAstechNeeded() {
when(campaign.getAstechNeed()).thenReturn(1);
assertTrue(dialog.checkNag());
assertTrue(checkAstechsNeededCount(campaign));
}

@Test
void negativeAstechsNeeded() {
when(campaign.getAstechNeed()).thenReturn(-1);
assertFalse(dialog.checkNag());
assertFalse(checkAstechsNeededCount(campaign));
}
}

0 comments on commit c69506a

Please sign in to comment.