|
| 1 | +/* |
| 2 | + * Copyright 2017 Google Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.google.cloud.tools.eclipse.dataflow.core.launcher; |
| 18 | + |
| 19 | +import static org.hamcrest.CoreMatchers.instanceOf; |
| 20 | +import static org.junit.Assert.assertThat; |
| 21 | +import static org.mockito.Mockito.mock; |
| 22 | +import static org.mockito.Mockito.when; |
| 23 | + |
| 24 | +import com.google.cloud.tools.eclipse.dataflow.core.launcher.options.PipelineOptionsHierarchy; |
| 25 | +import com.google.cloud.tools.eclipse.dataflow.core.launcher.options.PipelineOptionsNamespaces; |
| 26 | +import com.google.cloud.tools.eclipse.dataflow.core.project.MajorVersion; |
| 27 | +import org.eclipse.core.resources.IProject; |
| 28 | +import org.eclipse.core.runtime.NullProgressMonitor; |
| 29 | +import org.eclipse.jdt.core.IJavaElement; |
| 30 | +import org.eclipse.jdt.core.IJavaProject; |
| 31 | +import org.eclipse.jdt.core.IType; |
| 32 | +import org.eclipse.jdt.core.JavaModelException; |
| 33 | +import org.junit.Before; |
| 34 | +import org.junit.Test; |
| 35 | +import org.junit.runner.RunWith; |
| 36 | +import org.mockito.Mock; |
| 37 | +import org.mockito.runners.MockitoJUnitRunner; |
| 38 | + |
| 39 | +@RunWith(MockitoJUnitRunner.class) |
| 40 | +public class ClasspathPipelineOptionsHierarchyFactoryTest { |
| 41 | + |
| 42 | + @Mock private IProject project; |
| 43 | + @Mock private IJavaProject javaProject; |
| 44 | + |
| 45 | + @Before |
| 46 | + public void setUp() { |
| 47 | + IJavaElement javaElement = mock(IJavaElement.class); |
| 48 | + when(project.getAdapter(IJavaElement.class)).thenReturn(javaElement); |
| 49 | + when(javaElement.getJavaProject()).thenReturn(javaProject); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testForProject_projectHasNoPipelineOptionsType() |
| 54 | + throws PipelineOptionsRetrievalException { |
| 55 | + PipelineOptionsHierarchy optionsHeierarchy = new ClasspathPipelineOptionsHierarchyFactory() |
| 56 | + .forProject(project, null, new NullProgressMonitor()); |
| 57 | + assertThat(optionsHeierarchy, instanceOf(EmptyPipelineOptionsHierarchy.class)); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testForProject_pipelineOptionsTypeDoesNotExistInProject() |
| 62 | + throws PipelineOptionsRetrievalException, JavaModelException { |
| 63 | + String version = PipelineOptionsNamespaces.rootType(MajorVersion.ONE); |
| 64 | + when(javaProject.findType(version)).thenReturn(mock(IType.class)); |
| 65 | + |
| 66 | + PipelineOptionsHierarchy optionsHeierarchy = new ClasspathPipelineOptionsHierarchyFactory() |
| 67 | + .forProject(project, MajorVersion.ONE, new NullProgressMonitor()); |
| 68 | + assertThat(optionsHeierarchy, instanceOf(EmptyPipelineOptionsHierarchy.class)); |
| 69 | + } |
| 70 | +} |
0 commit comments