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;
26
27 import java.io.PrintStream;
28 import java.util.List;
29 import java.util.Random;
30
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import static org.junit.Assert.assertTrue;
35
36 public class MultiBindingAssertionTest {
37
38 StringPrintStream sps = new StringPrintStream(System.err);
39 PrintStream old = System.err;
40 int diff = 1024 + new Random().nextInt(10000);
41
42 @Before
43 public void setUp() throws Exception {
44 System.setErr(sps);
45 }
46
47 @After
48 public void tearDown() throws Exception {
49 System.setErr(old);
50 }
51
52 @Test
53 public void test() throws Exception {
54 Logger logger = LoggerFactory.getLogger(this.getClass());
55 String msg = "hello world " + diff;
56 logger.info(msg);
57 List<String> list = sps.stringList;
58 assertMsgContains(list, 0, "Class path contains multiple SLF4J providers.");
59 assertMsgContains(list, 1, "Found provider");
60 assertMsgContains(list, 2, "Found provider");
61 assertMsgContains(list, 3, "See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.");
62 assertMsgContains(list, 4, "Actual provider is of type [");
63 }
64
65 void assertMsgContains(List<String> strList, int index, String msg) {
66 assertTrue(((String) strList.get(index)).contains(msg));
67 }
68 }