1 16 17 package org.apache.commons.betwixt; 18 19 import junit.framework.TestCase; 20 21 25 public class TestOptions extends TestCase { 26 27 private static final int A_SHIFT = 1 << 0; 28 private static final int B_SHIFT = 1 << 1; 29 private static final int C_SHIFT = 1 << 2; 30 31 32 public void testGetValue() { 33 Options options = new Options(); 34 options.addOption("A", "Alpha"); 35 options.addOption("B", "Beta"); 36 37 assertEquals("Get added value", "Alpha", options.getValue("A")); 38 assertNull("Value not added is null", options.getValue("C")); 39 40 options.addOption("A", "New Value"); 41 assertEquals("Lat value set wins", "New Value", options.getValue("A")); 42 } 43 44 public void testGetNames() { 45 Options options = new Options(); 46 options.addOption("A", "Alpha"); 47 options.addOption("B", "Beta"); 48 options.addOption("C", "Gamma"); 49 50 String [] names = options.getNames(); 51 assertEquals("Expected three names", 3, names.length); 52 int flag = (A_SHIFT) + (B_SHIFT) + (C_SHIFT); 53 for ( int i = 0; i <3 ; i++ ) { 54 if (names[i].equals("A")) 55 { 56 assertTrue("A named twice", (flag & (A_SHIFT))>0); 57 flag -= (A_SHIFT); 58 } 59 else if (names[i].equals("B")) 60 { 61 assertTrue("B named twice", (flag & (B_SHIFT))>0); 62 flag -= (B_SHIFT); 63 } 64 else if (names[i].equals("C")) 65 { 66 assertTrue("C named twice", (flag & (C_SHIFT))>0); 67 flag -= (C_SHIFT); 68 } 69 else 70 { 71 fail("Unexpected name: " + names[i]); 72 } 73 } 74 } 75 76 } 77 | Popular Tags |