From e2774e6cd4ce8d577c067925c17d858825c7b291 Mon Sep 17 00:00:00 2001 From: generatedunixname89002005279527 Date: Tue, 28 Jan 2025 04:04:34 -0800 Subject: [PATCH] fbandroid/libraries/components/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols Reviewed By: pasqualeanatriello Differential Revision: D68759967 fbshipit-source-id: 89462dae564e6995932408c02dae06d6a2a53869 --- .../redsymbols/ComponentFinderTest.java | 68 ------ .../ComponentShortNamesCacheTest.java | 63 ------ .../ComponentsCacheServiceTest.java | 55 ----- .../redsymbols/FileGenerateUtilsTest.java | 107 ---------- .../GenerateComponentActionTest.java | 92 -------- .../GeneratedFilesListenerTest.java | 85 -------- .../OnCodeAnalysisFinishedListenerTest.java | 90 -------- .../redsymbols/RedSymbolsResolverTest.java | 197 ------------------ 8 files changed, 757 deletions(-) delete mode 100644 litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentFinderTest.java delete mode 100644 litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentShortNamesCacheTest.java delete mode 100644 litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentsCacheServiceTest.java delete mode 100644 litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/FileGenerateUtilsTest.java delete mode 100644 litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/GenerateComponentActionTest.java delete mode 100644 litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/GeneratedFilesListenerTest.java delete mode 100644 litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/OnCodeAnalysisFinishedListenerTest.java delete mode 100644 litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/RedSymbolsResolverTest.java diff --git a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentFinderTest.java b/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentFinderTest.java deleted file mode 100644 index c2a3f785d2c..00000000000 --- a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentFinderTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.intellij.redsymbols; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -import com.facebook.litho.intellij.LithoPluginIntellijTest; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiFile; -import com.intellij.psi.search.GlobalSearchScope; -import com.intellij.psi.util.PsiTreeUtil; -import java.io.IOException; -import org.junit.After; -import org.junit.Test; - -public class ComponentFinderTest extends LithoPluginIntellijTest { - - public ComponentFinderTest() { - super("testdata/file"); - } - - @After - @Override - public void tearDown() throws Exception { - ComponentsCacheService.getInstance(testHelper.getProject()).dispose(); - super.tearDown(); - } - - @Test - public void findClass() throws IOException { - final Project project = testHelper.getFixture().getProject(); - final PsiFile file = testHelper.configure("LayoutSpec.java"); - - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - final ComponentFinder finder = new ComponentFinder(project); - // Add file to cache - final PsiClass cls = PsiTreeUtil.findChildOfType(file, PsiClass.class); - FileGenerateUtils.generateClass(cls); - - // No result with project scope - final PsiClass result1 = - finder.findClass("Layout", GlobalSearchScope.projectScope(project)); - assertThat(result1).isNull(); - - // Result with component scope - final PsiClass result2 = finder.findClass("Layout", ComponentScope.getInstance()); - assertThat(result2).isNotNull(); - }); - } -} diff --git a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentShortNamesCacheTest.java b/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentShortNamesCacheTest.java deleted file mode 100644 index 1318fb20cf5..00000000000 --- a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentShortNamesCacheTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.intellij.redsymbols; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -import com.facebook.litho.intellij.LithoPluginIntellijTest; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiFile; -import com.intellij.psi.util.PsiTreeUtil; -import java.io.IOException; -import org.junit.After; -import org.junit.Test; - -public class ComponentShortNamesCacheTest extends LithoPluginIntellijTest { - - public ComponentShortNamesCacheTest() { - super("testdata/file"); - } - - @After - @Override - public void tearDown() throws Exception { - ComponentsCacheService.getInstance(testHelper.getProject()).dispose(); - super.tearDown(); - } - - @Test - public void getAllClassNames() throws IOException { - // Add file to cache - final Project project = testHelper.getFixture().getProject(); - final PsiFile file = testHelper.configure("LayoutSpec.java"); - - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - final ComponentShortNamesCache namesCache = new ComponentShortNamesCache(project); - // Add file to cache - final PsiClass cls = PsiTreeUtil.findChildOfType(file, PsiClass.class); - FileGenerateUtils.generateClass(cls); - - final String[] allClassNames = namesCache.getAllClassNames(); - assertThat(allClassNames.length).isOne(); - assertThat(allClassNames[0]).isEqualTo("Layout"); - }); - } -} diff --git a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentsCacheServiceTest.java b/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentsCacheServiceTest.java deleted file mode 100644 index 64bfffc3842..00000000000 --- a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/ComponentsCacheServiceTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.intellij.redsymbols; - -import static junit.framework.Assert.assertNotNull; -import static junit.framework.TestCase.assertSame; - -import com.facebook.litho.intellij.LithoPluginIntellijTest; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiClass; -import org.junit.Test; - -public class ComponentsCacheServiceTest extends LithoPluginIntellijTest { - - public ComponentsCacheServiceTest() { - super("testdata/services"); - } - - @Test - public void update_valueIsCached() { - final Project project = testHelper.getFixture().getProject(); - final ComponentsCacheService service = ComponentsCacheService.getInstance(project); - testHelper.getPsiClass( - psiClasses -> { - assertNotNull(psiClasses); - PsiClass cls = psiClasses.get(0); - final String componentQN = cls.getQualifiedName(); - service.update(componentQN, cls); - final PsiClass component1 = service.getComponent(componentQN); - - assertNotNull(component1); - assertSame(cls, component1); - - // Check value is cached - final PsiClass component2 = service.getComponent(componentQN); - assertSame(component1, component2); - return true; - }, - "LayoutSpec.java"); - } -} diff --git a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/FileGenerateUtilsTest.java b/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/FileGenerateUtilsTest.java deleted file mode 100644 index c3ab7ed13a5..00000000000 --- a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/FileGenerateUtilsTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.intellij.redsymbols; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.facebook.litho.intellij.LithoPluginIntellijTest; -import com.facebook.litho.intellij.LithoPluginUtils; -import com.facebook.litho.intellij.services.ComponentGenerateService; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiFile; -import java.io.IOException; -import java.util.function.BiConsumer; -import org.junit.Ignore; -import org.junit.Test; - -public class FileGenerateUtilsTest extends LithoPluginIntellijTest { - - public FileGenerateUtilsTest() { - super("testdata/services"); - } - - @Ignore("T73932936") - @Test - public void updateLayoutComponentAsync_specNotChanged_sameInMemoryComponent() throws IOException { - retrieveInitialAndUpdatedComponents( - "InitialLayoutSpec.java", - "UpdatedLayoutSpecWithSameInterface.java", - (initialComponent, updatedComponent) -> - assertThat(updatedComponent) - .describedAs( - "Expected: %s, Got: %s", initialComponent.getText(), updatedComponent.getText()) - .isSameAs(initialComponent)); - } - - @Ignore("T73932936") - @Test - public void updateMountComponentAsync_specNotChanged_sameInMemoryComponent() throws IOException { - retrieveInitialAndUpdatedComponents( - "InitialMountSpec.java", - "UpdatedMountSpecWithSameInterface.java", - (initialComponent, updatedComponent) -> - assertThat(updatedComponent).isSameAs(initialComponent)); - } - - @Ignore("T73932936") - @Test - public void updateLayoutComponentAsync_specChanged_notSameInMemoryComponent() throws IOException { - retrieveInitialAndUpdatedComponents( - "InitialLayoutSpec.java", - "UpdatedLayoutSpecWithDifferentInterface.java", - (initialComponent, updatedComponent) -> - assertThat(updatedComponent).isNotSameAs(initialComponent)); - } - - @Ignore("T73932936") - @Test - public void updateMountComponentAsync_specChanged_notSameInMemoryComponent() throws IOException { - retrieveInitialAndUpdatedComponents( - "InitialMountSpec.java", - "UpdatedMountSpecWithDifferentInterface.java", - (initialComponent, updatedComponent) -> - assertThat(updatedComponent).isNotSameAs(initialComponent)); - } - - private void retrieveInitialAndUpdatedComponents( - String fileName, String fileChangedName, BiConsumer assertion) - throws IOException { - final PsiFile file = testHelper.configure(fileName); - final PsiFile fileChanged = testHelper.configure(fileChangedName); - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - final PsiClass spec = LithoPluginUtils.getFirstClass(file, psiClass -> true).get(); - final PsiClass component = FileGenerateUtils.generateClass(spec); - - assertThat(component).isNotNull(); - - final PsiClass updatedSpec = - LithoPluginUtils.getFirstClass(fileChanged, psiClass -> true).get(); - - final PsiClass componentFromCachedModel = - FileGenerateUtils.generateClass(updatedSpec); - assertThat(component).isEqualTo(componentFromCachedModel); - - // Update model before generating new class - ComponentGenerateService.getInstance().getOrCreateSpecModel(updatedSpec, false); - final PsiClass updatedComponent = FileGenerateUtils.generateClass(updatedSpec); - assertion.accept(component, updatedComponent); - }); - } -} diff --git a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/GenerateComponentActionTest.java b/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/GenerateComponentActionTest.java deleted file mode 100644 index 7dbc601c788..00000000000 --- a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/GenerateComponentActionTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.intellij.redsymbols; - -import static org.assertj.core.api.Java6Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.facebook.litho.intellij.LithoPluginIntellijTest; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.psi.PsiFile; -import java.io.IOException; -import org.junit.Test; - -public class GenerateComponentActionTest extends LithoPluginIntellijTest { - - public GenerateComponentActionTest() { - super("testdata/file"); - } - - @Test - public void getValidSpec_whenFileHasLayoutSpec_returnsSpec() throws IOException { - final PsiFile psiFile = testHelper.configure("LayoutSpec.java"); - final AnActionEvent mock = mockEvent(psiFile); - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - assertThat(GenerateComponentAction.getValidSpec(mock).isPresent()).isTrue(); - assertThat(GenerateComponentAction.getValidSpec(mock).get().getQualifiedName()) - .isEqualTo("LayoutSpec"); - }); - } - - @Test - public void getValidSpec_whenFileHasMountSpec_returnsSpec() throws IOException { - final PsiFile psiFile = testHelper.configure("MountSpec.java"); - final AnActionEvent mock = mockEvent(psiFile); - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - assertThat(GenerateComponentAction.getValidSpec(mock).isPresent()).isTrue(); - assertThat(GenerateComponentAction.getValidSpec(mock).get().getQualifiedName()) - .isEqualTo("MountSpec"); - }); - } - - @Test - public void getValidSpec_whenFileHasSectionSpec_returnsSpec() throws IOException { - final PsiFile psiFile = testHelper.configure("SectionSpec.java"); - final AnActionEvent mock = mockEvent(psiFile); - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - assertThat(GenerateComponentAction.getValidSpec(mock).isPresent()).isTrue(); - assertThat(GenerateComponentAction.getValidSpec(mock).get().getQualifiedName()) - .isEqualTo("SectionSpec"); - }); - } - - @Test - public void getValidSpec_whenFileHasNoSpecs_returnsNothing() throws IOException { - final PsiFile psiFile = testHelper.configure("NotSpec.java"); - final AnActionEvent mock = mockEvent(psiFile); - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - assertThat(GenerateComponentAction.getValidSpec(mock).isPresent()).isFalse(); - }); - } - - private static AnActionEvent mockEvent(PsiFile psiFile) { - AnActionEvent mock = mock(AnActionEvent.class); - when(mock.getData(CommonDataKeys.PSI_FILE)).thenReturn(psiFile); - return mock; - } -} diff --git a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/GeneratedFilesListenerTest.java b/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/GeneratedFilesListenerTest.java deleted file mode 100644 index bb4350e0abf..00000000000 --- a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/GeneratedFilesListenerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.intellij.redsymbols; - -import static org.assertj.core.api.Java6Assertions.assertThat; -import static org.mockito.Mockito.when; - -import com.facebook.litho.intellij.LithoPluginIntellijTest; -import com.facebook.litho.intellij.PsiSearchUtils; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent; -import com.intellij.openapi.vfs.newvfs.events.VFileEvent; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiFile; -import com.intellij.psi.util.PsiTreeUtil; -import java.io.IOException; -import java.util.Collections; -import org.junit.After; -import org.junit.Test; -import org.mockito.Mockito; - -public class GeneratedFilesListenerTest extends LithoPluginIntellijTest { - - public GeneratedFilesListenerTest() { - super("testdata/services"); - } - - @After - @Override - public void tearDown() throws Exception { - PsiSearchUtils.getInstance().clearMocks(); - ComponentsCacheService.getInstance(testHelper.getProject()).dispose(); - super.tearDown(); - } - - @Test - public void after_Remove() throws IOException { - final Project project = testHelper.getFixture().getProject(); - final GeneratedFilesListener listener = new GeneratedFilesListener(project); - final PsiFile file = testHelper.configure("LayoutSpec.java"); - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - final PsiClass cls = PsiTreeUtil.findChildOfType(file, PsiClass.class); - // Add file to cache - FileGenerateUtils.generateClass(cls); - final ComponentsCacheService service = ComponentsCacheService.getInstance(project); - final PsiClass component = service.getComponent("Layout"); - assertThat(component).isNotNull(); - - // Mock file created and found on disk - final VFileEvent mockEvent = mockEvent(); - PsiSearchUtils.getInstance().addMock("Layout", cls); - listener.after(Collections.singletonList(mockEvent)); - // Ensure cache is cleaned - final PsiClass component2 = service.getComponent("Layout"); - assertThat(component2).isNull(); - }); - } - - private VFileEvent mockEvent() { - final VFileEvent event = Mockito.mock(VFileCreateEvent.class); - VirtualFile mockFile = Mockito.mock(VirtualFile.class); - when(mockFile.isValid()).thenReturn(true); - when(mockFile.getPath()).thenReturn(GeneratedFilesListener.BUCK_OUT_BASE); - when(event.getFile()).thenReturn(mockFile); - return event; - } -} diff --git a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/OnCodeAnalysisFinishedListenerTest.java b/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/OnCodeAnalysisFinishedListenerTest.java deleted file mode 100644 index 33b0c373d24..00000000000 --- a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/OnCodeAnalysisFinishedListenerTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.intellij.redsymbols; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -import com.facebook.litho.intellij.LithoPluginIntellijTest; -import com.facebook.litho.intellij.PsiSearchUtils; -import com.facebook.litho.intellij.settings.AppSettingsState; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiFile; -import com.intellij.psi.util.PsiTreeUtil; -import java.io.IOException; -import java.util.Arrays; -import org.junit.After; -import org.junit.Test; - -public class OnCodeAnalysisFinishedListenerTest extends LithoPluginIntellijTest { - - public OnCodeAnalysisFinishedListenerTest() { - super("testdata/actions"); - } - - @After - @Override - public void tearDown() throws Exception { - PsiSearchUtils.getInstance().clearMocks(); - super.tearDown(); - } - - @Test - public void daemonFinished_settingsTrue_resolved() throws IOException { - final PsiFile specPsiFile = testHelper.configure("LayoutSpec.java"); - final PsiFile fileUnderTest = testHelper.configure("ResolveRedSymbolsActionTest.java"); - final Project project = testHelper.getFixture().getProject(); - AppSettingsState.getInstance(project).getState().resolveRedSymbols = true; - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - // Search and highlights in test env are not populated, do it manually - PsiSearchUtils.getInstance() - .addMock("LayoutSpec", PsiTreeUtil.findChildOfType(specPsiFile, PsiClass.class)); - RedSymbolsResolverTest.parseDocument( - testHelper.getFixture().getEditor().getDocument(), fileUnderTest, project); - new OnCodeAnalysisFinishedListener(project).daemonFinished(); - }); - final PsiClass cached = ComponentsCacheService.getInstance(project).getComponent("Layout"); - assertThat(cached) - .describedAs( - "Not present in cache %s", - Arrays.toString(ComponentsCacheService.getInstance(project).getAllComponents())) - .isNotNull(); - } - - @Test - public void daemonFinished_settingsFalse_notResolved() throws IOException { - final PsiFile specPsiFile = testHelper.configure("LayoutSpec.java"); - final PsiFile fileUnderTest = testHelper.configure("ResolveRedSymbolsActionTest.java"); - final Project project = testHelper.getFixture().getProject(); - AppSettingsState.getInstance(project).getState().resolveRedSymbols = false; - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - // Search and highlights in test env are not populated, do it manually - PsiSearchUtils.getInstance() - .addMock("LayoutSpec", PsiTreeUtil.findChildOfType(specPsiFile, PsiClass.class)); - RedSymbolsResolverTest.parseDocument( - testHelper.getFixture().getEditor().getDocument(), fileUnderTest, project); - new OnCodeAnalysisFinishedListener(project).daemonFinished(); - }); - final PsiClass cached = ComponentsCacheService.getInstance(project).getComponent("Layout"); - assertThat(cached).isNull(); - } -} diff --git a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/RedSymbolsResolverTest.java b/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/RedSymbolsResolverTest.java deleted file mode 100644 index 1f88698c97c..00000000000 --- a/litho-intellij-plugin/src/test/java/com/facebook/litho/intellij/redsymbols/RedSymbolsResolverTest.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.facebook.litho.intellij.redsymbols; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -import com.facebook.litho.intellij.LithoPluginIntellijTest; -import com.facebook.litho.intellij.PsiSearchUtils; -import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; -import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl; -import com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator; -import com.intellij.codeInsight.daemon.impl.HighlightInfo; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.ex.RangeHighlighterEx; -import com.intellij.openapi.editor.impl.DocumentMarkupModel; -import com.intellij.openapi.editor.impl.MarkupModelImpl; -import com.intellij.openapi.editor.markup.HighlighterLayer; -import com.intellij.openapi.editor.markup.HighlighterTargetArea; -import com.intellij.openapi.editor.markup.MarkupModel; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.psi.PsiClass; -import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiJavaFile; -import com.intellij.psi.util.PsiTreeUtil; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.Mockito; - -@Ignore("t99683002") -public class RedSymbolsResolverTest extends LithoPluginIntellijTest { - private static final String RESOLVED_RED_SYMBOLS_KEY = "resolved_red_symbols"; - private Project project; - private PsiJavaFile pf; - private VirtualFile vf; - private Editor editor; - - public RedSymbolsResolverTest() { - super("testdata/actions"); - } - - @Before - @Override - public void setUp() throws Exception { - PsiSearchUtils.getInstance().clearMocks(); - super.setUp(); - - project = testHelper.getFixture().getProject(); - pf = (PsiJavaFile) testHelper.configure("ResolveRedSymbolsActionTest.java"); - vf = pf.getViewProvider().getVirtualFile(); - editor = testHelper.getFixture().getEditor(); - } - - @After - @Override - public void tearDown() throws Exception { - PsiSearchUtils.getInstance().clearMocks(); - ComponentsCacheService.getInstance(testHelper.getProject()).dispose(); - super.tearDown(); - } - - @Test - public void resolveRedSymbols_forInCommentSpec_skips() throws IOException { - String specType = "InComment"; - resolveRedSymbolsForSpec( - specType, - eventMetadata -> { - assertThat(eventMetadata.get(RESOLVED_RED_SYMBOLS_KEY)).isEqualTo("[]"); - - final PsiClass cached = - ComponentsCacheService.getInstance(project).getComponent(specType); - assertThat(cached).isNull(); - }); - } - - @Test - public void resolveRedSymbols_forLayoutSpec_resolves() throws Exception { - final String specType = "Layout"; - resolveRedSymbolsForSpec( - specType, - eventMetadata -> { - assertResolved(specType, eventMetadata, project); - }); - } - - @Test - public void resolveRedSymbols_forMountSpec_resolves() throws Exception { - String specType = "Mount"; - resolveRedSymbolsForSpec( - specType, - eventMetadata -> { - assertResolved(specType, eventMetadata, project); - }); - } - - private static void assertResolved( - String specType, Map eventMetadata, Project project) { - assertThat(eventMetadata.get(RESOLVED_RED_SYMBOLS_KEY)).isEqualTo("[" + specType + "]"); - - final PsiClass cached = ComponentsCacheService.getInstance(project).getComponent(specType); - assertThat(cached).isNotNull(); - assertThat(cached.getName()).isEqualTo(specType); - } - - private void resolveRedSymbolsForSpec( - String specType, Consumer> onFinishAction) throws IOException { - final PsiFile specPsiFile = testHelper.configure(specType + "Spec.java"); - ApplicationManager.getApplication() - .invokeAndWait( - () -> { - // Search and highlights in test env are not populated, do it manually - PsiClass mockClass = PsiTreeUtil.findChildOfType(specPsiFile, PsiClass.class); - PsiSearchUtils.getInstance().addMock(specType + "Spec", mockClass); - parseDocument(editor.getDocument(), pf, project); - - final Map eventMetadata = new HashMap<>(); - RedSymbolsResolver.resolveRedSymbols( - pf, - vf, - editor, - project, - eventMetadata, - ignore -> { - assertThat(eventMetadata).isNotEmpty(); - }); - onFinishAction.accept(eventMetadata); - }); - } - - /** In the test env MarkupModel isn't filled */ - public static void parseDocument(Document document, PsiFile psiFile, Project project) { - final List infos = new ArrayList<>(); - ProgressManager.getInstance() - .run( - new Task.Backgroundable(project, "") { - @Override - public void run(ProgressIndicator indicator) { - final ProgressIndicator daemonIndicator = new DaemonProgressIndicator(); - ProgressManager.getInstance() - .runProcess( - () -> { - ReadAction.run( - () -> - infos.addAll( - ((DaemonCodeAnalyzerImpl) - DaemonCodeAnalyzer.getInstance(project)) - .runMainPasses(psiFile, document, daemonIndicator))); - }, - daemonIndicator); - } - }); - - final MarkupModel markup = DocumentMarkupModel.forDocument(document, project, false); - infos.forEach( - info -> { - info.setHighlighter(Mockito.mock(RangeHighlighterEx.class)); - ((MarkupModelImpl) markup) - .addRangeHighlighterAndChangeAttributes( - info.startOffset, - info.endOffset, - HighlighterLayer.ERROR, - info.getTextAttributes(null, null), - HighlighterTargetArea.LINES_IN_RANGE, - false, - highlighter -> highlighter.setErrorStripeTooltip(info)); - }); - markup.getAllHighlighters(); - } -}