1   package net.sf.chainedoptions.support;
2   
3   import java.util.LinkedList;
4   import java.util.List;
5   
6   import net.sf.chainedoptions.LabelValueBean;
7   import net.sf.chainedoptions.support.FirstItemStrategy;
8   
9   import junit.framework.TestCase;
10  
11  /***
12   * @author Mattias Arthursson
13   */
14  public class FirstItemStrategyTest extends TestCase {
15  
16      private FirstItemStrategy tested;
17  
18      protected void setUp() throws Exception {
19          super.setUp();
20  
21          tested = new FirstItemStrategy();
22  
23      }
24  
25      protected void tearDown() throws Exception {
26          super.tearDown();
27  
28          tested = null;
29      }
30  
31      public void testAdjustAndSort() {
32          List originalList = new LinkedList();
33          LabelValueBean bean1 = new LabelValueBean("xLabel", "xValue");
34          originalList.add(bean1);
35          LabelValueBean bean2 = new LabelValueBean("aLabel", "aValue");
36          originalList.add(bean2);
37  
38          List result = tested.adjustAndSort(originalList, null);
39  
40          assertEquals(2, result.size());
41          assertEquals(bean2, result.get(0));
42          assertEquals(bean1, result.get(1));
43      }
44  
45      public void testGetDefaultValue() {
46          List originalList = new LinkedList();
47          LabelValueBean bean1 = new LabelValueBean("aLabel", "aValue");
48          originalList.add(bean1);
49          LabelValueBean bean2 = new LabelValueBean("xLabel", "xValue");
50          originalList.add(bean2);
51  
52          String result = tested.getDefaultValue(originalList, null);
53  
54          assertEquals("aValue", result);
55      }
56  
57      public void testGetDefaultValue_noValues() {
58          List originalList = new LinkedList();
59  
60          String result = tested.getDefaultValue(originalList, null);
61  
62          assertEquals("", result);
63      }
64  }