forked from john-bai/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlyweightTest.java
More file actions
45 lines (40 loc) · 1.26 KB
/
Copy pathFlyweightTest.java
File metadata and controls
45 lines (40 loc) · 1.26 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
/*
* 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.*;
import java.awt.Font;
/**
*
* @author jtherrell
*/
public class FlyweightTest {
private static final char[] chars = {'a','b','c','d','e','f'};
private static final Font[] fonts = {new Font("Arial", Font.BOLD, 12), new Font("Times", Font.ITALIC, 18)};
/**
* Test of getInstance method, of class Singleton.
*/ @Test
public void testFlyweightSingletonBehavior() {
Char[] characters = new Char[chars.length];
for (int i = 0; i < chars.length; i++) {
characters[i] = CharacterFactory.CreateCharacter(chars[i]);
assertEquals(characters[i], CharacterFactory.CreateCharacter(chars[i]));
}
}
/**
* Test of getInstance method, of class Singleton.
*/ @Test
public void testFlyweightDraw() {
Log log = new Log();
Char[] characters = new Char[chars.length];
for (int i = 0; i < chars.length; i++) {
CharacterFactory.CreateCharacter(chars[i]).draw(fonts[i%2], log);
}
String expResult = "a:Arial-BoldMT\nb:Times-Italic\nc:Arial-BoldMT\n"
+ "d:Times-Italic\ne:Arial-BoldMT\nf:Times-Italic\n";
String result = log.toString();
assertEquals(expResult, result);
}
}