package com.atlassian.bitbucket.web.conditions;

import com.atlassian.stash.internal.user.InternalNormalUser;
import com.atlassian.bitbucket.auth.AuthenticationContext;
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 IsLoggedInConditionTest {

    @Mock
    private AuthenticationContext authenticationContext;

    @InjectMocks
    private IsLoggedInCondition condition;

    @Test
    public void testNoLoggedIn() throws Exception {
        assertFalse(condition.shouldDisplay(Collections.<String, Object>emptyMap()));
    }

    @Test
    public void testLoggedIn() throws Exception {
        when(authenticationContext.getCurrentUser()).thenReturn(new InternalNormalUser.Builder().name("user").build());
        assertTrue(condition.shouldDisplay(Collections.<String, Object>emptyMap()));
    }
}
