package com.atlassian.bitbucket.web.conditions;

import com.atlassian.bitbucket.server.ApplicationStatusService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.Collections;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class ResourceExhaustedConditionTest {

    @Mock
    private ApplicationStatusService applicationStatusService;

    @InjectMocks
    private ResourceExhaustedCondition condition;

    @Before
    public void setup() throws Exception {
        condition.init(Collections.<String, String>emptyMap());
    }

    @Test
    public void testShouldDisplay() throws Exception {
        when(applicationStatusService.hasRecentlyRejectedRequests()).thenReturn(true);
        assertTrue(condition.shouldDisplay(null));
    }

    @Test
    public void testShouldNotDisplay() throws Exception {
        assertFalse(condition.shouldDisplay(null));
    }
}
