Introduction to System Under Test

After we have finished this lesson, we are familiar with the classes which are used in the other lessons of this topic.

The goal of this lesson is not to criticize the way these classes are written. However, if you want to study this matter further, I recommend that you read the articles provided by this lesson (check the other yellow boxes).

Introduction to the MailingAddress Class

The MailingAddress class contains the information of a single mailing address. Because our application must handle both domestic (shipped to Finland) and international orders, the MailingAddress class must contain the following information:

  • The name of the receiver
  • Street address
  • Post office box
  • Post code
  • City
  • State
  • Country

The source code of the MailingAddress class looks as follows:

 1public class MailingAddress {
 2
 3    private final String receiver;
 4    private final String streetAddress;
 5    private final String postOfficeBox;
 6    private final String postCode;
 7    private final String city;
 8    private final String state;
 9    private final String country;
10}

There are three things I want to point out:

  • An address can have either a street address or a post office box.
  • The state information is not required in all countries (like in Finland). However, if we want to deliver an order to the United States, we have to provide this information.
  • The country information is not required if we want to deliver orders to domestic addresses.

The developers of our application decided to use the telescoping constructor (anti)pattern for creating new MailingAddress objects. They wrote three constructors which are described in the following:

First, if we want to deliver an order to the Unites States, we have to use the constructor that allows us to set all fields of the created MailingAddress object. The source code of this constructor looks as follows:

 1public class MailingAddress {
 2
 3    private final String receiver;
 4    private final String streetAddress;
 5    private final String postOfficeBox;
 6    private final String postCode;
 7    private final String city;
 8    private final String state;
 9    private final String country;
10
11    public MailingAddress(String receiver,
12                          String streetAddress,
13                          String postOfficeBox,
14                          String postCode,
15                          String city,
16                          String state,
17                          String country) {
18        this.receiver = receiver;
19        this.streetAddress = streetAddress;
20        this.postOfficeBox = postOfficeBox;
21        this.postCode = postCode;
22        this.city = city;
23        this.state = state;
24        this.country = country;
25    }
26}

We can use this constructor for creating new MailingAddress objects which contain the following addresses:

1Teddy Tester
2Test Street 51
3Test City TX 11111
4USA
5
6Teddy Tester
7PO Box 1
8Test City TX 11111
9USA

Second, if we want to deliver an order to a country that doesn’t require the state information (such as Sweden), we can use the constructor that looks as follows:

 1public class MailingAddress {
 2
 3    private final String receiver;
 4    private final String streetAddress;
 5    private final String postOfficeBox;
 6    private final String postCode;
 7    private final String city;
 8    private final String state;
 9    private final String country;
10
11    public MailingAddress(String receiver,
12                          String streetAddress,
13                          String postOfficeBox,
14                          String postCode,
15                          String city,
16                          String country) {
17        this(receiver,
18             streetAddress,
19             postOfficeBox,
20             postCode,
21             city,
22             null,
23             country
24        );
25    }
26}

We can use this constructor for creating new MailingAddress objects which contain the following addresses:

1Teddy Tester
2Test Street 51
311111 Test City
4SWEDEN
5
6Teddy Tester
7PO Box 1
811111 Test City
9SWEDEN

Third, if we want to deliver an order to Finland, we can use the constructor that looks as follows:

 1public class MailingAddress {
 2
 3    private final String receiver;
 4    private final String streetAddress;
 5    private final String postOfficeBox;
 6    private final String postCode;
 7    private final String city;
 8    private final String state;
 9    private final String country;
10
11    public MailingAddress(String receiver,
12                          String streetAddress,
13                          String postOfficeBox,
14                          String postCode,
15                          String city) {
16        this(receiver, streetAddress, postOfficeBox, postCode, city, null);
17    }
18}

We can use this constructor for creating new MailingAddress objects which contain the following addresses:

1Teddy Tester
2Test Street 51
311111 Test City
4
5Teddy Tester
6PO Box 1
711111 Test City

Next, we will take a closer look at the Task class.

Introduction to the Task Class

