private CordovaProjectCLI setupMockCLI(HybridProject project) throws CoreException { IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); CordovaProjectCLI mockCLI = spy(CordovaProjectCLI.newCLIforProject(mockProject)); doReturn(mockProcess).when(mockCLI).startShell(any(IStreamListener.class), any(IProgressMonitor.class), any(ILaunchConfiguration.class)); when(mockProcess.getStreamsProxy()).thenReturn(mockStreams); when(mockProcess.isTerminated()).thenReturn(Boolean.TRUE); doReturn(mockCLI).when(project).getProjectCLI(); return mockCLI; }
@Test public void testAdditionalEnvProperties() throws CoreException{ CordovaProjectCLI mockCLI = getMockCLI(); IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); setupMocks(mockCLI, mockProcess, mockStreams); ArgumentCaptor<ILaunchConfiguration> confCaptor = ArgumentCaptor.forClass(ILaunchConfiguration.class); mockCLI.prepare(new NullProgressMonitor(), "android"); verify(mockCLI).startShell(any(IStreamListener.class), any(IProgressMonitor.class), confCaptor.capture()); Map<String,String> attr = confCaptor.getValue().getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map<String,String>)null); assertEquals(EnvironmentPropsExt.ENV_VALUE, attr.get(EnvironmentPropsExt.ENV_KEY)); }
@Test public void testGeneratedPrepareCommandCorrectly() throws CoreException, IOException{ CordovaProjectCLI mockCLI = getMockCLI(); IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); setupMocks(mockCLI, mockProcess, mockStreams); mockCLI.prepare(new NullProgressMonitor(), "android"); verify(mockStreams).write("cordova prepare android\n"); }
@Test public void testGeneratedPluginCommandCorrectlyForREMOVE() throws CoreException,IOException{ CordovaProjectCLI mockCLI = getMockCLI(); IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); setupMocks(mockCLI, mockProcess, mockStreams); mockCLI.plugin(Command.REMOVE, new NullProgressMonitor(), "cordova-plugin-console", CordovaProjectCLI.OPTION_SAVE); verify(mockStreams).write("cordova plugin remove cordova-plugin-console --save\n"); }
@Test public void testGeneratedPlatformCommandCorrectlyForREMOVE() throws CoreException,IOException{ CordovaProjectCLI mockCLI = getMockCLI(); IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); setupMocks(mockCLI, mockProcess, mockStreams); mockCLI.platform(Command.REMOVE, new NullProgressMonitor(), "ios", CordovaProjectCLI.OPTION_SAVE); verify(mockStreams).write("cordova platform remove ios --save\n"); }
@Test public void testGeneratedBuildCommandCorrectly() throws CoreException,IOException{ CordovaProjectCLI mockCLI = getMockCLI(); IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); setupMocks(mockCLI, mockProcess, mockStreams); mockCLI.build(new NullProgressMonitor(), "ios"); verify(mockStreams).write("cordova build ios\n"); }
@Test public void testGeneratedRunCommandCorrectly() throws CoreException,IOException{ CordovaProjectCLI mockCLI = getMockCLI(); IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); setupMocks(mockCLI, mockProcess, mockStreams); mockCLI.run(new NullProgressMonitor(), "android"); verify(mockStreams).write("cordova run android\n"); }
@Test public void testGeneratedEmulateCommandCorrectly() throws CoreException,IOException{ CordovaProjectCLI mockCLI = getMockCLI(); IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); setupMocks(mockCLI, mockProcess, mockStreams); mockCLI.emulate(new NullProgressMonitor(), "windows"); verify(mockStreams).write("cordova emulate windows\n"); }
@Test public void testAdditionalEnvProperties() throws CoreException{ CordovaCLI mockCLI = getMockCLI(); IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); setupMocks(mockCLI, mockProcess, mockStreams); ArgumentCaptor<ILaunchConfiguration> confCaptor = ArgumentCaptor.forClass(ILaunchConfiguration.class); mockCLI.version(new NullProgressMonitor()); verify(mockCLI).startShell(any(IStreamListener.class), any(IProgressMonitor.class), confCaptor.capture()); Map<String,String> attr = confCaptor.getValue().getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map<String,String>)null); assertEquals(EnvironmentPropsExt.ENV_VALUE, attr.get(EnvironmentPropsExt.ENV_KEY)); }
@Test public void testGeneratedVersionCommandCorrectly() throws CoreException,IOException{ CordovaCLI mockCLI = getMockCLI(); IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); setupMocks(mockCLI, mockProcess, mockStreams); mockCLI.version(new NullProgressMonitor()); verify(mockStreams).write("cordova -version\n"); }
@Test public void testGeneratedNodeVersionCommandCorrectly() throws CoreException,IOException{ CordovaCLI mockCLI = getMockCLI(); IProcess mockProcess = mock(IProcess.class); IStreamsProxy2 mockStreams = mock(IStreamsProxy2.class); setupMocks(mockCLI, mockProcess, mockStreams); mockCLI.nodeVersion(new NullProgressMonitor()); verify(mockStreams).write("node -v\n"); }
private void setupMocks(CordovaCLI mockCLI, IProcess mockProcess, IStreamsProxy2 mockStreams) throws CoreException { doReturn(mockProcess).when(mockCLI).startShell(any(IStreamListener.class), any(IProgressMonitor.class),any(ILaunchConfiguration.class)); when(mockProcess.getStreamsProxy()).thenReturn(mockStreams); when(mockProcess.isTerminated()).thenReturn(Boolean.TRUE); }