-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientTest.java
More file actions
61 lines (55 loc) · 2.62 KB
/
ClientTest.java
File metadata and controls
61 lines (55 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import org.junit.Before;
import org.junit.Test;
import model.Client;
import model.SmartPortfolio;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests the functionality of the Client class to ensure it properly handles operations related to
* managing portfolios. This includes testing the creation of portfolios and the retrieval of
* existing portfolios. The tests aim to validate that the model.Client class meets the business
* requirements for accurately tracking and managing multiple portfolio entries
* associated with a single client.
*/
public class ClientTest {
private Client client;
/**
* Initializes a new model.Client object before each test execution to ensure test isolation.
* This setup method is crucial as it prepares a consistent state for the tests by creating a
* model.Client named "Janet Lim". This approach ensures that each test starts with a clean slate,
* avoiding dependencies between tests and potential side effects from previous tests.
*/
@Before
public void setUp() {
client = new Client("Janet Lim");
}
/**
* Tests the ability of the model.Client class to correctly create and retrieve portfolios.
* This method first creates a portfolio named "Tech model.Portfolio" and then checks whether this
* portfolio can be successfully retrieved from the client's portfolio list. The test verifies
* the functionality of both creating a new portfolio and retrieving it by name, ensuring that
* the create operation adds the portfolio correctly
* and the get operation retrieves it accurately.
*/
@Test
public void testGetPortfolios() {
client.createPortfolio("Tech model.Portfolio");
assertTrue("The portfolio list should contain the 'Tech model.Portfolio'",
client.getPortfolios().containsKey("Tech model.Portfolio"));
}
/**
* Tests the portfolio creation logic within the model.Client class to ensure that a
* new portfolio can be created and is returned correctly. This test specifically
* checks if the newly created portfolio object matches an expected portfolio object
* created with the same parameters. It tests the creation process
* by comparing the result of the createPortfolio
* method against a new instance of a model.Portfolio, verifying that the properties and linkage
* to the client are correctly established.
*/
@Test
public void testCreatePortfolio() {
assertEquals("Newly created portfolio should match the expected portfolio object",
new SmartPortfolio("Tech model.Portfolio", client),
client.createPortfolio("Tech model.Portfolio"));
}
}