001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.status;
015
016import ch.qos.logback.core.Context;
017import ch.qos.logback.core.ContextBase;
018import ch.qos.logback.core.CoreConstants;
019import org.junit.Test;
020
021import static org.junit.Assert.assertEquals;
022import static org.junit.Assert.assertTrue;
023
024/**
025 * @author Ceki Gülcü
026 */
027public class StatusUtilTest {
028
029    Context context = new ContextBase();
030    StatusUtil statusUtil = new StatusUtil(context);
031
032    @Test
033    public void emptyStatusListShouldResultInNotFound() {
034        assertEquals(-1, statusUtil.timeOfLastReset());
035    }
036
037    @Test
038    public void withoutResetsStatusUtilShouldReturnNotFound() {
039        context.getStatusManager().add(new InfoStatus("test", this));
040        assertEquals(-1, statusUtil.timeOfLastReset());
041    }
042
043    @Test
044    public void statusListShouldReturnLastResetTime() {
045        context.getStatusManager().add(new InfoStatus("test", this));
046        long resetTime = System.currentTimeMillis();
047        context.getStatusManager().add(new InfoStatus(CoreConstants.RESET_MSG_PREFIX, this));
048        context.getStatusManager().add(new InfoStatus("bla", this));
049        assertTrue(resetTime <= statusUtil.timeOfLastReset());
050    }
051
052}