1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.octo.captcha.component.image.wordtoimage;
21
22
23 import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
24 import com.octo.captcha.component.image.backgroundgenerator.GradientBackgroundGenerator;
25 import com.octo.captcha.component.image.fontgenerator.FontGenerator;
26 import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
27 import com.octo.captcha.component.image.textpaster.SimpleTextPaster;
28 import com.octo.captcha.component.image.textpaster.TextPaster;
29 import junit.framework.TestCase;
30
31 import java.awt.*;
32 import java.awt.image.BufferedImage;
33
34 /***
35 * <p>Description: </p>
36 *
37 * @author <a href="mailto:mga@octo.com">Mathieu Gandin</a>
38 * @version 1.0
39 */
40 public class ComposedWordToImageTest extends TestCase {
41
42 private ComposedWordToImage composedWordToImage;
43 private Integer minAcceptedWordLength = new Integer(1);
44 private Integer maxAcceptedWordLength = new Integer(10);
45 private Integer imageHeight = new Integer(100);
46 private Integer imageWidth = new Integer(100);
47 private Integer minFontSize = new Integer(10);
48 private Integer maxFontSize = new Integer(12);
49
50 /***
51 * Constructor for ComposedWordToImageTest.
52 */
53 public ComposedWordToImageTest(String name) {
54 super(name);
55 }
56
57 public void setUp() {
58 BackgroundGenerator background = new GradientBackgroundGenerator(this.imageWidth, this.imageHeight, Color.black, Color.white);
59 FontGenerator fontGenerator = new RandomFontGenerator(this.minFontSize, this.maxFontSize);
60 TextPaster textPaster = new SimpleTextPaster(this.minAcceptedWordLength, this.maxAcceptedWordLength, Color.blue);
61 this.composedWordToImage = new ComposedWordToImage(fontGenerator, background, textPaster);
62 }
63
64 public void testGetFont() {
65 Font test = this.composedWordToImage.getFont();
66 assertNotNull(test);
67 }
68
69 public void testGetBackround() {
70 BufferedImage test = this.composedWordToImage.getBackground();
71 assertNotNull(test);
72 }
73
74 public void testGetMaxAcceptedWordLength() {
75 int expected = this.maxAcceptedWordLength.intValue();
76 int test = this.composedWordToImage.getMaxAcceptedWordLength();
77 assertEquals(expected, test);
78 }
79
80 public void testGetMinAcceptedWordLength() {
81 int expected = this.minAcceptedWordLength.intValue();
82 int test = this.composedWordToImage.getMinAcceptedWordLength();
83 assertEquals(expected, test);
84 }
85
86 public void testGetImageHeight() {
87 int expected = this.imageHeight.intValue();
88 int test = this.composedWordToImage.getImageHeight();
89 assertEquals(expected, test);
90 }
91
92 public void testGetImageWidth() {
93 int expected = this.imageWidth.intValue();
94 int test = this.composedWordToImage.getImageWidth();
95 assertEquals(expected, test);
96 }
97
98 public void testGetMinFontSize() {
99 int expected = this.minFontSize.intValue();
100 int test = this.composedWordToImage.getMinFontSize();
101 assertEquals(expected, test);
102 }
103
104 }