1
2
3
4
5
6
7
8
9
10 package ch.qos.logback.core.status;
11
12 import java.util.Iterator;
13
14 import junit.framework.TestCase;
15
16 public class StatusBaseTest extends TestCase {
17
18 public void testAddStatus() {
19 {
20 InfoStatus status = new InfoStatus("testing", this);
21 status.add(new ErrorStatus("error", this));
22 Iterator it = status.iterator();
23 assertTrue("No status was added", it.hasNext());
24 assertTrue("hasChilden method reported wrong result", status
25 .hasChildren());
26 }
27 {
28 InfoStatus status = new InfoStatus("testing", this);
29 try {
30 status.add(null);
31 fail("method should have thrown an Exception");
32 } catch (NullPointerException ex) {
33 }
34 }
35 }
36
37 public void testRemoveStatus() {
38 {
39 InfoStatus status = new InfoStatus("testing", this);
40 ErrorStatus error = new ErrorStatus("error", this);
41 status.add(error);
42 boolean result = status.remove(error);
43 Iterator it = status.iterator();
44 assertTrue("Remove failed", result);
45 assertFalse("No status was removed", it.hasNext());
46 assertFalse("hasChilden method reported wrong result", status
47 .hasChildren());
48 }
49 {
50 InfoStatus status = new InfoStatus("testing", this);
51 ErrorStatus error = new ErrorStatus("error", this);
52 status.add(error);
53 boolean result = status.remove(null);
54 assertFalse("Remove result was not false", result);
55 }
56 }
57
58 public void testEffectiveLevel() {
59 {
60
61 ErrorStatus status = new ErrorStatus("error", this);
62 WarnStatus warn = new WarnStatus("warning", this);
63 status.add(warn);
64 assertEquals("effective level misevaluated", status.getEffectiveLevel(),
65 Status.ERROR);
66 }
67
68 {
69
70 InfoStatus status = new InfoStatus("info", this);
71 WarnStatus warn = new WarnStatus("warning", this);
72 status.add(warn);
73 assertEquals("effective level misevaluated", status.getEffectiveLevel(),
74 Status.WARN);
75 }
76
77 {
78
79 InfoStatus status = new InfoStatus("info", this);
80 WarnStatus warn = new WarnStatus("warning", this);
81 ErrorStatus error = new ErrorStatus("error", this);
82 status.add(warn);
83 warn.add(error);
84 assertEquals("effective level misevaluated", status.getEffectiveLevel(),
85 Status.ERROR);
86 }
87 }
88
89 }