Skip to content

Commit 9bdd675

Browse files
committed
update java/ch00 - ch05 with README's and updated libraries.
1 parent d6d90db commit 9bdd675

18 files changed

Lines changed: 118 additions & 71 deletions

File tree

cs/ch01/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Test-Driven Development - C# - Chapter 01
22

3-
This solution contains a code for Chapter 1 of the book ["Test-Driven Development By Example" by
3+
This solution contains code for Chapter 1 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.
77

88
## Chapter 1 - The Multi-Currency Money Example
99
Kent starts this chapter with the process you should follow for TDD:
10-
1. Quicky add a test.
10+
1. Quickly add a test.
1111
2. Run all tests and see the new one fail.
1212
3. Make a little change.
1313
4. Run all tests and see them all pass.

java/ch00/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Test-Driven Development - Java - Introduction and Base Solution
22

33
This folder contains a base solution for 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.
4+
Kent Beck](https://a.co/d/1sr05eT). The code is written in Java and uses the JUnit testing framework for the tests.
55
I use this solution as the starting point for each chapter from the book.
66

77
**To be clear:** The README's in these folders do not contain the content of the chapters. They just contain a summary

java/ch01/README.md

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

3-
This solution contains a code for Chapter 1 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 1 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
## Chapter 1 - The Multi-Currency Money Example
99
Kent starts this chapter with the process you should follow for TDD:
10-
1. Quicky add a test.
10+
1. Quickly add a test.
1111
2. Run all tests and see the new one fail.
1212
3. Make a little change.
1313
4. Run all tests and see them all pass.
@@ -17,7 +17,7 @@ He then starts out with a TODO list:
1717
- [ ] \$5 + 10 CHF = $10 if rate is 2:1
1818
- [ ] \$5 * 2 = $10
1919

20-
These TODO's are then added into the Money.Tests DollarTest class and we write the tests from there.
20+
These TODO's are then added into the DollarTest class and we write the tests from there.
2121
By the end of the chapter, that list has grown to this, and only the second item has been completed:
2222
- [ ] \$5 + 10 CHF = $10 if rate is 2:1
2323
- [x] \$5 * 2 = $10
@@ -55,7 +55,7 @@ found that when I diverged from the book, large sections became unnecessary. I m
5555
as the concepts of TDD that each chapter introduces are more important than the implementation.
5656

5757
### A note about TODO comments in the code
58-
JetBrains Rider has a TODO window that shows all the TODO comments in the code and I use it extensively in real world
58+
JetBrains IntelliJ has a TODO window that shows all the TODO comments in the code and I use it extensively in real world
5959
code. I normally delete the TODO comments when I finish the task, but in this case I have left them in to show the
6060
progression of the chapter and I have marked them as "- DONE" when they are completed.
6161

@@ -68,10 +68,11 @@ Another thing to note is that when I am working on a user story, the TODO commen
6868
tracking system (ADO or Jira) and I delete the TODO comments when I finish the task.
6969

7070
## Last Update
71-
I try and keep this code up to date with the latest versions. I generally wait until a new version of .NET SDK is
72-
released and I only update it for Long Term Support (LTS)versions. .NET 8 is the latest LTS version as of this writing.
71+
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
72+
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
73+
use JDK 25 and JUnit 5.13.4.
7374

7475
This repository was last updated in September 2025.
75-
- .NET SDK version 8
76-
- NUnit version 4.4.0
77-
- JetBrains Rider version 2025.2.2
76+
- Java JDK version 25
77+
- JUnit version 5.13.4
78+
- JetBrains IntelliJ IDEA Ultimate version 2025.2.2

java/ch01/src/main/java/com/thesoftwaregorilla/tdd/money/Dollar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class Dollar {
44
int amount;
55

6-
public Dollar(int amount) {
6+
Dollar(int amount) {
77
this.amount = amount;
88
}
99

java/ch01/src/test/java/com/thesoftwaregorilla/tdd/money/DollarTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
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 * 2 = $10 - DONE
8+
//TODO: Make "amount" private
9+
//TODO: Dollar side-effects?
10+
//TODO: Money rounding?
611

712
public class DollarTest {
8-
13+
914
@Test
1015
public void testConstruction() {
1116
Dollar five = new Dollar(5);

java/ch02/README.md

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

33
This solution contains a code for Chapter 2 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.
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

@@ -19,13 +19,13 @@ easily understood, maintained, and tested so that any changes can be made with c
1919

2020
### Key points from the chapter
2121
Kent introduces the concept of the Value Object pattern. In the Chapter 2 implementation, when the `times()` method is
22-
called, the value of `Amount` is changed, hence the title of the chapter - Degenerate Objects. He walks us through how
22+
called, the value of `amount` is changed, hence the title of the chapter - Degenerate Objects. He walks us through how
2323
he fixes this by returning an immutable value object. The idea is that the `Dollar` object should never change its state.
2424
Instead, a new object should be returned with the new state.
2525

26-
There's a key issue with the implementation in Chapter 2, though. The `Amount` member is public and settable. As I
27-
explained in the [README for Chapter 1](../ch01/README.md), in C# I would normally implement this as a read-only
28-
property (in Java, it would be a getter only) , but I have kept it as a public member to stay true to the book until
26+
There's a key issue with the implementation in Chapter 2, though. The `amount` member is public and settable. As I
27+
explained in the [README for Chapter 1](../ch01/README.md), in Java I would normally implement this as a read-only
28+
property with a getter only, but I have kept it as a public member to stay true to the book until
2929
we make it private in Chapter 4.
3030

3131
Kent also introduces the three strategies for getting to green:
@@ -42,10 +42,11 @@ By the end of the chapter, the TODO list looks like this:
4242
- [ ] Money rounding?
4343

4444
## Last Update
45-
I try and keep this code up to date with the latest versions. I generally wait until a new version of .NET SDK is
46-
released and I only update it for Long Term Support (LTS)versions. .NET 8 is the latest LTS version as of this writing.
45+
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
46+
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
47+
use JDK 25 and JUnit 5.13.4.
4748

4849
This repository was last updated in September 2025.
49-
- .NET SDK version 8
50-
- NUnit version 4.4.0
51-
- JetBrains Rider version 2025.2.2
50+
- Java JDK version 25
51+
- JUnit version 5.13.4
52+
- JetBrains IntelliJ IDEA Ultimate version 2025.2.2

java/ch02/src/main/java/com/thesoftwaregorilla/tdd/money/Dollar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class Dollar {
44
int amount;
55

6-
public Dollar(int amount) {
6+
Dollar(int amount) {
77
this.amount = amount;
88
}
99

java/ch02/src/test/java/com/thesoftwaregorilla/tdd/money/DollarTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
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 * 2 = $10 - DONE
8+
//TODO: Make "amount" private
9+
//TODO: Dollar side-effects? - DONE
10+
//TODO: Money rounding?
611

712
public class DollarTest {
813

java/ch03/README.md

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

33
This solution contains a code for Chapter 3 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.
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

@@ -11,8 +11,8 @@ Martin Fowler has a good article on the [Value Object pattern](https://martinfow
1111
worth reading that describes the pattern in more detail. He also has a book called [Patterns of Enterprise Application
1212
Architecture](https://a.co/d/bDrbiQw) that describes the pattern in more detail. There's also a reasonably good [Wikipedia
1313
article](https://en.wikipedia.org/wiki/Value_object) that gives examples in several languages, including C#, Java & Python.
14-
If I were implementing this in the real world, I would probably use a `record` in C# as they are immutable by default and
15-
implement value equality.
14+
If I were implementing this in the real world, I would probably use a `record` in Java as they are immutable by default
15+
and implement value equality.
1616

1717
### Triangulation
1818
Kent introduces the concept of triangulation in this chapter. The idea is that you write three tests that cover the same
@@ -36,10 +36,11 @@ By the end of the chapter, the TODO list looks like this:
3636

3737

3838
## Last Update
39-
I try and keep this code up to date with the latest versions. I generally wait until a new version of .NET SDK is
40-
released and I only update it for Long Term Support (LTS)versions. .NET 8 is the latest LTS version as of this writing.
39+
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
40+
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
41+
use JDK 25 and JUnit 5.13.4.
4142

4243
This repository was last updated in September 2025.
43-
- .NET SDK version 8
44-
- NUnit version 4.4.0
45-
- JetBrains Rider version 2025.2.2
44+
- Java JDK version 25
45+
- JUnit version 5.13.4
46+
- JetBrains IntelliJ IDEA Ultimate version 2025.2.2

java/ch03/src/main/java/com/thesoftwaregorilla/tdd/money/Dollar.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public class Dollar {
44
int amount;
55

6-
public Dollar(int amount) {
6+
Dollar(int amount) {
77
this.amount = amount;
88
}
99

@@ -12,7 +12,6 @@ public Dollar times(int multiplier) {
1212
}
1313

1414
public boolean equals(Object object) {
15-
Dollar dollar = (Dollar) object;
16-
return amount == dollar.amount;
15+
return object instanceof Dollar dollar && this.amount == dollar.amount;
1716
}
1817
}

0 commit comments

Comments
 (0)