View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.status;
15  
16  import ch.qos.logback.core.Context;
17  import ch.qos.logback.core.ContextBase;
18  import ch.qos.logback.core.CoreConstants;
19  import org.junit.jupiter.api.Test;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertTrue;
23  
24  /**
25   * @author Ceki Gülcü
26   */
27  public class StatusUtilTest {
28  
29      Context context = new ContextBase();
30      StatusUtil statusUtil = new StatusUtil(context);
31  
32      @Test
33      public void emptyStatusListShouldResultInNotFound() {
34          assertEquals(-1, statusUtil.timeOfLastReset());
35      }
36  
37      @Test
38      public void withoutResetsStatusUtilShouldReturnNotFound() {
39          context.getStatusManager().add(new InfoStatus("test", this));
40          assertEquals(-1, statusUtil.timeOfLastReset());
41      }
42  
43      @Test
44      public void statusListShouldReturnLastResetTime() {
45          context.getStatusManager().add(new InfoStatus("test", this));
46          long resetTime = System.currentTimeMillis();
47          context.getStatusManager().add(new InfoStatus(CoreConstants.RESET_MSG_PREFIX, this));
48          context.getStatusManager().add(new InfoStatus("bla", this));
49          assertTrue(resetTime <= statusUtil.timeOfLastReset());
50      }
51  
52  }