use of com.intellij.mock.MockModule in project intellij-community by JetBrains.
the class DomBasicsTest method testCopyingFromNonEmptyToEmpty.
public void testCopyingFromNonEmptyToEmpty() throws Throwable {
Module module = new MockModule(getTestRootDisposable());
final MyElement element1 = getDomManager().createMockElement(MyElement.class, module, false);
final MyElement element2 = getDomManager().createMockElement(MyElement.class, module, false);
element2.ensureTagExists();
assertNull(element2.getChild().getChild().getGenericValue().getStringValue());
element1.getChild().getChild().getGenericValue().setStringValue("abc");
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
element2.copyFrom(element1);
}
}.execute();
assertEquals("abc", element2.getChild().getChild().getGenericValue().getStringValue());
}
use of com.intellij.mock.MockModule in project intellij by bazelbuild.
the class BlazeRenderErrorContributorTest method initTest.
@Override
protected void initTest(Container applicationServices, Container projectServices) {
super.initTest(applicationServices, projectServices);
applicationServices.register(FileTypeManager.class, new MockFileTypeManager());
projectServices.register(ProjectFileIndex.class, mock(ProjectFileIndex.class));
projectServices.register(BuildReferenceManager.class, new MockBuildReferenceManager(project));
projectServices.register(TransitiveDependencyMap.class, new TransitiveDependencyMap(project));
projectServices.register(ProjectScopeBuilder.class, new ProjectScopeBuilderImpl(project));
projectServices.register(AndroidResourceModuleRegistry.class, new AndroidResourceModuleRegistry());
BlazeImportSettingsManager importSettingsManager = new BlazeImportSettingsManager();
BlazeImportSettings settings = new BlazeImportSettings("", "", "", "", BuildSystem.Blaze);
importSettingsManager.setImportSettings(settings);
projectServices.register(BlazeImportSettingsManager.class, importSettingsManager);
createPsiClassesAndSourceToTargetMap(projectServices);
projectDataManager = new MockBlazeProjectDataManager();
projectServices.register(BlazeProjectDataManager.class, projectDataManager);
ExtensionPoint<RenderErrorContributor.Provider> extensionPoint = registerExtensionPoint(ExtensionPointName.create("com.android.rendering.renderErrorContributor"), RenderErrorContributor.Provider.class);
extensionPoint.registerExtension(new RenderErrorContributor.Provider());
extensionPoint.registerExtension(new BlazeRenderErrorContributor.BlazeProvider());
module = new MockModule(project, () -> {
});
// For the isApplicable tests.
provider = new BlazeRenderErrorContributor.BlazeProvider();
}
use of com.intellij.mock.MockModule in project android by JetBrains.
the class NlUsageTrackerManagerTest method testRenderLogging.
public void testRenderLogging() {
UsageTracker usageTracker = mock(UsageTracker.class);
LinkedList<AndroidStudioEvent> logCalls = new LinkedList<>();
doAnswer(invocation -> {
logCalls.add(((AndroidStudioEvent.Builder) invocation.getArguments()[0]).build());
return null;
}).when(usageTracker).log(any());
DesignSurface surface = mock(DesignSurface.class);
when(surface.getLayoutType()).thenReturn(NlLayoutType.LAYOUT);
when(surface.getScreenMode()).thenReturn(DesignSurface.ScreenMode.BOTH);
when(surface.getScale()).thenReturn(0.50);
Configuration configuration = getConfigurationMock();
when(surface.getConfiguration()).thenReturn(configuration);
NlUsageTracker tracker = new NlUsageTrackerManager(SYNC_EXECUTOR, surface, usageTracker) {
@Override
boolean shouldLog(int percent) {
// Log everything in tests
return true;
}
};
Result renderResult = mock(Result.class);
when(renderResult.getStatus()).thenReturn(Result.Status.SUCCESS);
HtmlLinkManager linkManager = mock(HtmlLinkManager.class);
RenderLogger logger = mock(RenderLogger.class);
when(logger.getLinkManager()).thenReturn(linkManager);
ImmutableMap<String, Throwable> brokenClasses = ImmutableMap.of("com.test.mock", new Throwable("mock error"));
when(logger.getBrokenClasses()).thenReturn(brokenClasses);
RenderResult result = mock(RenderResult.class);
ViewInfo rootView = new ViewInfo("ConstraintLayout", null, 0, 0, 50, 50);
rootView.setChildren(ImmutableList.of(new ViewInfo("TextView", null, 0, 0, 30, 20)));
;
when(result.getRootViews()).thenReturn(ImmutableList.of(rootView));
when(result.getRenderResult()).thenReturn(renderResult);
when(result.getLogger()).thenReturn(logger);
when(result.getModule()).thenReturn(new MockModule(getProject(), getTestRootDisposable()));
tracker.logRenderResult(NlModel.ChangeType.EDIT, result, 230);
assertEquals(1, logCalls.size());
AndroidStudioEvent studioEvent = logCalls.getFirst();
LayoutEditorRenderResult loggedResult = studioEvent.getLayoutEditorEvent().getRenderResult();
assertEquals(Result.Status.SUCCESS.ordinal(), loggedResult.getResultCode());
assertEquals(230, loggedResult.getTotalRenderTimeMs());
assertEquals(2, loggedResult.getComponentCount());
assertEquals(1, loggedResult.getTotalIssueCount());
assertEquals(1, loggedResult.getErrorCount());
assertEquals(0, loggedResult.getFidelityWarningCount());
}
use of com.intellij.mock.MockModule in project intellij-community by JetBrains.
the class DomBasicsTest method testMockElements.
public void testMockElements() throws Throwable {
Module module = new MockModule(getTestRootDisposable());
final MyElement element = getDomManager().createMockElement(MyElement.class, module, false);
assertSame(module, element.getModule());
assertTrue(element.isValid());
assertNull(element.getXmlTag());
assertEquals(element, DomUtil.getFileElement(element).getRootElement());
assertFalse(DomUtil.getFile(element).isPhysical());
final MyElement element2 = getDomManager().createMockElement(MyElement.class, null, false);
assertNull(element2.getModule());
assertNull(element2.getXmlTag());
element2.addChildElement().getGenericValue().setStringValue("xxx");
assertNotNull(element2.getXmlTag());
final MyElement oldChild = element2.getChild();
element.getAttr().setValue("attr");
element.getGenericValue().setValue(Boolean.TRUE);
element.getChild().getGenericValue().setStringValue("abc");
element.addChildElement().getGenericValue().setStringValue("def");
new WriteCommandAction(getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
element2.copyFrom(element);
}
}.execute();
assertEquals("attr", element2.getAttr().getValue());
assertEquals("true", element2.getGenericValue().getStringValue());
final MyElement newChild = element2.getChild();
assertEquals("abc", newChild.getGenericValue().getStringValue());
final List<MyElement> childElements = element2.getChildElements();
assertEquals(1, childElements.size());
assertEquals("def", childElements.get(0).getGenericValue().getStringValue());
}
use of com.intellij.mock.MockModule in project intellij-community by JetBrains.
the class DomBasicsTest method testCopyingFromEmptyToEmpty.
public void testCopyingFromEmptyToEmpty() throws Throwable {
Module module = new MockModule(getTestRootDisposable());
MyElement element1 = getDomManager().createMockElement(MyElement.class, module, false);
MyElement element2 = getDomManager().createMockElement(MyElement.class, module, false);
element2.copyFrom(element1);
assertNull(element2.getXmlTag());
}
Aggregations