Skip to content

Commit 51c0fba

Browse files
committed
update java/ch12 & ch13 - ch11 with README's and updated libraries.
1 parent 06ebf99 commit 51c0fba

8 files changed

Lines changed: 72 additions & 30 deletions

File tree

cs/ch12/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Test-Driven Development - C# - Chapter 12
22

3-
This solution contains a code for Chapter 12 of the book ["Test-Driven Development By Example" by
3+
This solution contains code for Chapter 12 of the book ["Test-Driven Development By Example" by
44
Kent Beck](https://a.co/d/1sr05eT). The code is written in C# and uses the NUnit testing framework for the tests.
55

66
For information on how to set up the repository, please see the [README in the ch00](../ch00/README.md) folder.

cs/ch13/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Test-Driven Development - C# - Chapter 13
22

3-
This solution contains a code for Chapter 13 of the book ["Test-Driven Development By Example" by
3+
This solution contains code for Chapter 13 of the book ["Test-Driven Development By Example" by
44
Kent Beck](https://a.co/d/1sr05eT). The code is written in C# and uses the NUnit testing framework for the tests.
55

66
For information on how to set up the repository, please see the [README in the ch00](../ch00/README.md) folder.

java/ch12/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Test-Driven Development - C# - Chapter 12
1+
# Test-Driven Development - Java - Chapter 12
22

3-
This solution contains a code for Chapter 12 of the book ["Test-Driven Development By Example" by
4-
Kent Beck](https://a.co/d/1sr05eT). The code is written in C# and uses the NUnit testing framework for the tests.
3+
This solution contains code for Chapter 12 of the book ["Test-Driven Development By Example" by
4+
Kent Beck](https://a.co/d/1sr05eT). The code is written in Java and uses the JUnit testing framework for the tests.
55

66
For information on how to set up the repository, please see the [README in the ch00](../ch00/README.md) folder.
77

@@ -88,10 +88,11 @@ By the end of the chapter, the TODO list looks like this:
8888
- [x] Delete `testFrancMultiplication()`
8989

9090
## Last Update
91-
I try and keep this code up to date with the latest versions. I generally wait until a new version of .NET SDK is
92-
released and I only update it for Long Term Support (LTS) versions. .NET 8 is the latest LTS version as of this writing.
91+
I try and keep this code up to date with the latest versions. I generally wait until a new version of the JDK or Maven is
92+
released and I only update it for major versions. JDK 25 is the latest version as of this writing, and the POM is set to
93+
use JDK 25 and JUnit 5.13.4.
9394

9495
This repository was last updated in September 2025.
95-
- .NET SDK version 8
96-
- NUnit version 4.4.0
97-
- JetBrains Rider version 2025.2.2
96+
- Java JDK version 25
97+
- JUnit version 5.13.4
98+
- JetBrains IntelliJ IDEA Ultimate version 2025.2.2

java/ch12/src/main/java/com/thesoftwaregorilla/tdd/money/Money.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public Expression plus(Money addend) {
3434

3535
@Override
3636
public boolean equals(Object object) {
37-
Money money = (Money) object;
38-
return getAmount() == money.getAmount() && getCurrency().equals(money.getCurrency());
37+
return object instanceof Money money && this.amount == money.amount && this.currency.equals(money.currency);
3938
}
4039

4140
@Override

java/ch12/src/test/java/com/thesoftwaregorilla/tdd/money/MoneyTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
import org.junit.jupiter.api.Test;
44
import static org.junit.jupiter.api.Assertions.*;
55

6+
//TODO: $5 + 10 CHF = $10 if rate is 2:1
7+
//TODO: $5 + $5 = $10
8+
//TODO: Money rounding?
9+
//TODO: hashCode()
10+
//TODO: Equal null
11+
//TODO: Equal object
12+
13+
//DONE items:
14+
//TODO: equals() -DONE
15+
//TODO: $5 * 2 = $10 - DONE
16+
//TODO: Make "amount" private - DONE
17+
//TODO: Dollar side-effects? - DONE
18+
//TODO: 5 CHF * 2 = 10 CHF - DONE
19+
//TODO: Dollar/Franc duplication - DONE
20+
//TODO: Common equals - DONE
21+
//TODO: Common Times - DONE
22+
//TODO: Compare Francs with Dollars - DONE
23+
//TODO: Currency? - DONE
24+
//TODO: Delete `testFrancMultiplication()` - DONE
25+
626
public class MoneyTest {
727

828
private final Money fiveDollar = Money.dollar(5);

java/ch13/README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Test-Driven Development - C# - Chapter 13
1+
# Test-Driven Development - Java - Chapter 13
22

3-
This solution contains a code for Chapter 13 of the book ["Test-Driven Development By Example" by
4-
Kent Beck](https://a.co/d/1sr05eT). The code is written in C# and uses the NUnit testing framework for the tests.
3+
This solution contains code for Chapter 13 of the book ["Test-Driven Development By Example" by
4+
Kent Beck](https://a.co/d/1sr05eT). The code is written in Java and uses the JUnit testing framework for the tests.
55

66
For information on how to set up the repository, please see the [README in the ch00](../ch00/README.md) folder.
77

@@ -12,14 +12,12 @@ now returns a 'Sum' object. The 'Bank' class is introduced to handle currency co
1212
given currency.
1313

1414
### Key point from the chapter
15-
Two big code changes had to happen in my code in this chapter had to happen:
16-
1. The `amount` field in the `Money` class needed to be exposed as a property so that it could be accessed from the `Sum`
17-
class.
18-
2. The constructor in the `Money` class needed to be changed to `internal` so that it could be accessed from the `Sum`
19-
class.
20-
I have a rule that I never want to expose anything that is not absolutely necessary, so I my own TDD approach to this
21-
would have been to have more explicit intention about the `Amount` property, and refactor the factory methods in `Money`
22-
for the specific implementations. I changed the code here so that the `Amount` property is `public` but `set` is `private`.
15+
The `amount` field in the `Money` class needed to be exposed as a property so that it could be accessed from the `Sum`
16+
class. For the Java version of the code, I did that a while back.
17+
18+
I have a rule that I never want to expose anything that is not absolutely necessary, so I my own TDD approach to this
19+
would have been to have more explicit intention about the `amount` property, and refactor the factory methods in `Money`
20+
for the specific implementations. I changed the code here so that the `amount` property is `public` but `set` is `private`.
2321

2422
### My thoughts on the chapter
2523
This is one of the worst chapters in the book. No matter how many times I read it, I don't understand the premise that
@@ -56,10 +54,11 @@ By the end of the chapter, the TODO list looks like this:
5654
- [x] Delete `testFrancMultiplication()`
5755

5856
## Last Update
59-
I try and keep this code up to date with the latest versions. I generally wait until a new version of .NET SDK is
60-
released and I only update it for Long Term Support (LTS) versions. .NET 8 is the latest LTS version as of this writing.
57+
I try and keep this code up to date with the latest versions. I generally wait until a new version of the JDK or Maven is
58+
released and I only update it for major versions. JDK 25 is the latest version as of this writing, and the POM is set to
59+
use JDK 25 and JUnit 5.13.4.
6160

6261
This repository was last updated in September 2025.
63-
- .NET SDK version 8
64-
- NUnit version 4.4.0
65-
- JetBrains Rider version 2025.2.2
62+
- Java JDK version 25
63+
- JUnit version 5.13.4
64+
- JetBrains IntelliJ IDEA Ultimate version 2025.2.2

java/ch13/src/main/java/com/thesoftwaregorilla/tdd/money/Money.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public Money reduce(String to) {
3939

4040
@Override
4141
public boolean equals(Object object) {
42-
Money money = (Money) object;
43-
return getAmount() == money.getAmount() && getCurrency().equals(money.getCurrency());
42+
return object instanceof Money money && this.amount == money.amount && this.currency.equals(money.currency);
4443
}
4544

4645
@Override

java/ch13/src/test/java/com/thesoftwaregorilla/tdd/money/MoneyTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@
33
import org.junit.jupiter.api.Test;
44
import static org.junit.jupiter.api.Assertions.*;
55

6+
//TODO: $5 + 10 CHF = $10 if rate is 2:1
7+
//TODO: $5 + $5 = $10
8+
//TODO: Return Money from $5 + $5
9+
//TODO: Bank.Reduce(Money) - DONE
10+
//TODO: Reduce Money with conversion
11+
//TODO: Reduce (Bank, String)
12+
//TODO: Money rounding?
13+
//TODO: hashCode()
14+
//TODO: Equal null
15+
//TODO: Equal object
16+
17+
//DONE items:
18+
//TODO: equals() -DONE
19+
//TODO: $5 * 2 = $10 - DONE
20+
//TODO: Make "amount" private - DONE
21+
//TODO: Dollar side-effects? - DONE
22+
//TODO: 5 CHF * 2 = 10 CHF - DONE
23+
//TODO: Dollar/Franc duplication - DONE
24+
//TODO: Common equals - DONE
25+
//TODO: Common Times - DONE
26+
//TODO: Compare Francs with Dollars - DONE
27+
//TODO: Currency? - DONE
28+
//TODO: Delete `testFrancMultiplication()` - DONE
29+
630
public class MoneyTest {
731

832
private final Money fiveDollar = Money.dollar(5);

0 commit comments

Comments
 (0)