/* * Copyright 2016 Red Hat, Inc. and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.kie.workbench.common.screens.explorer.client.utils; import java.util.Arrays; import java.util.Collection; import org.guvnor.common.services.project.model.Project; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.uberfire.backend.vfs.Path; import static org.junit.Assert.*; import static org.kie.workbench.common.screens.explorer.client.TestUtils.*; import static org.mockito.Mockito.*; @RunWith( Parameterized.class ) public class UtilsIsInBranchTest { private final Path branchRootPath; private final Project project; private final boolean isInBranch; public UtilsIsInBranchTest( final boolean isInBranch, final Path branchRootPath, final Project project ) { this.branchRootPath = branchRootPath; this.project = project; this.isInBranch = isInBranch; } @Parameterized.Parameters public static Collection<Object[]> testData() { return Arrays.asList( new Object[][]{ {false, null, null}, {false, null, mock( Project.class )}, {false, mock( Path.class ), null}, sameRoots(), differentRoots(), } ); } private static Object[] sameRoots() { final Path branchRootPath = getPathMock( "default://master@uf-playground/" ); final Project project = getProjectMock( "default://master@uf-playground/project1" ); return new Object[]{true, branchRootPath, project}; } private static Object[] differentRoots() { final Path branchRootPath = getPathMock( "default://master@uf-playground/" ); final Project project = getProjectMock( "default://debBranch@uf-playground/project1" ); return new Object[]{false, branchRootPath, project}; } @Test public void testIsInBranch() throws Exception { assertEquals( isInBranch, Utils.isInBranch( branchRootPath, project ) ); } }