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