

package org.kie.workbench.common.screens.explorer.client.widgets;

import java.util.HashMap;
import java.util.HashSet;

import org.guvnor.common.services.project.context.ProjectContextChangeEvent;
import org.guvnor.common.services.project.model.Project;
import org.guvnor.structure.organizationalunit.OrganizationalUnit;
import org.guvnor.structure.repositories.Repository;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kie.workbench.common.screens.explorer.model.FolderListing;
import org.kie.workbench.common.screens.explorer.model.ProjectExplorerContent;
import org.kie.workbench.common.screens.explorer.service.ExplorerService;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.uberfire.mocks.CallerMock;
import org.uberfire.mocks.EventSourceMock;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

@RunWith( MockitoJUnitRunner.class )
public class ActiveContextItemsTest {

    @Mock
    ExplorerService explorerService;
    private ActiveContextItems activeContextItems;

    @Before
    public void setUp() throws Exception {
        activeContextItems = new ActiveContextItems( new EventSourceMock<ProjectContextChangeEvent>(),
                                                     new CallerMock<>( explorerService ) );
    }

    @Test
    public void testSetupActiveBranch() throws Exception {

        assertTrue( activeContextItems.setupActiveBranch( getProjectContext( "master" ) ) );

        assertFalse( activeContextItems.setupActiveBranch( getProjectContext( "master" ) ) );

        assertTrue( activeContextItems.setupActiveBranch( getProjectContext( "hahaaNotTheSame" ) ) );
    }

    private ProjectExplorerContent getProjectContext( final String branch ) {
        return new ProjectExplorerContent( new HashSet<>(),
                                           mock( OrganizationalUnit.class ),
                                           new HashSet<>(),
                                           mock( Repository.class ),
                                           branch,
                                           new HashSet<>(),
                                           mock( Project.class ),
                                           mock( FolderListing.class ),
                                           new HashMap<>() );
    }
}