1 package org.slf4j;
2
3 import java.io.PrintStream;
4 import java.util.Random;
5
6 import junit.framework.TestCase;
7
8 public class VersionMismatchAssertionTest extends TestCase {
9
10 StringPrintStream sps = new StringPrintStream(System.err);
11 PrintStream old = System.err;
12 int diff = 1024 + new Random().nextInt(10000);
13
14 public VersionMismatchAssertionTest(String name) {
15 super(name);
16 }
17
18 protected void setUp() throws Exception {
19 super.setUp();
20 System.setErr(sps);
21 }
22
23 protected void tearDown() throws Exception {
24 super.tearDown();
25 System.setErr(old);
26 }
27
28 public void test() throws Exception {
29 Logger logger = LoggerFactory.getLogger(this.getClass());
30 String msg = "hello world " + diff;
31 logger.info(msg);
32
33 String s0 = (String) sps.stringList.get(0);
34 assertTrue(s0.matches("SLF4J: The requested version .* by your slf4j binding is not compatible with.*"));
35
36 String s1 = (String) sps.stringList.get(1);
37 assertTrue(s1.contains(LoggerFactory.VERSION_MISMATCH));
38
39 String s2 = (String) sps.stringList.get(2);
40 assertTrue(s2.contains(msg));
41
42 }
43 }