1 package org.opentrafficsim.base.parameters;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import org.opentrafficsim.base.modelproperties.PickList;
11 import org.opentrafficsim.base.modelproperties.PickListItem;
12
13
14
15
16
17
18
19
20
21
22
23
24 public class PickTest
25 {
26
27
28
29
30
31
32
33 public final void testPickList() throws ParameterException
34 {
35 PickListItem<String> item1 = new PickListItem<>("id1", "description1", "long description 1");
36 assertEquals("can retrieve id", "id1", item1.getId());
37 assertEquals("can retrieve display text", "description1", item1.getDisplayText());
38 assertEquals("can retrieve description", "long description 1", item1.getDescription());
39 assertTrue("toString returns something with PickListItem in it", item1.toString().indexOf("PickListItem") >= 0);
40 PickList<String> pl = new PickList<>("id", "description", item1);
41 assertEquals("can retrieve id", "id", pl.getId());
42 assertEquals("can retrieve description", "description", pl.getDescription());
43 assertTrue("toString returns something with PickList in it", pl.toString().indexOf("PickList") >= 0);
44 PickListItem<String> item2 = new PickListItem<>("id1", "description2");
45 assertEquals("using 2 arg constructor sets description to display text", "description2", item2.getDisplayText());
46 assertEquals("using 2 arg constructor sets description to display text", "description2", item2.getDescription());
47 try
48 {
49 pl.addItem(item2);
50 }
51 catch (ParameterException pe)
52 {
53
54 }
55 item2 = new PickListItem<>("id2", "description2", "long description 2");
56 pl.addItem(item2);
57 String constraintDescription = pl.getConstraint().toString();
58 assertNotNull("constraint toString may not be null", constraintDescription);
59 assertTrue("constraint toString contains id1", constraintDescription.indexOf("id1") >= 0);
60 assertTrue("constraint toString contains id2", constraintDescription.indexOf("id2") >= 0);
61
62 pl = new PickList<>("id", "description", item1, item2);
63 List<PickListItem<String>> list = new ArrayList<>();
64 try
65 {
66 new PickList<>("idXX", "descriptionXX", list);
67 }
68 catch (ParameterException pe)
69 {
70
71 }
72 list.add(item1);
73 pl = new PickList<>("idXX", "descriptionXX", list);
74 assertEquals("can retrieve id", "idXX", pl.getId());
75 assertEquals("can retrieve description", "descriptionXX", pl.getDescription());
76 assertTrue("toString returns something with PickList in it", pl.toString().indexOf("PickList") >= 0);
77 }
78 }