View Javadoc
1   /*
2    * Copyright (c) 2012-2022, jcabi.com
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met: 1) Redistributions of source code must retain the above
8    * copyright notice, this list of conditions and the following
9    * disclaimer. 2) Redistributions in binary form must reproduce the above
10   * copyright notice, this list of conditions and the following
11   * disclaimer in the documentation and/or other materials provided
12   * with the distribution. 3) Neither the name of the jcabi.com nor
13   * the names of its contributors may be used to endorse or promote
14   * products derived from this software without specific prior written
15   * permission.
16   *
17   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21   * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28   * OF THE POSSIBILITY OF SUCH DAMAGE.
29   */
30  package org.slf4j.impl;
31  
32  import org.apache.maven.monitor.logging.DefaultLog;
33  import org.codehaus.plexus.logging.Logger;
34  import org.codehaus.plexus.logging.console.ConsoleLogger;
35  import org.hamcrest.MatcherAssert;
36  import org.hamcrest.Matchers;
37  import org.junit.jupiter.api.Test;
38  
39  /**
40   * Test case for {@link Slf4jAdapter}.
41   *
42   * @since 0.1
43   * @checkstyle ExecutableStatementCountCheck (500 lines)
44   */
45  public final class Slf4jAdapterTest {
46  
47      @Test
48      public void sendsLogMessagesThrough() {
49          final Slf4jAdapter logger = new Slf4jAdapter(
50              new DefaultLog(
51                  new ConsoleLogger(
52                      Logger.LEVEL_DEBUG,
53                      Slf4jAdapterTest.class.getName()
54                  )
55              ),
56              "com.jcabi.test"
57          );
58          logger.isTraceEnabled();
59          logger.isDebugEnabled();
60          logger.isInfoEnabled();
61          logger.isWarnEnabled();
62          logger.isErrorEnabled();
63          MatcherAssert.assertThat(
64              Slf4jAdapter.class.getName(),
65              Matchers.equalTo(logger.getName())
66          );
67          logger.trace("trace-test message");
68          logger.trace("trace-test-2", new IllegalArgumentException("trace-ex"));
69          logger.trace("trace-test {}", "trace-message");
70          logger.trace("trace-test {} {}", "trc1", "trc2");
71          logger.trace("trace-test-2 {} {}", "trace-1", "trace-2");
72          logger.debug("debug-test message");
73          logger.debug("debug-test-2", new IllegalArgumentException("debug-ex"));
74          logger.debug("debug-test {}", "debug-message");
75          logger.debug("debug-test {} {}", "dbg1", "dbg2");
76          logger.debug("debug-test-2 {} {}", "debug-1", "debug-2");
77          logger.info("info-test message");
78          logger.info("info-test-2", new IllegalArgumentException("info-ex"));
79          logger.info("info-test {}", "info-message");
80          logger.info("info-test {} {}", "inf1", "inf2");
81          logger.info("info-test-2 {} {}", "info-1", "info-2");
82          logger.warn("warn-test message");
83          logger.warn("warn-test-2", new IllegalArgumentException("warn-ex"));
84          logger.warn("warn-test {}", "warn-message");
85          logger.warn("warn-test {} {}", "warn--1", "warn--2");
86          logger.warn("warn-test-2 {} {}", "warn-1", "warn-2");
87          logger.error("error-test message");
88          logger.error("error-test-2", new IllegalArgumentException("error-ex"));
89          logger.error("error-test {}", "error-message");
90          logger.error("error-test {} {}", "error-1", "error-2");
91          logger.error("error-test-2 {} {}", "err-1", "err-2");
92      }
93  
94  }