1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.slf4j.helpers;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
30
31 import org.junit.Test;
32 import org.slf4j.Logger;
33
34 import java.util.Arrays;
35 import java.util.HashSet;
36 import java.util.Set;
37
38 public class SubstituteLoggerFactoryTest {
39 private final SubstituteLoggerFactory factory = new SubstituteLoggerFactory();
40
41 @Test
42 public void testFactory() {
43 Logger log = factory.getLogger("foo");
44 assertNotNull(log);
45
46 Logger log2 = factory.getLogger("foo");
47 assertTrue("Loggers with same name must be same", log == log2);
48 }
49
50 @Test
51 public void testLoggerNameList() {
52 factory.getLogger("foo1");
53 factory.getLogger("foo2");
54
55 Set<String> expectedNames = new HashSet<>(Arrays.asList("foo1", "foo2"));
56 Set<String> actualNames = new HashSet<>(factory.getLoggerNames());
57
58 assertEquals(expectedNames, actualNames);
59 }
60
61 @Test
62 public void testLoggers() {
63 factory.getLogger("foo1");
64 factory.getLogger("foo2");
65
66 Set<String> expectedNames = new HashSet<>(Arrays.asList("foo1", "foo2"));
67
68 Set<String> actualNames = new HashSet<>();
69 for (SubstituteLogger slog : factory.getLoggers()) {
70 actualNames.add(slog.getName());
71 }
72
73 assertEquals(expectedNames, actualNames);
74 }
75
76 }