Skip to content

Commit

Permalink
springframeworkguru#18 - Degenerate / Immutable Objects "Side Effects"
Browse files Browse the repository at this point in the history
(cherry picked from commit 7be4ef5)
  • Loading branch information
patrick.corbett@infomotion.de authored and patrickcorbett committed Apr 22, 2024
1 parent d7890be commit 7faecbc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/guru/springframework/Dollar.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public Dollar(int pAmount) {
amount = pAmount;
}

void times(int pMultiplier) {
amount *= pMultiplier;
Dollar times(int pMultiplier) {
return new Dollar(amount * pMultiplier);
}
}
6 changes: 4 additions & 2 deletions src/test/java/guru/springframework/MoneyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class MoneyTest {
@Test
void testMultiplication() {
Dollar five = new Dollar(5);
five.times(2);
Assertions.assertEquals(10, five.amount);
Dollar product = five.times(2);
Assertions.assertEquals(10, product.amount);
product = five.times(3);
Assertions.assertEquals(15, product.amount);
}

}

0 comments on commit 7faecbc

Please sign in to comment.