Search in sources :

Example 1 with MockModule

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());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) MockModule(com.intellij.mock.MockModule) MockModule(com.intellij.mock.MockModule) Module(com.intellij.openapi.module.Module) Result(com.intellij.openapi.application.Result)

Example 2 with MockModule

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();
}
Also used : BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) RenderErrorContributor(com.android.tools.idea.rendering.RenderErrorContributor) AndroidResourceModuleRegistry(com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry) MockFileTypeManager(com.intellij.openapi.fileTypes.MockFileTypeManager) TransitiveDependencyMap(com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap) MockModule(com.intellij.mock.MockModule) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ProjectScopeBuilderImpl(com.intellij.psi.search.ProjectScopeBuilderImpl)

Example 3 with MockModule

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());
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) RenderLogger(com.android.tools.idea.rendering.RenderLogger) Configuration(com.android.tools.idea.configurations.Configuration) RenderResult(com.android.tools.idea.rendering.RenderResult) LayoutEditorRenderResult(com.google.wireless.android.sdk.stats.LayoutEditorRenderResult) LinkedList(java.util.LinkedList) RenderResult(com.android.tools.idea.rendering.RenderResult) Result(com.android.ide.common.rendering.api.Result) LayoutEditorRenderResult(com.google.wireless.android.sdk.stats.LayoutEditorRenderResult) ViewInfo(com.android.ide.common.rendering.api.ViewInfo) UsageTracker(com.android.tools.analytics.UsageTracker) HtmlLinkManager(com.android.tools.idea.rendering.HtmlLinkManager) MockModule(com.intellij.mock.MockModule) LayoutEditorRenderResult(com.google.wireless.android.sdk.stats.LayoutEditorRenderResult) AndroidStudioEvent(com.google.wireless.android.sdk.stats.AndroidStudioEvent)

Example 4 with MockModule

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());
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) MockModule(com.intellij.mock.MockModule) MockModule(com.intellij.mock.MockModule) Module(com.intellij.openapi.module.Module) Result(com.intellij.openapi.application.Result)

Example 5 with MockModule

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());
}
Also used : MockModule(com.intellij.mock.MockModule) MockModule(com.intellij.mock.MockModule) Module(com.intellij.openapi.module.Module)

Aggregations

MockModule (com.intellij.mock.MockModule)7 Module (com.intellij.openapi.module.Module)3 BlazeImportSettings (com.google.idea.blaze.base.settings.BlazeImportSettings)2 BlazeImportSettingsManager (com.google.idea.blaze.base.settings.BlazeImportSettingsManager)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 MockFileTypeManager (com.intellij.openapi.fileTypes.MockFileTypeManager)2 ProjectScopeBuilderImpl (com.intellij.psi.search.ProjectScopeBuilderImpl)2 Result (com.android.ide.common.rendering.api.Result)1 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)1 UsageTracker (com.android.tools.analytics.UsageTracker)1 Configuration (com.android.tools.idea.configurations.Configuration)1 BuildSystemService (com.android.tools.idea.project.BuildSystemService)1 HtmlLinkManager (com.android.tools.idea.rendering.HtmlLinkManager)1 RenderErrorContributor (com.android.tools.idea.rendering.RenderErrorContributor)1 RenderLogger (com.android.tools.idea.rendering.RenderLogger)1 RenderResult (com.android.tools.idea.rendering.RenderResult)1 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)1 AndroidResourceModuleRegistry (com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry)1 BlazeBuildService (com.google.idea.blaze.base.actions.BlazeBuildService)1