The Task class is used in a simple task tracker, and it contains the information of a single task. That’s why the Task class must contain the following information:

  • Id
  • The assignee of the task.
  • The user who closed the task.
  • The user who created the task.
  • Description
  • The user who modified the task.
  • Title
  • Status
  • Resolution

The source code of the Task class looks as follows:

 1public class Task {
 2
 3    private Long id;
 4    private Assignee assignee;
 5    private Closer closer;
 6    private Creator creator;
 7    private String description;
 8    private Modifier modifier;
 9    private String title;
10    private TaskStatus status;
11    private TaskResolution resolution;
12}

The Assignee, Closer, Creator, and Modifier classes are immutable value objects which store the userId of the relevant user.

The source code of the Assignee class looks as follows:

1public class Assignee {
2
3    private final Long userId;
4
5    public Assignee(Long userId) {
6        this.userId = userId;
7    }
8}

The source code of the Closer class looks as follows:

1public class Closer {
2
3    private final Long userId;
4
5    public Closer(Long userId) {
6        this.userId = userId;
7    }
8}

The source code of the Creator class looks as follows:

1public class Creator {
2
3    private final Long userId;
4
5    public Creator(Long userId) {
6        this.userId = userId;
7    }
8}

The source code of the Modifier class looks as follows:

1public class Modifier {
2
3    private final Long userId;
4
5    public Creator(Long userId) {
6        this.userId = userId;
7    }
8}

The TaskStatus enum specifies the statuses of a task. Its source code looks as follows:

1public enum TaskStatus {
2    CLOSED,
3    IN_PROGRESS,
4    OPEN
5}

The TaskResolution enum specifies the resolutions of a task. Its source code looks as follows:

1public enum TaskResolution {
2    DUPLICATE,
3    DONE,
4    WONT_DO
5}

The following figure illustrates the relationships between these components:

The developers of our task tracker application decided to use the JavaBeans pattern when they created the Task class. This means that:

  • We can create a new Task object by using a no argument constructor.
  • We can set the property values of the created object by using setter methods.
  • We can get the property values of the created object by using getter methods.

The full source code of the Task class looks as follows:

 1public class Task {
 2
 3    private Long id;
 4    private Assignee assignee;
 5    private Closer closer;
 6    private Creator creator;
 7    private String description;
 8    private Modifier modifier;
 9    private String title;
10    private TaskStatus status;
11    private TaskResolution resolution;
12
13    public Task() {
14
15    }
16
17    public Long getId() {
18        return id;
19    }
20
21    public Assignee getAssignee() {
22        return assignee;
23    }
24
25    public Closer getCloser() {
26        return closer;
27    }
28
29    public Creator getCreator() {
30        return creator;
31    }
32
33    public String getDescription() {
34        return description;
35    }
36
37    public Modifier getModifier() {
38    	return modifier;
39    }
40
41    public String getTitle() {
42        return title;
43    }
44
45    public TaskStatus getStatus() {
46        return status;
47    }
48
49    public TaskResolution getResolution() {
50        return resolution;
51    }
52
53    public void setId(Long id) {
54        this.id = id;
55    }
56
57    public void setAssignee(Assignee assignee) {
58        this.assignee = assignee;
59    }
60
61    public void setCloser(Closer closer) {
62        this.closer = closer;
63    }
64
65    public void setCreator(Creator creator) {
66        this.creator = creator;
67    }
68
69    public void setDescription(String description) {
70        this.description = description;
71    }
72
73    public void setModifier(Modifier modifier) {
74        this.modifier = modifier;
75    }
76
77    public void setTitle(String title) {
78        this.title = title;
79    }
80
81    public void setStatus(TaskStatus status) {
82        this.status = status;
83    }
84
85    public void setResolution(TaskResolution resolution) {
86        this.resolution = resolution;
87    }
88}

We are now familiar with the classes which are used in the other lessons of this topic. Let’s summarize what we learned from this lesson.

Summary

This lesson has taught us four things:

  • The MailingAddress class contains the information of a single mailing address.
  • We can create new MailingAddress objects by using the telescoping constructor (anti)pattern.
  • The Task class contains the information of a single task.
  • The Task class uses the JavaBeans pattern.