use of com.intellij.mock.MockProjectEx in project buck by facebook.
the class BuckModuleTest method initBuckModule.
public Project initBuckModule() {
Extensions.registerAreaClass("IDEA_PROJECT", null);
MockDisposable mockDisposable = new MockDisposable();
MockProjectEx project = new MockProjectEx(mockDisposable);
MockApplication application = new MockApplicationEx(mockDisposable);
ApplicationManager.setApplication(application, mockDisposable);
application.registerService(UISettings.class, UISettings.getShadowInstance());
application.registerService(PropertiesComponent.class, new ProjectPropertiesComponentImpl());
FileTypeManager fileTypeManager = EasyMock.createMock(FileTypeManager.class);
EasyMock.expect(fileTypeManager.getFileTypeByFileName(BuckFileType.INSTANCE.getDefaultExtension())).andReturn(BuckFileType.INSTANCE).times(3);
EasyMock.replay(fileTypeManager);
application.registerService(FileTypeManager.class, fileTypeManager);
project.addComponent(PsiDocumentManager.class, EasyMock.createMock(PsiDocumentManager.class));
return project;
}
use of com.intellij.mock.MockProjectEx in project buck by facebook.
the class BuckEventsConsumerTest method hasBuckModuleAttachReceivedNullTargetThenWeShowNone.
@Test
public void hasBuckModuleAttachReceivedNullTargetThenWeShowNone() throws NoSuchFieldException, IllegalAccessException {
Extensions.registerAreaClass("IDEA_PROJECT", null);
MockDisposable mockDisposable = new MockDisposable();
MockApplication application = new MockApplicationEx(mockDisposable);
ApplicationManager.setApplication(application, mockDisposable);
BuckEventsConsumer buckEventsConsumer = new BuckEventsConsumer(new MockProjectEx(new MockDisposable()));
buckEventsConsumer.attach(null, new DefaultTreeModel(null));
Field privateStringField = BuckEventsConsumer.class.getDeclaredField("mTarget");
privateStringField.setAccessible(true);
String fieldValue = (String) privateStringField.get(buckEventsConsumer);
assertEquals(fieldValue, "NONE");
}
use of com.intellij.mock.MockProjectEx in project buck by facebook.
the class BuckClientTest method testConnectDisconnect.
@Test
public void testConnectDisconnect() {
Extensions.registerAreaClass("IDEA_PROJECT", null);
MockDisposable mockDisposable = new MockDisposable();
MockApplication application = new MockApplicationEx(mockDisposable);
ApplicationManager.setApplication(application, mockDisposable);
Project project = new MockProjectEx(new MockDisposable());
TestBuckEventHandler handler = new TestBuckEventHandler();
BuckSocket buckSocket = new BuckSocket(handler);
BuckClientManager.getOrCreateClient(project, handler).setBuckSocket(buckSocket);
BuckClientManager.getOrCreateClient(project, handler).connect();
buckSocket.onConnect(new MockSession());
BuckClientManager.getOrCreateClient(project, handler).disconnectWithoutRetry();
buckSocket.onClose(0, "FOO");
assertFalse(BuckClientManager.getOrCreateClient(project, handler).isConnected());
}
use of com.intellij.mock.MockProjectEx in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudBreakpointHandlerTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
fixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getTestName(true)).getFixture();
fixture.setUp();
project = new MockProjectEx(getTestRootDisposable());
psiManager = mock(PsiManager.class);
project.registerService(PsiManager.class, psiManager);
XDebugSession session = mock(XDebugSession.class);
when(session.getProject()).thenReturn(project);
process = mock(CloudDebugProcess.class);
when(process.getXDebugSession()).thenReturn(session);
CloudDebugProcessState processState = mock(CloudDebugProcessState.class);
existingBreakpoints = new ArrayList<Breakpoint>();
when(processState.getCurrentServerBreakpointList()).thenReturn(ContainerUtil.immutableList(existingBreakpoints));
when(process.getProcessState()).thenReturn(processState);
stateController = mock(CloudDebugProcessStateController.class);
when(process.getStateController()).thenReturn(stateController);
registrationShouldSucceed = true;
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
addedBp.set((Breakpoint) invocation.getArguments()[0]);
SetBreakpointHandler handler = (SetBreakpointHandler) invocation.getArguments()[1];
if (registrationShouldSucceed) {
handler.onSuccess(desiredResultId);
} else {
handler.onError("Registration failed");
}
return null;
}
}).when(stateController).setBreakpointAsync(any(Breakpoint.class), any(SetBreakpointHandler.class));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
removedBp.set((String) invocation.getArguments()[0]);
return null;
}
}).when(stateController).deleteBreakpointAsync(anyString());
fileResolver = mock(ServerToIdeFileResolver.class);
handler = new CloudBreakpointHandler(process, fileResolver);
XDebuggerManager debuggerManager = mock(XDebuggerManager.class);
project.addComponent(XDebuggerManager.class, debuggerManager);
breakpointManager = mock(XBreakpointManager.class);
when(debuggerManager.getBreakpointManager()).thenReturn(breakpointManager);
}
use of com.intellij.mock.MockProjectEx in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
fixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getTestName(true)).getFixture();
fixture.setUp();
project = new MockProjectEx(getTestRootDisposable());
PsiManager psiManager = Mockito.mock(PsiManager.class);
project.registerService(PsiManager.class, psiManager);
IntegratedGoogleLoginService mockLoginService = TestUtils.installMockService(IntegratedGoogleLoginService.class);
GoogleLoginState googleLoginState = Mockito.mock(GoogleLoginState.class);
CredentialedUser user = Mockito.mock(CredentialedUser.class);
LinkedHashMap<String, CredentialedUser> allusers = new LinkedHashMap<String, CredentialedUser>();
when(user.getEmail()).thenReturn(USER);
when(user.getGoogleLoginState()).thenReturn(googleLoginState);
when(googleLoginState.fetchAccessToken()).thenReturn(PASSWORD);
when(mockLoginService.getAllUsers()).thenReturn(allusers);
allusers.put(USER, user);
}
Aggregations