Skip to content

Commit

Permalink
Improved Checkstyle on test-classes
Browse files Browse the repository at this point in the history
  • Loading branch information
elisab3 committed May 25, 2026
1 parent 5eb6c99 commit 7fb1ee0
Show file tree
Hide file tree
Showing 12 changed files with 410 additions and 409 deletions.
200 changes: 100 additions & 100 deletions src/test/java/ExchangeTest.java

Large diffs are not rendered by default.

82 changes: 41 additions & 41 deletions src/test/java/PlayerTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import static org.junit.jupiter.api.Assertions.*;

import Model.Player;
import java.math.BigDecimal;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import Model.Player;

import java.math.BigDecimal;

/**
* Unit tests for the Player class.
Expand All @@ -16,7 +16,7 @@ public class PlayerTest {

@BeforeEach
void setUp() {
player = new Player("Jane", new BigDecimal("1000"));
player = new Player("Jane", new BigDecimal("1000"));
}

// ---- Positive tests ----
Expand All @@ -26,76 +26,76 @@ void setUp() {
*/
@Test
void testGetName() {
assertEquals("Jane", player.getName());
assertEquals("Jane", player.getName());
}

/**
* Tests that player's initial money equals starting capital.
*/
@Test
void testGetMoneyMatchesStartingCapital() {
assertEquals(new BigDecimal("1000"), player.getMoney());
assertEquals(new BigDecimal("1000"), player.getMoney());
}

/**
* Tests that adding money increases player's balance.
*/
@Test
void testAddMoney() {
player.addMoney(new BigDecimal("500"));
assertEquals(new BigDecimal("1500"), player.getMoney());
player.addMoney(new BigDecimal("500"));
assertEquals(new BigDecimal("1500"), player.getMoney());
}

/**
* Tests that adding zero money does not change balance.
*/
@Test
void testAddMoneyZero() {
player.addMoney(BigDecimal.ZERO);
assertEquals(new BigDecimal("1000"), player.getMoney());
player.addMoney(BigDecimal.ZERO);
assertEquals(new BigDecimal("1000"), player.getMoney());
}

/**
* Tests that withdrawing money decreases player's balance.
*/
@Test
void testWithdrawMoney() {
player.withdrawMoney(new BigDecimal("400"));
assertEquals(new BigDecimal("600"), player.getMoney());
player.withdrawMoney(new BigDecimal("400"));
assertEquals(new BigDecimal("600"), player.getMoney());
}

/**
* Tests that withdrawing zero money does not change balance.
*/
@Test
void testWithdrawMoneyZero() {
player.withdrawMoney(BigDecimal.ZERO);
assertEquals(new BigDecimal("1000"), player.getMoney());
player.withdrawMoney(BigDecimal.ZERO);
assertEquals(new BigDecimal("1000"), player.getMoney());
}

/**
* Tests that player's portfolio is initially empty.
*/
@Test
void testPortfolioInitiallyEmpty() {
assertTrue(player.getPortfolio().getShares().isEmpty());
assertTrue(player.getPortfolio().getShares().isEmpty());
}

/**
* Tests that player's transaction archive is initially empty.
*/
@Test
void testTransactionArchiveInitiallyEmpty() {
assertTrue(player.getTransactionArchive().isEmpty());
assertTrue(player.getTransactionArchive().isEmpty());
}

/**
* Tests that player can be created with zero starting money.
*/
@Test
void testStartingMoneyZeroAllowed() {
Player broke = new Player("Broke", BigDecimal.ZERO);
assertEquals(BigDecimal.ZERO, broke.getMoney());
Player broke = new Player("Broke", BigDecimal.ZERO);
assertEquals(BigDecimal.ZERO, broke.getMoney());
}

// ---- Negative tests ----
Expand All @@ -105,79 +105,79 @@ void testStartingMoneyZeroAllowed() {
*/
@Test
void testNullNameThrows() {
assertThrows(IllegalArgumentException.class, () ->
new Player(null, new BigDecimal("1000"))
);
assertThrows(IllegalArgumentException.class, () ->
new Player(null, new BigDecimal("1000"))
);
}

/**
* Tests that Player constructor throws when given a blank name.
*/
@Test
void testBlankNameThrows() {
assertThrows(IllegalArgumentException.class, () ->
new Player(" ", new BigDecimal("1000"))
);
assertThrows(IllegalArgumentException.class, () ->
new Player(" ", new BigDecimal("1000"))
);
}

/**
* Tests that Player constructor throws when given null starting money.
*/
@Test
void testNullStartingMoneyThrows() {
assertThrows(IllegalArgumentException.class, () ->
new Player("Jane", null)
);
assertThrows(IllegalArgumentException.class, () ->
new Player("Jane", null)
);
}

/**
* Tests that Player constructor throws when given negative starting money.
*/
@Test
void testNegativeStartingMoneyThrows() {
assertThrows(IllegalArgumentException.class, () ->
new Player("Jane", new BigDecimal("-1"))
);
assertThrows(IllegalArgumentException.class, () ->
new Player("Jane", new BigDecimal("-1"))
);
}

/**
* Tests that addMoney throws when given null amount.
*/
@Test
void testAddNullAmountThrows() {
assertThrows(IllegalArgumentException.class, () ->
player.addMoney(null)
);
assertThrows(IllegalArgumentException.class, () ->
player.addMoney(null)
);
}

/**
* Tests that addMoney throws when given negative amount.
*/
@Test
void testAddNegativeAmountThrows() {
assertThrows(IllegalArgumentException.class, () ->
player.addMoney(new BigDecimal("-100"))
);
assertThrows(IllegalArgumentException.class, () ->
player.addMoney(new BigDecimal("-100"))
);
}

/**
* Tests that withdrawMoney throws when given null amount.
*/
@Test
void testWithdrawNullAmountThrows() {
assertThrows(IllegalArgumentException.class, () ->
player.withdrawMoney(null)
);
assertThrows(IllegalArgumentException.class, () ->
player.withdrawMoney(null)
);
}

/**
* Tests that withdrawMoney throws when given negative amount.
*/
@Test
void testWithdrawNegativeAmountThrows() {
assertThrows(IllegalArgumentException.class, () ->
player.withdrawMoney(new BigDecimal("-100"))
);
assertThrows(IllegalArgumentException.class, () ->
player.withdrawMoney(new BigDecimal("-100"))
);
}
}

Loading

0 comments on commit 7fb1ee0

Please sign in to comment.