1 package org.apache.velocity.tools.generic;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.junit.*;
23 import static org.junit.Assert.*;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import org.apache.velocity.tools.generic.Alternator;
29
30
31
32
33
34
35
36
37 public class AlternatorToolTests {
38
39 public @Test void ctorAlternatorTool() throws Exception
40 {
41 try
42 {
43 new AlternatorTool();
44 }
45 catch (Exception e)
46 {
47 fail("Constructor 'AlternatorTool()' failed due to: " + e);
48 }
49 }
50
51 public @Test void methodConfigure_Map() throws Exception
52 {
53 AlternatorTool tool = new AlternatorTool();
54 Map<String,Object> conf = new HashMap<String,Object>();
55 conf.put(AlternatorTool.AUTO_ALTERNATE_DEFAULT_KEY, false);
56 tool.configure(conf);
57 assertFalse(tool.getAutoAlternateDefault());
58 }
59
60 public @Test void methodsGetSetAutoAlternateDefault() throws Exception
61 {
62 AlternatorTool tool = new AlternatorTool();
63 assertTrue(tool.getAutoAlternateDefault());
64 tool.setAutoAlternateDefault(false);
65 assertFalse(tool.getAutoAlternateDefault());
66 tool.setAutoAlternateDefault(true);
67 assertTrue(tool.getAutoAlternateDefault());
68 }
69
70 public @Test void methodMake_ObjectVarArgs() throws Exception
71 {
72 AlternatorTool tool = new AlternatorTool();
73 assertNull(tool.make());
74 Alternator result = tool.make(new Object[] { true });
75 assertTrue((Boolean)result.getNext());
76 assertTrue((Boolean)result.getNext());
77 result = tool.make("hi", true, false, 0);
78 assertEquals("hi", result.getNext());
79 assertTrue((Boolean)result.getNext());
80 assertFalse((Boolean)result.getNext());
81 assertEquals(0, result.getNext());
82 assertEquals("hi", result.getNext());
83 result = tool.make(new Object[] { "red", "blue" });
84 result.shift();
85 assertEquals("blue", result.toString());
86 }
87
88 public @Test void methodMake_booleanObjectVarArgs() throws Exception
89 {
90 AlternatorTool tool = new AlternatorTool();
91 Alternator result = tool.make(false, new Object[] { "red", "blue" });
92 assertEquals("red", result.toString());
93 assertEquals("red", result.toString());
94 result.shift();
95 assertEquals("blue", result.toString());
96 }
97
98 public @Test void methodAuto_ObjectVarArgs() throws Exception
99 {
100 AlternatorTool tool = new AlternatorTool();
101 Alternator result = tool.auto(-1,0,null,1);
102 assertEquals("-1", result.toString());
103 assertEquals(0, result.getCurrent());
104 assertEquals("0", result.toString());
105 assertEquals(null, result.toString());
106 assertEquals("1", result.toString());
107 assertEquals("-1", result.toString());
108 }
109
110 public @Test void methodManual_ObjectVarArgs() throws Exception
111 {
112 AlternatorTool tool = new AlternatorTool();
113 Alternator result = tool.manual(new Object[] { true, false });
114 assertTrue((Boolean)result.getCurrent());
115 assertEquals("true", result.toString());
116 assertTrue((Boolean)result.getNext());
117 assertEquals("false", result.toString());
118 assertFalse((Boolean)result.getNext());
119 assertEquals("true", result.toString());
120 }
121
122 }
123