1 37 38 package net.sourceforge.cruisecontrol; 39 40 import junit.framework.TestCase; 41 42 import java.util.Calendar ; 43 44 public class PauseBuilderTest extends TestCase { 45 46 private Calendar cal, cal2; 47 48 public PauseBuilderTest(String name) { 49 super(name); 50 } 51 52 public void setUp() { 53 cal = Calendar.getInstance(); 54 cal.clear(); 55 cal.set(2001, Calendar.NOVEMBER, 22); cal2 = Calendar.getInstance(); 57 cal2.clear(); 58 cal2.set(2001, Calendar.NOVEMBER, 23); } 60 61 public void testValidate() { 62 PauseBuilder pb = new PauseBuilder(); 63 64 try { 65 pb.validate(); 66 fail("PauseBuilder should throw exceptions when required fields are not set."); 67 } catch (CruiseControlException e) { 68 } 69 70 pb.setStartTime(1400); 71 try { 72 pb.validate(); 73 fail("PauseBuilder should throw exceptions when required fields are not set."); 74 } catch (CruiseControlException e) { 75 } 76 77 pb.setEndTime(1500); 78 79 try { 80 pb.validate(); 81 } catch (CruiseControlException e) { 82 fail("PauseBuilder should not throw exceptions when required fields are set."); 83 } 84 85 try { 86 pb.setDay("sUnDaY"); 87 pb.validate(); 88 pb.setDay("monday"); 89 pb.validate(); 90 pb.setDay("TuesdaY"); 91 pb.validate(); 92 pb.setDay("wedNESday"); 93 pb.validate(); 94 pb.setDay("Thursday"); 95 pb.validate(); 96 pb.setDay("friday"); 97 pb.validate(); 98 pb.setDay("SATURDAY"); 99 pb.validate(); 100 } catch (CruiseControlException e) { 101 fail("PauseBuilder shouldn't throw exception with english names for day of week (case insensitive)"); 102 } 103 try { 104 pb.setDay("1"); 105 pb.validate(); 106 fail("PauseBuilder requires english names for day of week (case insensitive)"); 107 } catch (CruiseControlException e) { 108 } 109 } 110 111 public void testIsPaused() { 112 Calendar calendar = Calendar.getInstance(); 113 calendar.set(2002, Calendar.DECEMBER, 23, 18, 00, 00); 114 115 Calendar calendar2 = Calendar.getInstance(); 116 calendar2.set(2002, Calendar.DECEMBER, 23, 20, 00, 00); 117 118 Calendar calendar3 = Calendar.getInstance(); 119 calendar3.set(2002, Calendar.DECEMBER, 23, 22, 00, 00); 120 121 Calendar calendar4 = Calendar.getInstance(); 122 calendar4.set(2002, Calendar.DECEMBER, 24, 3, 00, 00); 123 124 Calendar calendar5 = Calendar.getInstance(); 125 calendar5.set(2002, Calendar.DECEMBER, 24, 7, 00, 00); 126 127 PauseBuilder pb = new PauseBuilder(); 128 pb.setStartTime(1900); 129 pb.setEndTime(2100); 130 131 assertEquals(false, pb.isPaused(calendar.getTime())); 132 assertEquals(true, pb.isPaused(calendar2.getTime())); 133 assertEquals(false, pb.isPaused(calendar3.getTime())); 134 135 pb.setDay("monday"); 136 assertEquals(false, pb.isPaused(calendar.getTime())); 137 assertEquals(true, pb.isPaused(calendar2.getTime())); 138 assertEquals(false, pb.isPaused(calendar3.getTime())); 139 140 pb.setDay("tuesday"); 141 assertEquals(false, pb.isPaused(calendar.getTime())); 142 assertEquals(false, pb.isPaused(calendar2.getTime())); 143 assertEquals(false, pb.isPaused(calendar3.getTime())); 144 145 pb = new PauseBuilder(); 146 pb.setStartTime(2100); 147 pb.setEndTime(500); 148 149 assertEquals(false, pb.isPaused(calendar.getTime())); 150 assertEquals(true, pb.isPaused(calendar3.getTime())); 151 assertEquals(true, pb.isPaused(calendar4.getTime())); 152 assertEquals(false, pb.isPaused(calendar5.getTime())); 153 154 pb.setDay("monday"); 155 156 assertEquals(false, pb.isPaused(calendar.getTime())); 157 assertEquals(true, pb.isPaused(calendar3.getTime())); 158 assertEquals(true, pb.isPaused(calendar4.getTime())); 159 assertEquals(false, pb.isPaused(calendar5.getTime())); 160 161 pb.setDay("tuesday"); 162 163 assertEquals(false, pb.isPaused(calendar.getTime())); 164 assertEquals(false, pb.isPaused(calendar3.getTime())); 165 assertEquals(false, pb.isPaused(calendar4.getTime())); 166 assertEquals(false, pb.isPaused(calendar5.getTime())); 167 } 168 169 } 170 | Popular Tags |