1 7 8 package org.sapia.validator; 9 10 import junit.framework.*; 11 import java.util.ArrayList ; 12 import java.util.List ; 13 14 18 public class StatusTest extends TestCase { 19 20 public StatusTest(String testName) { 21 super(testName); 22 } 23 24 27 public void testGetErrors() { 28 Status st = new Status(null); 29 st.addError(new ValidationErr("test", "msg")); 30 super.assertEquals(1, st.getErrors().size()); 31 } 32 33 36 public void testIsError() { 37 Status st = new Status(null); 38 st.addError(new ValidationErr("test", "msg")); 39 super.assertTrue(st.isError()); 40 } 41 42 45 public void testAddErrors() { 46 Status st = new Status(null); 47 List errs = new ArrayList (); 48 for(int i = 0; i < 5; i++){ 49 errs.add(new ValidationErr(""+i, "msg" + i)); 50 } 51 st.addErrors(errs); 52 super.assertEquals(5, st.getErrors().size()); 53 } 54 55 58 public void testRemoveErrorsFor() { 59 Status st = new Status(null); 60 List errs = new ArrayList (); 61 for(int i = 0; i < 5; i++){ 62 errs.add(new ValidationErr("test"+i, "msg" + i)); 63 } 64 st.addErrors(errs); 65 super.assertEquals(5, st.removeErrorsFor("test").size()); 66 super.assertEquals(0, st.getErrors().size()); 67 } 68 69 72 public void testRemoveErrors() { 73 Status st = new Status(null); 74 List errs = new ArrayList (); 75 for(int i = 0; i < 5; i++){ 76 errs.add(new ValidationErr(""+i, "msg" + i)); 77 } 78 st.addErrors(errs); 79 super.assertEquals(5, st.removeErrors().size()); 80 super.assertEquals(0, st.getErrors().size()); 81 } 82 83 public void testRemoveAnonymousErrors(){ 84 Status st = new Status(null); 85 List errs = new ArrayList (); 86 for(int i = 0; i < 5; i++){ 87 errs.add(new ValidationErr(""+i, "msg" + i)); 88 } 89 st.addErrors(errs); 90 st.addError(new ValidationErr(null, "test1")); 91 st.addError(new ValidationErr(null, "test2")); 92 super.assertEquals(2, st.removeAnonymousErrors().size()); 93 super.assertEquals(5, st.getErrors().size()); 94 95 } 96 97 } 98
| Popular Tags
|