What I Created
In this little example, I created four classes: PersonTest, which I used to drive the creation of the Person class as well as the two exception classes, AgeBelowMinimumException and AgeAboveMaximumException.
The Java source code for this Eclipse project is available for download at the Pragmatic Programmers web page for this book.[47]
Here’s the PersonTest class:
| package person; |
| |
| import static org.junit.Assert.*; |
| import org.junit.Test; |
| |
| public class PersonTest { |
| String personName = "Bob"; |
| int personAge = 21; |
| |
| @Test |
| public void testCreatePersonWithNameAndAge() { |
| Person p = new Person(personName, personAge); |
| assertEquals(personName, p.getName()); |
|
Get Beyond Legacy Code now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.