1 package org.incava.jagol; 2 3 import java.io.*; 4 import java.util.*; 5 import junit.framework.TestCase; 6 7 8 public class TestBooleanOption extends TestCase 9 { 10 BooleanOption opt = new BooleanOption("boolopt", "this is the description of boolopt"); 11 12 public TestBooleanOption(String name) 13 { 14 super(name); 15 } 16 17 public void testDefaultNull() 18 { 19 assertEquals("boolopt", opt.getLongName()); 20 assertEquals("this is the description of boolopt", opt.getDescription()); 21 22 assertNull("default value", opt.getValue()); 23 } 24 25 public void testDefaultValue() 26 { 27 BooleanOption opt = new BooleanOption("boolopt", "this is the description of boolopt", Boolean.TRUE); 28 assertEquals("default value", Boolean.TRUE, opt.getValue()); 29 } 30 31 public void testShortName() 32 { 33 opt.setShortName('n'); 34 assertEquals('n', opt.getShortName()); 35 } 36 37 public void testSetBooleanValue() 38 { 39 opt.setValue(Boolean.TRUE); 40 assertEquals("option value", Boolean.TRUE, opt.getValue()); 41 42 opt.setValue(Boolean.FALSE); 43 assertEquals("option value", Boolean.FALSE, opt.getValue()); 44 } 45 46 public void testSetFromArgsListPositive() 47 { 48 List args = new ArrayList(); 49 try { 50 boolean processed = opt.set("--boolopt", args); 51 assertEquals("option processed", true, processed); 52 assertEquals("option value", Boolean.TRUE, opt.getValue()); 53 assertEquals("argument removed from list", 0, args.size()); 54 } 55 catch (OptionException ite) { 56 fail("failure is not an option"); 57 } 58 } 59 60 public void testSetFromArgsListNegativeDash() 61 { 62 List args = new ArrayList(); 63 try { 64 boolean processed = opt.set("--no-boolopt", args); 65 assertEquals("option processed", true, processed); 66 assertEquals("option value", Boolean.FALSE, opt.getValue()); 67 assertEquals("argument removed from list", 0, args.size()); 68 } 69 catch (OptionException ite) { 70 fail("failure is not an option"); 71 } 72 } 73 74 public void testSetFromArgsListNegativeNoDash() 75 { 76 List args = new ArrayList(); 77 try { 78 boolean processed = opt.set("--noboolopt", args); 79 assertEquals("option processed", true, processed); 80 assertEquals("option value", Boolean.FALSE, opt.getValue()); 81 assertEquals("argument removed from list", 0, args.size()); 82 } 83 catch (OptionException ite) { 84 fail("failure is not an option"); 85 } 86 } 87 88 } 89 | Popular Tags |