1 package com.ashlux.mavenoc4jplugin.log;
2
3 import org.apache.maven.plugin.logging.Log;
4 import static org.easymock.EasyMock.*;
5 import org.testng.annotations.Test;
6
7 import java.io.ByteArrayInputStream;
8 import java.io.IOException;
9
10 import com.ashlux.mavenoc4jplugin.log.LogLevel;
11 import com.ashlux.mavenoc4jplugin.log.LogStreamGobbler;
12
13 public class LogStreamGobblerTest {
14 private static final String lineSeperator = System.getProperty("line.separator");
15
16 @Test
17 public void testLog_debug() {
18 Log log = createMock(Log.class);
19 log.debug("Log statement.");
20 replay(log);
21
22 LogStreamGobbler.log(log, LogLevel.DEBUG, "Log statement.");
23
24 verify(log);
25 }
26
27 @Test
28 public void testLog_info() {
29 Log log = createMock(Log.class);
30 log.info("Log statement.");
31 replay(log);
32
33 LogStreamGobbler.log(log, LogLevel.INFO, "Log statement.");
34
35 verify(log);
36 }
37
38 @Test
39 public void testLog_warn() {
40 Log log = createMock(Log.class);
41 log.warn("Log statement.");
42 replay(log);
43
44 LogStreamGobbler.log(log, LogLevel.WARN, "Log statement.");
45
46 verify(log);
47 }
48
49 @Test
50 public void testLog_error() {
51 Log log = createMock(Log.class);
52 log.error("Log statement.");
53 replay(log);
54
55 LogStreamGobbler.log(log, LogLevel.ERROR, "Log statement.");
56
57 verify(log);
58 }
59
60 @Test
61 public void testWork() throws IOException {
62 String testString =
63 "This is line one." + lineSeperator +
64 "This is line two." + lineSeperator +
65 "This is line three without a line seperator at the end.";
66
67 Log log = createMock(Log.class);
68 log.error("This is line one.");
69 log.error("This is line two.");
70 log.error("This is line three without a line seperator at the end.");
71 replay(log);
72
73 LogStreamGobbler.work(new ByteArrayInputStream(testString.getBytes()), log, LogLevel.ERROR);
74
75 verify(log);
76 }
77 }