forked from john-bai/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositeTest.java
More file actions
91 lines (81 loc) · 2.1 KB
/
Copy pathCompositeTest.java
File metadata and controls
91 lines (81 loc) · 2.1 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package designpatterns;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author jtherrell
*/
public class CompositeTest {
/**
* Test
*/ @Test
public void testPictureAddingLine() {
Graphic compositeObj = new Picture();
boolean result = compositeObj.add(new Line());
boolean expResult = true;
assertEquals(expResult, result);
}
/**
* Test
*/ @Test
public void testPictureAddingRectangle() {
Graphic compositeObj = new Picture();
boolean result = compositeObj.add(new Rectangle());
boolean expResult = true;
assertEquals(expResult, result);
}
/**
* Test
*/ @Test
public void testPictureAddingText() {
Graphic compositeObj = new Picture();
boolean result = compositeObj.add(new Text());
boolean expResult = true;
assertEquals(expResult, result);
}
/**
* Test
*/ @Test
public void testPictureRemoval() {
Graphic compositeObj = new Picture();
Graphic textObj = new Text();
compositeObj.add(textObj);
boolean result = compositeObj.remove(textObj);
boolean expResult = true;
assertEquals(expResult, result);
}
/**
* Test
*/ @Test
public void testPictureGetChild() {
Graphic compositeObj = new Picture();
Graphic textObj = new Text();
compositeObj.add(textObj);
Graphic returnedTextObj = compositeObj.getChild(0);
assertEquals(textObj, returnedTextObj);
}
/**
* Test
*/ @Test
public void testPictureDraw() {
Log log = new Log();
Graphic compositeObj = new Picture();
// We'll add a Picture in the Picture along with a standalone Graphic
// such as Line.
Graphic threeRectanglePicture = new Picture();
threeRectanglePicture.add(new Rectangle());
threeRectanglePicture.add(new Rectangle());
threeRectanglePicture.add(new Rectangle());
compositeObj.add(threeRectanglePicture);
compositeObj.add(new Line());
compositeObj.add(new Text());
compositeObj.draw(log);
String expResult = "RectRectRectLineText";
String result = log.toString();
assertEquals(expResult, result);
}
}