From 246637cd7ca918336c69eaf22fcb13d01cc30503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=98=84=EC=9A=B1?= <43038815+Hyeon-Uk@users.noreply.github.com> Date: Sat, 11 May 2024 21:45:48 +0900 Subject: [PATCH] Release v1.0.3 (#12) * [Refactor] Memory optimizing with OOP Refactoring (#11) * [Refactor] Apply Flyweight Pattern for UI Memory Optimization - Components in EditorPanel uses same instance, such as `JLabel` and `JBorder` - These components are immutable objects, so by creating one and sharing it, we can save memory. - So, I apply Flyweight pattern * [Refactor] Seperate Component with responsibility - according to Single Responsibility Principle in `Object Oriented Programming Principles`, They must have only their responsibility. - so seperate responsibility and Use IOC&DI with interface * [Feat] Add `remove all action` * [Refactor] Remove ToolbarPanel Dependency in mainViewPanel In mainView, toolbarPanel is not neccessary. so remove it. * [Refactor] Change ThreadStore's Creational Patterns, Singleton to Normal Object for making tests easier * [Refactor] Restructure to Enable DI in ToolWindowFactory and Remove Singleton Pattern * [Test] Add Action Tests - AddTest - RemoveAllTest - RemoveTest - RunAllTest - RunTest - StopAllTest * [Refactor] Remove dependencies each editor components from EditorPanel using interface and abstract class * [Test] Adding EditorPanel tests * [Test] Adding MyTestList tests * [Refactor] Remove dependencies subTestList from TestListPanel using interface and abstract class * [Test] Adding TestListPanel tests * [Test] Adding MainView tests --------- Signed-off-by: Hyeon-Uk --- build.gradle.kts | 76 +++---- .../pssupporter/MyToolWindowFactory.java | 81 ++++++- .../pssupporter/actions/MyAddTestAction.java | 20 +- .../actions/MyLoadTestDataAction.java | 41 +--- .../actions/MyRemoveAllTestAction.java | 41 ++++ .../actions/MyRemoveTestAction.java | 27 ++- .../actions/MyRunAllTestsAction.java | 31 ++- .../pssupporter/actions/MyRunTestAction.java | 35 ++- .../actions/MyStopAllTestsAction.java | 20 +- .../example/pssupporter/ui/MyEditorPanel.java | 93 -------- .../example/pssupporter/ui/MyMainView.java | 110 ---------- .../pssupporter/ui/MyTestListItem.java | 33 --- .../pssupporter/ui/MyTestListPanel.java | 76 ------- .../example/pssupporter/ui/editor/Editor.java | 15 ++ .../pssupporter/ui/editor/EditorPanel.java | 11 + .../pssupporter/ui/editor/MyEditorPanel.java | 103 +++++++++ .../editor/function/InputEditorFunction.java | 10 + .../editor/function/OutputEditorFunction.java | 10 + .../editor/function/ResultEditorFunction.java | 10 + .../ui/editor/panel/InputEditorPanel.java | 11 + .../ui/editor/panel/MyInputEditorPanel.java | 30 +++ .../ui/editor/panel/MyOutputEditorPanel.java | 30 +++ .../ui/editor/panel/MyResultEditorPanel.java | 42 ++++ .../ui/editor/panel/OutputEditorPanel.java | 11 + .../ui/editor/panel/ResultEditorPanel.java | 11 + .../pssupporter/ui/factory/JLabelFactory.java | 21 ++ .../ui/factory/JTitleBorderFactory.java | 23 ++ .../ui/{ => list}/MyCellRenderer.java | 2 +- .../pssupporter/ui/list/MySubTestList.java | 57 +++++ .../pssupporter/ui/list/MyTestListItem.java | 37 ++++ .../pssupporter/ui/list/MyTestListPanel.java | 83 +++++++ .../example/pssupporter/ui/list/TestList.java | 21 ++ .../pssupporter/ui/list/TestListPanel.java | 22 ++ .../ui/list/function/SubTestListFunction.java | 24 +++ .../ui/list/panel/SubTestList.java | 12 ++ .../pssupporter/ui/main/MyMainView.java | 103 +++++++++ .../ui/toolbar/ActionToolbarPanel.java | 19 ++ .../ui/{ => toolbar}/MyToolbarPanel.java | 5 +- .../pssupporter/ui/toolbar/Toolbar.java | 8 + ...balThreadStore.java => MyThreadStore.java} | 13 +- .../utils/thread/TestRunningThread.java | 6 +- .../com/example/pssupporter/vo/TestData.java | 20 ++ src/main/resources/META-INF/plugin.xml | 24 --- .../actions/MyAddTestActionTest.java | 110 ++++++++++ .../actions/MyRemoveAllTestActionTest.java | 126 +++++++++++ .../actions/MyRemoveTestActionTest.java | 134 ++++++++++++ .../actions/MyRunAllTestsActionTest.java | 168 +++++++++++++++ .../actions/MyRunTestActionTest.java | 138 ++++++++++++ .../actions/MyStopAllTestsActionTest.java | 111 ++++++++++ .../ui/editor/EditorPanelTest.java | 80 +++++++ .../ui/factory/JLabelFactoryTest.java | 37 ++++ .../ui/factory/JTitleBorderFactoryTest.java | 36 ++++ .../ui/fake/FakeInputEditorPanel.java | 21 ++ .../ui/fake/FakeOutputEditorPanel.java | 20 ++ .../ui/fake/FakeResultEditorPanel.java | 20 ++ .../pssupporter/ui/fake/FakeSubTestList.java | 57 +++++ .../pssupporter/ui/list/SubTestListTest.java | 202 ++++++++++++++++++ .../ui/list/TestListPanelTest.java | 201 +++++++++++++++++ .../pssupporter/ui/main/MainPanelTest.java | 86 ++++++++ ...dStoreTest.java => MyThreadStoreTest.java} | 76 +++---- 60 files changed, 2582 insertions(+), 519 deletions(-) create mode 100644 src/main/java/com/example/pssupporter/actions/MyRemoveAllTestAction.java delete mode 100644 src/main/java/com/example/pssupporter/ui/MyEditorPanel.java delete mode 100644 src/main/java/com/example/pssupporter/ui/MyMainView.java delete mode 100644 src/main/java/com/example/pssupporter/ui/MyTestListItem.java delete mode 100644 src/main/java/com/example/pssupporter/ui/MyTestListPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/Editor.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/EditorPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/MyEditorPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/function/InputEditorFunction.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/function/OutputEditorFunction.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/function/ResultEditorFunction.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/panel/InputEditorPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/panel/MyInputEditorPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/panel/MyOutputEditorPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/panel/MyResultEditorPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/panel/OutputEditorPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/editor/panel/ResultEditorPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/factory/JLabelFactory.java create mode 100644 src/main/java/com/example/pssupporter/ui/factory/JTitleBorderFactory.java rename src/main/java/com/example/pssupporter/ui/{ => list}/MyCellRenderer.java (96%) create mode 100644 src/main/java/com/example/pssupporter/ui/list/MySubTestList.java create mode 100644 src/main/java/com/example/pssupporter/ui/list/MyTestListItem.java create mode 100644 src/main/java/com/example/pssupporter/ui/list/MyTestListPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/list/TestList.java create mode 100644 src/main/java/com/example/pssupporter/ui/list/TestListPanel.java create mode 100644 src/main/java/com/example/pssupporter/ui/list/function/SubTestListFunction.java create mode 100644 src/main/java/com/example/pssupporter/ui/list/panel/SubTestList.java create mode 100644 src/main/java/com/example/pssupporter/ui/main/MyMainView.java create mode 100644 src/main/java/com/example/pssupporter/ui/toolbar/ActionToolbarPanel.java rename src/main/java/com/example/pssupporter/ui/{ => toolbar}/MyToolbarPanel.java (84%) create mode 100644 src/main/java/com/example/pssupporter/ui/toolbar/Toolbar.java rename src/main/java/com/example/pssupporter/utils/thread/{GlobalThreadStore.java => MyThreadStore.java} (91%) create mode 100644 src/test/java/com/example/pssupporter/actions/MyAddTestActionTest.java create mode 100644 src/test/java/com/example/pssupporter/actions/MyRemoveAllTestActionTest.java create mode 100644 src/test/java/com/example/pssupporter/actions/MyRemoveTestActionTest.java create mode 100644 src/test/java/com/example/pssupporter/actions/MyRunAllTestsActionTest.java create mode 100644 src/test/java/com/example/pssupporter/actions/MyRunTestActionTest.java create mode 100644 src/test/java/com/example/pssupporter/actions/MyStopAllTestsActionTest.java create mode 100644 src/test/java/com/example/pssupporter/ui/editor/EditorPanelTest.java create mode 100644 src/test/java/com/example/pssupporter/ui/factory/JLabelFactoryTest.java create mode 100644 src/test/java/com/example/pssupporter/ui/factory/JTitleBorderFactoryTest.java create mode 100644 src/test/java/com/example/pssupporter/ui/fake/FakeInputEditorPanel.java create mode 100644 src/test/java/com/example/pssupporter/ui/fake/FakeOutputEditorPanel.java create mode 100644 src/test/java/com/example/pssupporter/ui/fake/FakeResultEditorPanel.java create mode 100644 src/test/java/com/example/pssupporter/ui/fake/FakeSubTestList.java create mode 100644 src/test/java/com/example/pssupporter/ui/list/SubTestListTest.java create mode 100644 src/test/java/com/example/pssupporter/ui/list/TestListPanelTest.java create mode 100644 src/test/java/com/example/pssupporter/ui/main/MainPanelTest.java rename src/test/java/com/example/pssupporter/utils/{GlobalThreadStoreTest.java => MyThreadStoreTest.java} (70%) diff --git a/build.gradle.kts b/build.gradle.kts index c7bdcb2..67832fd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,61 +1,63 @@ plugins { - id("java") - id("org.jetbrains.kotlin.jvm") version "1.9.0" - id("org.jetbrains.intellij") version "1.15.0" + id("java") + id("org.jetbrains.kotlin.jvm") version "1.9.0" + id("org.jetbrains.intellij") version "1.15.0" } group = "com.example" version = "1.0.2" repositories { - mavenCentral() + mavenCentral() } // Configure Gradle IntelliJ Plugin // Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html intellij { - version.set("2022.2.5") - type.set("IC") // Target IDE Platform + version.set("2022.2.5") + type.set("IC") // Target IDE Platform - plugins.set(listOf("com.intellij.java","org.jetbrains.plugins.terminal")) + plugins.set(listOf("com.intellij.java", "org.jetbrains.plugins.terminal")) } -dependencies{ +dependencies { // implementation("junit:junit:4.13.2") // testImplementation("junit:junit:4.13.2") // testImplementation("org.mockito:mockito-core:3.4.6") // testImplementation("org.powermock:powermock-module-junit4:2.0.9") // testImplementation("org.powermock:powermock-api-mockito2:2.0.9") - testImplementation("org.mockito:mockito-junit-jupiter:5.8.0") - testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") - testImplementation("org.junit.jupiter:junit-jupiter-engine:5.8.2") + testImplementation("org.mockito:mockito-junit-jupiter:5.8.0") + testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.8.2") + // https://mvnrepository.com/artifact/org.mockito/mockito-inline + testImplementation("org.mockito:mockito-inline:5.2.0") } tasks { - // Set the JVM compatibility versions - withType { - sourceCompatibility = "17" - targetCompatibility = "17" - } - withType { - kotlinOptions.jvmTarget = "17" - } - - patchPluginXml { - sinceBuild.set("222") - untilBuild.set("232.*") - } - - signPlugin { - certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) - privateKey.set(System.getenv("PRIVATE_KEY")) - password.set(System.getenv("PRIVATE_KEY_PASSWORD")) - } - - publishPlugin { - token.set(System.getenv("PUBLISH_TOKEN")) - } - test { - useJUnitPlatform() - } + // Set the JVM compatibility versions + withType { + sourceCompatibility = "17" + targetCompatibility = "17" + } + withType { + kotlinOptions.jvmTarget = "17" + } + + patchPluginXml { + sinceBuild.set("222") + untilBuild.set("232.*") + } + + signPlugin { + certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) + privateKey.set(System.getenv("PRIVATE_KEY")) + password.set(System.getenv("PRIVATE_KEY_PASSWORD")) + } + + publishPlugin { + token.set(System.getenv("PUBLISH_TOKEN")) + } + test { + useJUnitPlatform() + } } diff --git a/src/main/java/com/example/pssupporter/MyToolWindowFactory.java b/src/main/java/com/example/pssupporter/MyToolWindowFactory.java index cc58f7a..9f1461c 100644 --- a/src/main/java/com/example/pssupporter/MyToolWindowFactory.java +++ b/src/main/java/com/example/pssupporter/MyToolWindowFactory.java @@ -4,7 +4,20 @@ package com.example.pssupporter; -import com.example.pssupporter.ui.MyMainView; +import com.example.pssupporter.actions.*; +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.editor.MyEditorPanel; +import com.example.pssupporter.ui.editor.panel.*; +import com.example.pssupporter.ui.list.MyCellRenderer; +import com.example.pssupporter.ui.list.MySubTestList; +import com.example.pssupporter.ui.list.MyTestListPanel; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.ui.main.MyMainView; +import com.example.pssupporter.ui.toolbar.MyToolbarPanel; +import com.example.pssupporter.utils.thread.MyThreadStore; +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.wm.ToolWindow; @@ -12,24 +25,82 @@ import com.intellij.openapi.wm.ToolWindowFactory; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.openapi.wm.ex.ToolWindowManagerListener; +import com.intellij.ui.components.JBPanel; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.ContentManager; import com.intellij.util.messages.MessageBusConnection; import org.jetbrains.annotations.NotNull; +import javax.swing.*; +import java.awt.*; + public class MyToolWindowFactory implements ToolWindowFactory { private MyMainView myMainView; + private TestListPanel myTestListPanel; + private EditorPanel myEditorPanel; + private MyToolbarPanel myToolbarPanel; + private MyThreadStore myThreadStore; + + private MyThreadStore createThreadStore() { + return new MyThreadStore(); + } + + private void createActionGroup() { + DefaultActionGroup myActionGroup = new DefaultActionGroup(); + myActionGroup.add(new MyLoadTestDataAction(myThreadStore)); + myActionGroup.add(new MyAddTestAction(myTestListPanel, myThreadStore)); + myActionGroup.add(new MyRemoveTestAction(myTestListPanel, myEditorPanel, myThreadStore)); + myActionGroup.add(new MyRemoveAllTestAction(myTestListPanel, myEditorPanel, myThreadStore)); + myActionGroup.add(new MyRunAllTestsAction(myTestListPanel, myEditorPanel, myMainView, myThreadStore)); + myActionGroup.add(new MyRunTestAction(myTestListPanel, myEditorPanel, myMainView, myThreadStore)); + myActionGroup.add(new MyStopAllTestsAction(myTestListPanel, myThreadStore)); + + ActionManager actionManager = ActionManager.getInstance(); + actionManager.registerAction("myActionGroup", myActionGroup); + } + + private ActionGroup getActionGroup(String actionGroupId) { + ActionManager actionManager = ActionManager.getInstance(); + return (ActionGroup) actionManager.getAction(actionGroupId); + } + + private MyToolbarPanel createToolbarPanel(JComponent targetComponent, String actionId) { + ActionGroup action = getActionGroup(actionId); + return new MyToolbarPanel(action, targetComponent); + } + + private TestListPanel createTestListPanel() { + MySubTestList mySubTestList = new MySubTestList(new MyCellRenderer()); + return new MyTestListPanel(mySubTestList, (e) -> myMainView.changeTestData()); + } + + private EditorPanel createEditorPanel() { + InputEditorPanel inputEditorPanel = new MyInputEditorPanel(); + OutputEditorPanel outputEditorPanel = new MyOutputEditorPanel(); + ResultEditorPanel resultEditorPanel = new MyResultEditorPanel(); + return new MyEditorPanel(inputEditorPanel, outputEditorPanel, resultEditorPanel); + } @Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { ApplicationManager.getApplication().invokeLater(() -> { - ContentManager contentManager = toolWindow.getContentManager(); - ContentFactory contentFactory = ContentFactory.getInstance(); + myTestListPanel = createTestListPanel(); + myEditorPanel = createEditorPanel(); + myMainView = new MyMainView(myTestListPanel, myEditorPanel, toolWindow.getAnchor().isHorizontal()); + + myThreadStore = createThreadStore(); + createActionGroup(); + myToolbarPanel = createToolbarPanel(myMainView, "myActionGroup"); + + JBPanel totalView = new JBPanel(new BorderLayout()); + totalView.add(myToolbarPanel, BorderLayout.NORTH); + totalView.add(myMainView, BorderLayout.CENTER); - myMainView = new MyMainView(project, toolWindow.getAnchor().isHorizontal()); + ContentFactory contentFactory = ContentFactory.getInstance(); + ContentManager contentManager = toolWindow.getContentManager(); - Content content = contentFactory.createContent(myMainView, "Supporter", false); + Content content = contentFactory.createContent(totalView, "Supporter", false); contentManager.addContent(content); setupToolWindowEventListener(project); diff --git a/src/main/java/com/example/pssupporter/actions/MyAddTestAction.java b/src/main/java/com/example/pssupporter/actions/MyAddTestAction.java index d9b4df8..02bd4e5 100644 --- a/src/main/java/com/example/pssupporter/actions/MyAddTestAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyAddTestAction.java @@ -4,26 +4,34 @@ package com.example.pssupporter.actions; -import com.example.pssupporter.ui.MyTestListPanel; -import com.example.pssupporter.utils.ComponentManager; -import com.example.pssupporter.utils.thread.GlobalThreadStore; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.utils.thread.MyThreadStore; import com.example.pssupporter.utils.thread.vo.ThreadGroupName; +import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import org.jetbrains.annotations.NotNull; public class MyAddTestAction extends AnAction { + private final TestListPanel myTestListPanel; + private final MyThreadStore myThreadStore; + + public MyAddTestAction(TestListPanel myTestListPanel, MyThreadStore myThreadStore) { + super("Add Test Data", "This action can add Test", AllIcons.General.Add); + this.myTestListPanel = myTestListPanel; + this.myThreadStore = myThreadStore; + } + @Override public void update(@NotNull AnActionEvent e) { super.update(e); - boolean isRunning = GlobalThreadStore.getInstance() + boolean isRunning = myThreadStore .hasRunningThreads(ThreadGroupName.TEST_RUNNING); e.getPresentation().setEnabled(!isRunning); } @Override public void actionPerformed(@NotNull AnActionEvent e) { - MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); - myTestListPanel.addTest(); + myTestListPanel.addTestData(); } } diff --git a/src/main/java/com/example/pssupporter/actions/MyLoadTestDataAction.java b/src/main/java/com/example/pssupporter/actions/MyLoadTestDataAction.java index d4e8eeb..aa3ce1f 100644 --- a/src/main/java/com/example/pssupporter/actions/MyLoadTestDataAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyLoadTestDataAction.java @@ -4,53 +4,32 @@ package com.example.pssupporter.actions; -import com.example.pssupporter.ui.MyTestListPanel; -import com.example.pssupporter.utils.ComponentManager; -import com.example.pssupporter.utils.StringUtils; -import com.example.pssupporter.utils.crawling.CrawlerProvider; -import com.example.pssupporter.utils.crawling.vo.Site; -import com.example.pssupporter.utils.thread.GlobalThreadStore; +import com.example.pssupporter.utils.thread.MyThreadStore; import com.example.pssupporter.utils.thread.vo.ThreadGroupName; -import com.example.pssupporter.vo.TestData; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.ui.Messages; import org.jetbrains.annotations.NotNull; -import java.util.List; - public class MyLoadTestDataAction extends AnAction { + private final MyThreadStore myThreadStore; + + public MyLoadTestDataAction(MyThreadStore myThreadStore) { + super("Load Test DataSets", "This action can load test data sets", AllIcons.Actions.Find); + this.myThreadStore = myThreadStore; + } + @Override public void update(@NotNull AnActionEvent e) { super.update(e); - boolean isRunning = GlobalThreadStore.getInstance() + boolean isRunning = myThreadStore .hasRunningThreads(ThreadGroupName.TEST_RUNNING); e.getPresentation().setEnabled(!isRunning); } @Override public void actionPerformed(@NotNull AnActionEvent e) { - Messages.showMessageDialog("Currently, this feature is not available because Baekjun has banned scraping.\nReference : BOJ Homepage","Caution", AllIcons.Actions.Exit); - return; -// MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); -// String selected = Messages.showInputDialog(e.getProject(), "Input Baekjoon number", "Load Test Data", null); -// if (!StringUtils.isBlank(selected)) { -// ComponentManager.getInstance().removeChildrenComponentsByName("myEditorPanel"); -// -// try { -// long number = Long.parseLong(selected); -// List examples = CrawlerProvider.getCrawler(Site.BAEKJOON_OJ).getExamples(number); -// -// myTestListPanel.removeAllTests(); -// -// for (TestData testData : examples) { -// myTestListPanel.addTest(testData); -// } -// -// } catch (NumberFormatException ne) { -// Messages.showMessageDialog(e.getProject(), "Input number!", "Load Test Error", null); -// } -// } + Messages.showMessageDialog("Currently, this feature is not available because Baekjun has banned scraping.\nReference : BOJ Homepage", "Caution", AllIcons.Actions.Exit); } } diff --git a/src/main/java/com/example/pssupporter/actions/MyRemoveAllTestAction.java b/src/main/java/com/example/pssupporter/actions/MyRemoveAllTestAction.java new file mode 100644 index 0000000..75db1fa --- /dev/null +++ b/src/main/java/com/example/pssupporter/actions/MyRemoveAllTestAction.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.actions; + +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.utils.thread.MyThreadStore; +import com.example.pssupporter.utils.thread.vo.ThreadGroupName; +import com.intellij.icons.AllIcons; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import org.jetbrains.annotations.NotNull; + +public class MyRemoveAllTestAction extends AnAction { + private final TestListPanel myTestListPanel; + private final EditorPanel myEditorPanel; + private final MyThreadStore myThreadStore; + + public MyRemoveAllTestAction(TestListPanel myTestListPanel, EditorPanel myEditorPanel, MyThreadStore myThreadStore) { + super("Remove All Test DataSets", "This action can remove all test data sets", AllIcons.Actions.GC); + this.myTestListPanel = myTestListPanel; + this.myEditorPanel = myEditorPanel; + this.myThreadStore = myThreadStore; + } + + @Override + public void update(@NotNull AnActionEvent e) { + super.update(e); + boolean isRunning = myThreadStore + .hasRunningThreads(ThreadGroupName.TEST_RUNNING); + e.getPresentation().setEnabled(!isRunning); + } + + @Override + public void actionPerformed(@NotNull AnActionEvent e) { + myEditorPanel.clearAll(); + myTestListPanel.removeAllTestDatas(); + } +} diff --git a/src/main/java/com/example/pssupporter/actions/MyRemoveTestAction.java b/src/main/java/com/example/pssupporter/actions/MyRemoveTestAction.java index b9d3b9f..5d0dbaf 100644 --- a/src/main/java/com/example/pssupporter/actions/MyRemoveTestAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyRemoveTestAction.java @@ -4,32 +4,41 @@ package com.example.pssupporter.actions; -import com.example.pssupporter.ui.MyTestListPanel; -import com.example.pssupporter.utils.ComponentManager; -import com.example.pssupporter.utils.thread.GlobalThreadStore; +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.utils.thread.MyThreadStore; import com.example.pssupporter.utils.thread.vo.ThreadGroupName; +import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import org.jetbrains.annotations.NotNull; public class MyRemoveTestAction extends AnAction { + private final TestListPanel myTestListPanel; + private final EditorPanel myEditorPanel; + private final MyThreadStore myThreadStore; + + public MyRemoveTestAction(TestListPanel myTestListPanel, EditorPanel myEditorPanel, MyThreadStore myThreadStore) { + super("Remove Test Data Set", "This action can remove test data set", AllIcons.General.Remove); + this.myTestListPanel = myTestListPanel; + this.myEditorPanel = myEditorPanel; + this.myThreadStore = myThreadStore; + } + @Override public void update(@NotNull AnActionEvent e) { super.update(e); - boolean isRunning = GlobalThreadStore.getInstance() + boolean isRunning = myThreadStore .hasRunningThreads(ThreadGroupName.TEST_RUNNING); e.getPresentation().setEnabled(!isRunning); } @Override public void actionPerformed(@NotNull AnActionEvent e) { - MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); int selectedIndex = myTestListPanel.getSelectedIndex(); if (selectedIndex != -1) { - ComponentManager.getInstance().removeChildrenComponentsByName("myEditorPanel"); - - myTestListPanel.removeTest(selectedIndex); - myTestListPanel.repaint(); + myEditorPanel.clearAll(); + myTestListPanel.removeTestData(selectedIndex); } } } diff --git a/src/main/java/com/example/pssupporter/actions/MyRunAllTestsAction.java b/src/main/java/com/example/pssupporter/actions/MyRunAllTestsAction.java index 1fd5529..a6b0aed 100644 --- a/src/main/java/com/example/pssupporter/actions/MyRunAllTestsAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyRunAllTestsAction.java @@ -4,14 +4,15 @@ package com.example.pssupporter.actions; -import com.example.pssupporter.ui.MyTestListItem; -import com.example.pssupporter.ui.MyTestListPanel; -import com.example.pssupporter.utils.ComponentManager; +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.list.MyTestListItem; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.ui.main.MyMainView; import com.example.pssupporter.utils.IntellijUtils; import com.example.pssupporter.utils.runner.CodeRunner; import com.example.pssupporter.utils.runner.CodeRunnerProvider; import com.example.pssupporter.utils.runner.vo.CodeLanguage; -import com.example.pssupporter.utils.thread.GlobalThreadStore; +import com.example.pssupporter.utils.thread.MyThreadStore; import com.example.pssupporter.utils.thread.TestRunningThread; import com.example.pssupporter.utils.thread.vo.ThreadGroupName; import com.intellij.icons.AllIcons; @@ -24,21 +25,33 @@ import java.util.Objects; public class MyRunAllTestsAction extends AnAction { + private final TestListPanel myTestListPanel; + private final EditorPanel myEditorPanel; + private final MyMainView myMainView; + private final MyThreadStore myThreadStore; + + public MyRunAllTestsAction(TestListPanel myTestListPanel, EditorPanel myEditorPanel, MyMainView myMainView, MyThreadStore myThreadStore) { + super("Run All Tests", "This action can run all tests", AllIcons.Actions.RunAll); + this.myTestListPanel = myTestListPanel; + this.myEditorPanel = myEditorPanel; + this.myMainView = myMainView; + this.myThreadStore = myThreadStore; + } + @Override public void update(@NotNull AnActionEvent e) { super.update(e); - boolean isRunning = GlobalThreadStore.getInstance() + boolean isRunning = myThreadStore .hasRunningThreads(ThreadGroupName.TEST_RUNNING); e.getPresentation().setEnabled(!isRunning); - MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); myTestListPanel.setEnabled(!isRunning); } @Override public void actionPerformed(@NotNull AnActionEvent e) { - ComponentManager.getInstance().removeChildrenComponentsByName("myEditorPanel"); - MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); + myMainView.saveAndClear(); myTestListPanel.clearSelection(); + myEditorPanel.clearAll(); List myTestListItems = myTestListPanel.getMyTestListItems(); IntellijUtils.getSelectedFile(Objects.requireNonNull(e.getProject())) @@ -50,7 +63,7 @@ public void actionPerformed(@NotNull AnActionEvent e) { TestRunningThread[] testRunningThreads = myTestListItems.stream() .map(item -> new TestRunningThread(path, codeRunner, item)) .toArray(TestRunningThread[]::new); - GlobalThreadStore.getInstance().executeThreads(ThreadGroupName.TEST_RUNNING, testRunningThreads); + myThreadStore.executeThreads(ThreadGroupName.TEST_RUNNING, testRunningThreads); }, () -> Messages.showMessageDialog("No selected file", "Run All Tests", AllIcons.Actions.Exit)); } } diff --git a/src/main/java/com/example/pssupporter/actions/MyRunTestAction.java b/src/main/java/com/example/pssupporter/actions/MyRunTestAction.java index dea69c6..1bc277d 100644 --- a/src/main/java/com/example/pssupporter/actions/MyRunTestAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyRunTestAction.java @@ -4,14 +4,15 @@ package com.example.pssupporter.actions; -import com.example.pssupporter.ui.MyTestListItem; -import com.example.pssupporter.ui.MyTestListPanel; -import com.example.pssupporter.utils.ComponentManager; +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.list.MyTestListItem; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.ui.main.MyMainView; import com.example.pssupporter.utils.IntellijUtils; import com.example.pssupporter.utils.runner.CodeRunner; import com.example.pssupporter.utils.runner.CodeRunnerProvider; import com.example.pssupporter.utils.runner.vo.CodeLanguage; -import com.example.pssupporter.utils.thread.GlobalThreadStore; +import com.example.pssupporter.utils.thread.MyThreadStore; import com.example.pssupporter.utils.thread.TestRunningThread; import com.example.pssupporter.utils.thread.vo.ThreadGroupName; import com.intellij.icons.AllIcons; @@ -23,28 +24,42 @@ import java.util.Objects; public class MyRunTestAction extends AnAction { + private final TestListPanel myTestListPanel; + private final EditorPanel myEditorPanel; + private final MyMainView myMainView; + private final MyThreadStore myThreadStore; + + public MyRunTestAction(TestListPanel myTestListPanel, EditorPanel myEditorPanel, MyMainView myMainView, MyThreadStore myThreadStore) { + super("Run Test", "This action can run selected test", AllIcons.Actions.Execute); + this.myTestListPanel = myTestListPanel; + this.myEditorPanel = myEditorPanel; + this.myMainView = myMainView; + this.myThreadStore = myThreadStore; + } + @Override public void update(@NotNull AnActionEvent e) { super.update(e); - boolean isRunning = GlobalThreadStore.getInstance() + boolean isRunning = myThreadStore .hasRunningThreads(ThreadGroupName.TEST_RUNNING); e.getPresentation().setEnabled(!isRunning); - MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); myTestListPanel.setEnabled(!isRunning); } @Override public void actionPerformed(@NotNull AnActionEvent e) { - MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); int selectedIndex = myTestListPanel.getSelectedIndex(); if (selectedIndex == -1) { return; } - ComponentManager.getInstance().removeChildrenComponentsByName("myEditorPanel"); + + myMainView.saveAndClear(); + + myEditorPanel.clearAll(); myTestListPanel.clearSelection(); - MyTestListItem selectedItem = myTestListPanel.getMyTestListItem(selectedIndex); + MyTestListItem selectedItem = myTestListPanel.getMyTestList(selectedIndex); IntellijUtils.getSelectedFile(Objects.requireNonNull(e.getProject())) .ifPresentOrElse(selectedFile -> { IntellijUtils.autoSaveFile(selectedFile); @@ -52,7 +67,7 @@ public void actionPerformed(@NotNull AnActionEvent e) { String path = selectedFile.getPath(); CodeRunner codeRunner = CodeRunnerProvider.getCodeRunner(CodeLanguage.JAVA); TestRunningThread testRunningThread = new TestRunningThread(path, codeRunner, selectedItem); - GlobalThreadStore.getInstance().executeThreads(ThreadGroupName.TEST_RUNNING, testRunningThread); + myThreadStore.executeThreads(ThreadGroupName.TEST_RUNNING, testRunningThread); } , () -> Messages.showMessageDialog("No selected file", "Run Test", AllIcons.Actions.Exit)); } diff --git a/src/main/java/com/example/pssupporter/actions/MyStopAllTestsAction.java b/src/main/java/com/example/pssupporter/actions/MyStopAllTestsAction.java index cff40d8..f64d600 100644 --- a/src/main/java/com/example/pssupporter/actions/MyStopAllTestsAction.java +++ b/src/main/java/com/example/pssupporter/actions/MyStopAllTestsAction.java @@ -4,29 +4,37 @@ package com.example.pssupporter.actions; -import com.example.pssupporter.ui.MyTestListPanel; -import com.example.pssupporter.utils.ComponentManager; -import com.example.pssupporter.utils.thread.GlobalThreadStore; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.utils.thread.MyThreadStore; import com.example.pssupporter.utils.thread.vo.ThreadGroupName; +import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import org.jetbrains.annotations.NotNull; public class MyStopAllTestsAction extends AnAction { + private final TestListPanel myTestListPanel; + private final MyThreadStore myThreadStore; + + public MyStopAllTestsAction(TestListPanel myTestListPanel, MyThreadStore myThreadStore) { + super("Stop All Running Tests", "This action can stop all tests", AllIcons.Actions.Suspend); + this.myTestListPanel = myTestListPanel; + this.myThreadStore = myThreadStore; + } + @Override public void update(@NotNull AnActionEvent e) { super.update(e); - boolean isRunning = GlobalThreadStore.getInstance() + boolean isRunning = myThreadStore .hasRunningThreads(ThreadGroupName.TEST_RUNNING); e.getPresentation().setEnabled(isRunning); - MyTestListPanel myTestListPanel = ComponentManager.getInstance().getComponent("myTestListPanel", MyTestListPanel.class); myTestListPanel.setEnabled(!isRunning); } @Override public void actionPerformed(AnActionEvent e) { - GlobalThreadStore.getInstance() + myThreadStore .interruptThreads(ThreadGroupName.TEST_RUNNING); } } diff --git a/src/main/java/com/example/pssupporter/ui/MyEditorPanel.java b/src/main/java/com/example/pssupporter/ui/MyEditorPanel.java deleted file mode 100644 index 060b67b..0000000 --- a/src/main/java/com/example/pssupporter/ui/MyEditorPanel.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package com.example.pssupporter.ui; - - -import com.example.pssupporter.vo.TestData; -import com.intellij.execution.filters.TextConsoleBuilderFactory; -import com.intellij.execution.ui.ConsoleView; -import com.intellij.execution.ui.ConsoleViewContentType; -import com.intellij.openapi.project.Project; -import com.intellij.ui.JBColor; -import com.intellij.ui.components.JBPanel; -import com.intellij.ui.components.JBScrollPane; -import com.intellij.ui.components.JBTextArea; - -import javax.swing.*; -import java.awt.*; - -public class MyEditorPanel extends JBPanel { - - private final JBTextArea myInputTextArea; - private final JBTextArea myOutputTextArea; - private final ConsoleView myLogConsoleView; - private final Project project; - private final TestData myTestData; - - public MyEditorPanel(Project project) { - this(project, new TestData()); - } - - public MyEditorPanel(Project project, TestData myTestData) { - this.myTestData = myTestData; - this.setName("MyLogPanel"); - this.setLayout(new BorderLayout()); - this.setBorder(BorderFactory.createLineBorder(JBColor.DARK_GRAY)); - this.project = project; - - JBPanel inputOutputPanel = new JBPanel(new GridLayout(1, 2)); - - myInputTextArea = new JBTextArea(); - myInputTextArea.setText(myTestData.getInput()); - - JBScrollPane myInputTextScrollPane = new JBScrollPane(myInputTextArea); - myInputTextScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(JBColor.DARK_GRAY), "Input")); - myInputTextScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - myInputTextScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - - myOutputTextArea = new JBTextArea(); - myOutputTextArea.setText(myTestData.getOutput()); - - JBScrollPane myOutputTextScrollPane = new JBScrollPane(myOutputTextArea); - myOutputTextScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(JBColor.DARK_GRAY), "Output")); - myOutputTextScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - myOutputTextScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - - myLogConsoleView = createConsoleView(); - - setBorder(BorderFactory.createLineBorder(JBColor.LIGHT_GRAY)); - JBScrollPane myLogScrollPane = new JBScrollPane(myLogConsoleView.getComponent()); - myLogScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(JBColor.DARK_GRAY), "Result")); - myLogScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - myLogScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - - inputOutputPanel.add(myInputTextScrollPane); - inputOutputPanel.add(myOutputTextScrollPane); - - this.add(inputOutputPanel, BorderLayout.NORTH); - this.add(myLogScrollPane, BorderLayout.SOUTH); - - // JSplitPane - JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, inputOutputPanel, myLogScrollPane); - splitPane.setDividerSize(1); - splitPane.setResizeWeight(0.3); - add(splitPane, BorderLayout.CENTER); - } - - public TestData getTestData() { - myTestData.setInput(myInputTextArea.getText()); - myTestData.setOutput(myOutputTextArea.getText()); - return myTestData; - } - - public void setResult(String result) { - myLogConsoleView.clear(); - myLogConsoleView.print(result, ConsoleViewContentType.SYSTEM_OUTPUT); - } - - private ConsoleView createConsoleView() { - return TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); - } -} diff --git a/src/main/java/com/example/pssupporter/ui/MyMainView.java b/src/main/java/com/example/pssupporter/ui/MyMainView.java deleted file mode 100644 index b16337e..0000000 --- a/src/main/java/com/example/pssupporter/ui/MyMainView.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package com.example.pssupporter.ui; - -import com.example.pssupporter.utils.ComponentManager; -import com.intellij.openapi.actionSystem.ActionGroup; -import com.intellij.openapi.project.Project; -import com.intellij.ui.components.JBPanel; -import com.intellij.ui.components.JBScrollPane; - -import javax.swing.*; -import java.awt.*; - -public class MyMainView extends JBPanel { - private Project myProject; - private boolean myHorizontal; - private JBPanel myTestPanel; - private MyTestListPanel myTestListPanel; - private JBScrollPane myTestListScrollPane; - private JBPanel myEditorPanel; - - - public MyMainView(Project project, boolean horizontal) { - super(new BorderLayout()); - this.myProject = project; - this.myHorizontal = horizontal; - - setupActionToolbarPanel(); - setupTestListPanel(); - setupEditorPanel(); - setupTestPanel(); - addComponentsToManager(); - } - - /** - * add component in component manager - */ - private void addComponentsToManager() { - ComponentManager.getInstance().addComponent("myTestListPanel", myTestListPanel); - ComponentManager.getInstance().addComponent("myEditorPanel", myEditorPanel); - } - - /** - * implements test panel that includes testList and editor panel. - */ - private void setupTestPanel() { - myTestPanel = new JBPanel(new BorderLayout()); - this.setLayoutBasedOnOrientation(this.myHorizontal, true); - this.add(myTestPanel, BorderLayout.CENTER); - } - - /** - * implements editor panel - */ - private void setupEditorPanel() { - myEditorPanel = new JBPanel(new GridLayout(1, 1)); - } - - /** - * implement test list panel - */ - private void setupTestListPanel() { - myTestListPanel = new MyTestListPanel(this.myProject); - myTestListScrollPane = new JBScrollPane(myTestListPanel); - myTestListScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); - myTestListScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); - } - - /** - * implement action panel - */ - private void setupActionToolbarPanel() { - ActionGroup myActionGroup = getActionGroup("myActionGroup"); - MyToolbarPanel myActionToolbarPanel = new MyToolbarPanel(myActionGroup, this); - - this.add(myActionToolbarPanel, BorderLayout.NORTH); - } - - private ActionGroup getActionGroup(String actionGroupId) { - com.intellij.openapi.actionSystem.ActionManager actionManager = com.intellij.openapi.actionSystem.ActionManager.getInstance(); - return (ActionGroup) actionManager.getAction(actionGroupId); - } - - public void setLayoutBasedOnOrientation(boolean horizontal) { - setLayoutBasedOnOrientation(horizontal, false); - } - - private void setLayoutBasedOnOrientation(boolean horizontal, boolean init) { - if (init || this.myHorizontal != horizontal) { - if (horizontal) { - setHorizontalLayout(); - } else { - setVerticalLayout(); - } - this.myHorizontal = horizontal; - } - } - - private void setHorizontalLayout() { - myTestPanel.add(myTestListScrollPane, BorderLayout.WEST); - myTestPanel.add(myEditorPanel, BorderLayout.CENTER); - } - - private void setVerticalLayout() { - myTestPanel.add(myTestListScrollPane, BorderLayout.NORTH); - myTestPanel.add(myEditorPanel, BorderLayout.CENTER); - } -} diff --git a/src/main/java/com/example/pssupporter/ui/MyTestListItem.java b/src/main/java/com/example/pssupporter/ui/MyTestListItem.java deleted file mode 100644 index f53e07f..0000000 --- a/src/main/java/com/example/pssupporter/ui/MyTestListItem.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package com.example.pssupporter.ui; - -import com.example.pssupporter.vo.TestStatus; - -public class MyTestListItem { - private final MyEditorPanel myEditorPanel; - private TestStatus myStatus; - - public MyTestListItem(MyEditorPanel myEditorPanel) { - this(myEditorPanel, TestStatus.READY); - } - - public MyTestListItem(MyEditorPanel myEditorPanel, TestStatus myStatus) { - this.myEditorPanel = myEditorPanel; - this.myStatus = myStatus; - } - - public MyEditorPanel getMyEditorPanel() { - return myEditorPanel; - } - - public TestStatus getStatus() { - return myStatus; - } - - public void setStatus(TestStatus myStatus) { - this.myStatus = myStatus; - } -} diff --git a/src/main/java/com/example/pssupporter/ui/MyTestListPanel.java b/src/main/java/com/example/pssupporter/ui/MyTestListPanel.java deleted file mode 100644 index b13aa52..0000000 --- a/src/main/java/com/example/pssupporter/ui/MyTestListPanel.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package com.example.pssupporter.ui; - -import com.example.pssupporter.utils.ComponentManager; -import com.example.pssupporter.vo.TestData; -import com.intellij.openapi.project.Project; -import com.intellij.ui.components.JBList; -import com.intellij.ui.components.JBPanel; - -import javax.swing.*; -import java.util.ArrayList; -import java.util.List; - -public class MyTestListPanel extends JBList { - - private DefaultListModel myModel; - private Project myProject; - - protected MyTestListPanel(Project project) { - this.myProject = project; - myModel = new DefaultListModel<>(); - setCellRenderer(new MyCellRenderer()); - - this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - addListSelectionListener((e) -> { - int selectedIndex = this.getSelectedIndex(); - - if (selectedIndex == -1) { - return; - } - MyTestListItem selectedItem = myModel.getElementAt(selectedIndex); - - JBPanel myEditorPanel = (JBPanel) ComponentManager.getInstance().getComponent("myEditorPanel"); - - ComponentManager.getInstance().removeChildrenComponents(myEditorPanel); - - myEditorPanel.add(selectedItem.getMyEditorPanel()); - myEditorPanel.repaint(); - }); - - this.setModel(myModel); - } - - public void addTest() { - myModel.addElement(new MyTestListItem(new MyEditorPanel(this.myProject))); - } - - public void addTest(TestData testData) { - myModel.addElement(new MyTestListItem(new MyEditorPanel(this.myProject, testData))); - } - - public void removeTest(int index) { - myModel.removeElementAt(index); - } - - public void removeAllTests() { - myModel.removeAllElements(); - } - - public List getMyTestListItems() { - List result = new ArrayList<>(myModel.size()); - for (int i = 0; i < myModel.size(); i++) { - result.add(myModel.getElementAt(i)); - } - - return result; - } - - public MyTestListItem getMyTestListItem(int selectedIndex) { - return myModel.getElementAt(selectedIndex); - } -} diff --git a/src/main/java/com/example/pssupporter/ui/editor/Editor.java b/src/main/java/com/example/pssupporter/ui/editor/Editor.java new file mode 100644 index 0000000..6bb674c --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/Editor.java @@ -0,0 +1,15 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor; + +public interface Editor { + String getInput(); + String getOutput(); + void setInput(String input); + void setOutput(String output); + void setResult(String result); + String getResult(); + void clearAll(); +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/EditorPanel.java b/src/main/java/com/example/pssupporter/ui/editor/EditorPanel.java new file mode 100644 index 0000000..3ce53e8 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/EditorPanel.java @@ -0,0 +1,11 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor; + +import com.intellij.ui.components.JBPanel; + +public abstract class EditorPanel extends JBPanel implements Editor{ + +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/MyEditorPanel.java b/src/main/java/com/example/pssupporter/ui/editor/MyEditorPanel.java new file mode 100644 index 0000000..d58c49f --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/MyEditorPanel.java @@ -0,0 +1,103 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor; + + +import com.example.pssupporter.ui.editor.panel.InputEditorPanel; +import com.example.pssupporter.ui.editor.panel.OutputEditorPanel; +import com.example.pssupporter.ui.editor.panel.ResultEditorPanel; +import com.example.pssupporter.ui.factory.JTitleBorderFactory; +import com.intellij.ui.JBColor; +import com.intellij.ui.components.JBPanel; +import com.intellij.ui.components.JBScrollPane; + +import javax.swing.*; +import javax.swing.border.Border; +import java.awt.*; + +public class MyEditorPanel extends EditorPanel { + + private final InputEditorPanel myInputEditorPanel; + private final OutputEditorPanel myOutputEditorPanel; + private final ResultEditorPanel myResultEditorPanel; + + public MyEditorPanel(InputEditorPanel inputEditorPanel, OutputEditorPanel outputEditorPanel, ResultEditorPanel resultEditorPanel) { + this.setLayout(new BorderLayout()); + this.setBorder(BorderFactory.createLineBorder(JBColor.DARK_GRAY)); + myInputEditorPanel = inputEditorPanel; + myOutputEditorPanel = outputEditorPanel; + myResultEditorPanel = resultEditorPanel; + + JBPanel inputOutputPanel = new JBPanel(new GridLayout(1, 2)); + + JBScrollPane myInputTextScrollPane = new JBScrollPane(myInputEditorPanel); + Border inputBorder = JTitleBorderFactory.getBorder("Input"); + myInputTextScrollPane.setBorder(inputBorder); + myInputTextScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + myInputTextScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + + JBScrollPane myOutputTextScrollPane = new JBScrollPane(myOutputEditorPanel); + Border outputBorder = JTitleBorderFactory.getBorder("Output"); + myOutputTextScrollPane.setBorder(outputBorder); + myOutputTextScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + myOutputTextScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + + setBorder(BorderFactory.createLineBorder(JBColor.LIGHT_GRAY)); + JBScrollPane myLogScrollPane = new JBScrollPane(myResultEditorPanel); + Border resultBorder = JTitleBorderFactory.getBorder("Result"); + myLogScrollPane.setBorder(resultBorder); + myLogScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + myLogScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + + inputOutputPanel.add(myInputTextScrollPane); + inputOutputPanel.add(myOutputTextScrollPane); + + this.add(inputOutputPanel, BorderLayout.NORTH); + this.add(myLogScrollPane, BorderLayout.SOUTH); + + // JSplitPane + JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, inputOutputPanel, myLogScrollPane); + splitPane.setDividerSize(1); + splitPane.setResizeWeight(0.3); + add(splitPane, BorderLayout.CENTER); + } + + @Override + public void clearAll() { + myInputEditorPanel.setInput(""); + myOutputEditorPanel.setOutput(""); + myResultEditorPanel.setResult(""); + } + + @Override + public String getInput() { + return myInputEditorPanel.getInput(); + } + + @Override + public String getOutput() { + return myOutputEditorPanel.getOutput(); + } + + @Override + public void setInput(String input) { + myInputEditorPanel.setInput(input); + } + + @Override + public void setOutput(String output) { + myOutputEditorPanel.setOutput(output); + } + + @Override + public void setResult(String result) { + myResultEditorPanel.setResult(result); + } + + @Override + public String getResult() { + return myResultEditorPanel.getResult(); + } +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/function/InputEditorFunction.java b/src/main/java/com/example/pssupporter/ui/editor/function/InputEditorFunction.java new file mode 100644 index 0000000..8348ea7 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/function/InputEditorFunction.java @@ -0,0 +1,10 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor.function; + +public interface InputEditorFunction { + void setInput(String input); + String getInput(); +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/function/OutputEditorFunction.java b/src/main/java/com/example/pssupporter/ui/editor/function/OutputEditorFunction.java new file mode 100644 index 0000000..46088de --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/function/OutputEditorFunction.java @@ -0,0 +1,10 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor.function; + +public interface OutputEditorFunction { + void setOutput(String output); + String getOutput(); +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/function/ResultEditorFunction.java b/src/main/java/com/example/pssupporter/ui/editor/function/ResultEditorFunction.java new file mode 100644 index 0000000..c8782ac --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/function/ResultEditorFunction.java @@ -0,0 +1,10 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor.function; + +public interface ResultEditorFunction { + void setResult(String result); + String getResult(); +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/panel/InputEditorPanel.java b/src/main/java/com/example/pssupporter/ui/editor/panel/InputEditorPanel.java new file mode 100644 index 0000000..6574444 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/panel/InputEditorPanel.java @@ -0,0 +1,11 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor.panel; + +import com.example.pssupporter.ui.editor.function.InputEditorFunction; +import com.intellij.ui.components.JBPanel; + +public abstract class InputEditorPanel extends JBPanel implements InputEditorFunction { +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/panel/MyInputEditorPanel.java b/src/main/java/com/example/pssupporter/ui/editor/panel/MyInputEditorPanel.java new file mode 100644 index 0000000..d3b8253 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/panel/MyInputEditorPanel.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor.panel; + +import com.example.pssupporter.ui.editor.function.InputEditorFunction; +import com.intellij.ui.components.JBTextArea; + +import java.awt.*; + +public class MyInputEditorPanel extends InputEditorPanel implements InputEditorFunction { + private final JBTextArea myInputTextArea; + + public MyInputEditorPanel() { + this.setLayout(new BorderLayout()); + myInputTextArea = new JBTextArea(); + this.add(myInputTextArea, BorderLayout.CENTER); + } + + @Override + public void setInput(String input) { + myInputTextArea.setText(input); + } + + @Override + public String getInput() { + return myInputTextArea.getText(); + } +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/panel/MyOutputEditorPanel.java b/src/main/java/com/example/pssupporter/ui/editor/panel/MyOutputEditorPanel.java new file mode 100644 index 0000000..5ea1360 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/panel/MyOutputEditorPanel.java @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor.panel; + +import com.example.pssupporter.ui.editor.function.OutputEditorFunction; +import com.intellij.ui.components.JBTextArea; + +import java.awt.*; + +public class MyOutputEditorPanel extends OutputEditorPanel implements OutputEditorFunction { + private final JBTextArea myOutputTextArea; + + public MyOutputEditorPanel() { + this.setLayout(new BorderLayout()); + myOutputTextArea = new JBTextArea(); + this.add(myOutputTextArea, BorderLayout.CENTER); + } + + @Override + public void setOutput(String output) { + myOutputTextArea.setText(output); + } + + @Override + public String getOutput() { + return myOutputTextArea.getText(); + } +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/panel/MyResultEditorPanel.java b/src/main/java/com/example/pssupporter/ui/editor/panel/MyResultEditorPanel.java new file mode 100644 index 0000000..4298596 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/panel/MyResultEditorPanel.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor.panel; + +import com.intellij.execution.filters.TextConsoleBuilderFactory; +import com.intellij.execution.ui.ConsoleView; +import com.intellij.execution.ui.ConsoleViewContentType; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ProjectManager; + +import java.awt.*; + +public class MyResultEditorPanel extends ResultEditorPanel { + private String myResult; + private final ConsoleView myResultConsoleView; + + public MyResultEditorPanel() { + this.myResult = null; + this.myResultConsoleView = createConsoleView(); + this.setLayout(new BorderLayout()); + this.add(myResultConsoleView.getComponent(), BorderLayout.CENTER); + } + + private ConsoleView createConsoleView() { + Project project = ProjectManager.getInstance().getDefaultProject(); + return TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole(); + } + + @Override + public void setResult(String result) { + this.myResult = result; + this.myResultConsoleView.clear(); + this.myResultConsoleView.print(result, ConsoleViewContentType.SYSTEM_OUTPUT); + } + + @Override + public String getResult() { + return this.myResult; + } +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/panel/OutputEditorPanel.java b/src/main/java/com/example/pssupporter/ui/editor/panel/OutputEditorPanel.java new file mode 100644 index 0000000..72e957f --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/panel/OutputEditorPanel.java @@ -0,0 +1,11 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor.panel; + +import com.example.pssupporter.ui.editor.function.OutputEditorFunction; +import com.intellij.ui.components.JBPanel; + +public abstract class OutputEditorPanel extends JBPanel implements OutputEditorFunction { +} diff --git a/src/main/java/com/example/pssupporter/ui/editor/panel/ResultEditorPanel.java b/src/main/java/com/example/pssupporter/ui/editor/panel/ResultEditorPanel.java new file mode 100644 index 0000000..958d808 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/editor/panel/ResultEditorPanel.java @@ -0,0 +1,11 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor.panel; + +import com.example.pssupporter.ui.editor.function.ResultEditorFunction; +import com.intellij.ui.components.JBPanel; + +public abstract class ResultEditorPanel extends JBPanel implements ResultEditorFunction { +} diff --git a/src/main/java/com/example/pssupporter/ui/factory/JLabelFactory.java b/src/main/java/com/example/pssupporter/ui/factory/JLabelFactory.java new file mode 100644 index 0000000..df747a6 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/factory/JLabelFactory.java @@ -0,0 +1,21 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.factory; + + +import javax.swing.*; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class JLabelFactory { + private static final Map ourLabelsWithText = new ConcurrentHashMap<>(); + + private JLabelFactory() { + } + + public static JLabel getJLabel(String text) { + return ourLabelsWithText.computeIfAbsent(text, JLabel::new); + } +} diff --git a/src/main/java/com/example/pssupporter/ui/factory/JTitleBorderFactory.java b/src/main/java/com/example/pssupporter/ui/factory/JTitleBorderFactory.java new file mode 100644 index 0000000..fb81525 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/factory/JTitleBorderFactory.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.factory; + +import com.intellij.ui.JBColor; + +import javax.swing.*; +import javax.swing.border.Border; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class JTitleBorderFactory { + private static final Map ourBordersWithTitle = new ConcurrentHashMap<>(); + + private JTitleBorderFactory() { + } + + public static Border getBorder(String title) { + return ourBordersWithTitle.computeIfAbsent(title, t -> BorderFactory.createTitledBorder(BorderFactory.createLineBorder(JBColor.DARK_GRAY), title)); + } +} diff --git a/src/main/java/com/example/pssupporter/ui/MyCellRenderer.java b/src/main/java/com/example/pssupporter/ui/list/MyCellRenderer.java similarity index 96% rename from src/main/java/com/example/pssupporter/ui/MyCellRenderer.java rename to src/main/java/com/example/pssupporter/ui/list/MyCellRenderer.java index 7bd44c3..333478c 100644 --- a/src/main/java/com/example/pssupporter/ui/MyCellRenderer.java +++ b/src/main/java/com/example/pssupporter/ui/list/MyCellRenderer.java @@ -2,7 +2,7 @@ * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. */ -package com.example.pssupporter.ui; +package com.example.pssupporter.ui.list; import com.intellij.icons.AllIcons; diff --git a/src/main/java/com/example/pssupporter/ui/list/MySubTestList.java b/src/main/java/com/example/pssupporter/ui/list/MySubTestList.java new file mode 100644 index 0000000..796970a --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/list/MySubTestList.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.list; + +import com.example.pssupporter.ui.list.panel.SubTestList; +import com.example.pssupporter.vo.TestData; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +public class MySubTestList extends SubTestList { + private DefaultListModel myModel; + + public MySubTestList(ListCellRenderer cellRenderer) { + this.setCellRenderer(cellRenderer); + myModel = new DefaultListModel<>(); + + this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + this.setModel(myModel); + } + + public void addTest() { + myModel.addElement(new MyTestListItem()); + } + + public void addTest(TestData testData) { + myModel.addElement(new MyTestListItem(testData)); + } + + public void removeTest(int index) { + if (0 <= index && index < myModel.size()) { + myModel.removeElementAt(index); + } + } + + public void removeAllTests() { + myModel.removeAllElements(); + } + + public List getMyTestListItems() { + List result = new ArrayList<>(myModel.size()); + for (int i = 0; i < myModel.size(); i++) { + result.add(myModel.getElementAt(i)); + } + + return result; + } + + public MyTestListItem getMyTestListItem(int selectedIndex) { + return selectedIndex < 0 || selectedIndex >= myModel.getSize() ? null : myModel.getElementAt(selectedIndex); + } +} diff --git a/src/main/java/com/example/pssupporter/ui/list/MyTestListItem.java b/src/main/java/com/example/pssupporter/ui/list/MyTestListItem.java new file mode 100644 index 0000000..9bfdddf --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/list/MyTestListItem.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.list; + +import com.example.pssupporter.vo.TestData; +import com.example.pssupporter.vo.TestStatus; + +public class MyTestListItem { + private TestData myTestData; + private TestStatus myStatus; + + public MyTestListItem() { + this(new TestData(), TestStatus.READY); + } + + public MyTestListItem(TestData testData) { + this(testData, TestStatus.READY); + } + + public MyTestListItem(TestData myTestData, TestStatus myStatus) { + this.myTestData = myTestData; + this.myStatus = myStatus; + } + + public TestData getTestData() { + return myTestData; + } + + public TestStatus getStatus() { + return myStatus; + } + public void setStatus(TestStatus status){ + this.myStatus = status; + } +} diff --git a/src/main/java/com/example/pssupporter/ui/list/MyTestListPanel.java b/src/main/java/com/example/pssupporter/ui/list/MyTestListPanel.java new file mode 100644 index 0000000..b3da364 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/list/MyTestListPanel.java @@ -0,0 +1,83 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.list; + +import com.example.pssupporter.ui.list.panel.SubTestList; +import com.example.pssupporter.vo.TestData; + +import javax.swing.*; +import javax.swing.event.ListSelectionListener; +import java.util.List; +import java.util.Optional; + +public class MyTestListPanel extends TestListPanel { + private final SubTestList mySubTestList; + + public MyTestListPanel(SubTestList testList, ListSelectionListener clickEvent) { + super(testList); + this.mySubTestList = testList; + this.mySubTestList.addListSelectionListener(clickEvent); + + this.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + this.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); + } + + @Override + public int getSelectedIndex() { + return mySubTestList.getSelectedIndex(); + } + + @Override + public void addTestData() { + mySubTestList.addTest(); + } + + @Override + public void addTestData(TestData testData) { + mySubTestList.addTest(testData); + } + + @Override + public void removeTestData(int index) { + if (0 <= index && index < mySubTestList.getMyTestListItems().size()) { + mySubTestList.removeTest(index); + } + } + + @Override + public void removeAllTestDatas() { + mySubTestList.removeAllTests(); + } + + @Override + public List getAllTestData() { + return mySubTestList.getMyTestListItems().stream().map(MyTestListItem::getTestData).toList(); + } + + @Override + public Optional getTestData(int index) { + return Optional.ofNullable(mySubTestList.getMyTestListItem(index) == null ? null : mySubTestList.getMyTestListItem(index).getTestData()); + } + + @Override + public Optional getSelectedTestData() { + return getTestData(this.getSelectedIndex()); + } + + @Override + public void clearSelection() { + mySubTestList.clearSelection(); + } + + @Override + public List getMyTestListItems() { + return mySubTestList.getMyTestListItems(); + } + + @Override + public MyTestListItem getMyTestList(int selectedIndex) { + return mySubTestList.getMyTestListItem(selectedIndex); + } +} diff --git a/src/main/java/com/example/pssupporter/ui/list/TestList.java b/src/main/java/com/example/pssupporter/ui/list/TestList.java new file mode 100644 index 0000000..0bd7b47 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/list/TestList.java @@ -0,0 +1,21 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.list; + +import com.example.pssupporter.vo.TestData; + +import java.util.List; +import java.util.Optional; + +public interface TestList { + void addTestData(); + void addTestData(TestData testData); + void removeTestData(int index); + void removeAllTestDatas(); + List getAllTestData(); + Optional getTestData(int index); + Optional getSelectedTestData(); + int getSelectedIndex(); +} diff --git a/src/main/java/com/example/pssupporter/ui/list/TestListPanel.java b/src/main/java/com/example/pssupporter/ui/list/TestListPanel.java new file mode 100644 index 0000000..89035f4 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/list/TestListPanel.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.list; + +import com.intellij.ui.components.JBList; +import com.intellij.ui.components.JBScrollPane; + +import java.util.List; + +public abstract class TestListPanel extends JBScrollPane implements TestList { + public TestListPanel(JBList list) { + super(list); + } + + public abstract void clearSelection(); + + public abstract List getMyTestListItems(); + + public abstract MyTestListItem getMyTestList(int selectedIndex); +} diff --git a/src/main/java/com/example/pssupporter/ui/list/function/SubTestListFunction.java b/src/main/java/com/example/pssupporter/ui/list/function/SubTestListFunction.java new file mode 100644 index 0000000..028e46d --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/list/function/SubTestListFunction.java @@ -0,0 +1,24 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.list.function; + +import com.example.pssupporter.ui.list.MyTestListItem; +import com.example.pssupporter.vo.TestData; + +import java.util.List; + +public interface SubTestListFunction { + void addTest(); + + void addTest(TestData testData); + + void removeTest(int index); + + void removeAllTests(); + + List getMyTestListItems(); + + MyTestListItem getMyTestListItem(int index); +} diff --git a/src/main/java/com/example/pssupporter/ui/list/panel/SubTestList.java b/src/main/java/com/example/pssupporter/ui/list/panel/SubTestList.java new file mode 100644 index 0000000..53f9a90 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/list/panel/SubTestList.java @@ -0,0 +1,12 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.list.panel; + +import com.example.pssupporter.ui.list.MyTestListItem; +import com.example.pssupporter.ui.list.function.SubTestListFunction; +import com.intellij.ui.components.JBList; + +public abstract class SubTestList extends JBList implements SubTestListFunction { +} diff --git a/src/main/java/com/example/pssupporter/ui/main/MyMainView.java b/src/main/java/com/example/pssupporter/ui/main/MyMainView.java new file mode 100644 index 0000000..ab814f6 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/main/MyMainView.java @@ -0,0 +1,103 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.main; + +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.vo.TestData; +import com.intellij.ui.components.JBPanel; + +import java.awt.*; + + +public class MyMainView extends JBPanel { + private boolean myHorizontal; + + private final TestListPanel myTestListPanel; + private final EditorPanel myEditorPanel; + private TestData myCurrentTestData; + + public MyMainView(TestListPanel testListPanel, EditorPanel editorPanel, boolean horizontal) { + super(new BorderLayout()); + + this.myTestListPanel = testListPanel; + this.myEditorPanel = editorPanel; + + this.myHorizontal = horizontal; + + this.myCurrentTestData = null; + + setupTestListPanel(myTestListPanel); + setupEditorPanel(myEditorPanel); + } + + /** + * implements editor panel + */ + private void setupEditorPanel(EditorPanel editorPanel) { + this.add(editorPanel, BorderLayout.CENTER); + } + + /** + * implement test list panel + */ + private void setupTestListPanel(TestListPanel testListPanel) { + this.add(testListPanel, BorderLayout.WEST); + } + + public void setLayoutBasedOnOrientation(boolean horizontal) { + setLayoutBasedOnOrientation(horizontal, false); + } + + private void setLayoutBasedOnOrientation(boolean horizontal, boolean init) { + if (init || this.myHorizontal != horizontal) { + if (horizontal) { + setHorizontalLayout(); + } else { + setVerticalLayout(); + } + this.myHorizontal = horizontal; + } + } + + private void setHorizontalLayout() { + this.add(myTestListPanel, BorderLayout.WEST); + this.add(myEditorPanel, BorderLayout.CENTER); + } + + private void setVerticalLayout() { + this.add(myTestListPanel, BorderLayout.NORTH); + this.add(myEditorPanel, BorderLayout.CENTER); + } + + //custom action + public void changeTestData() { + //save current input and output if current test data presents + if (myCurrentTestData != null) { + myCurrentTestData.setInput(myEditorPanel.getInput()); + myCurrentTestData.setOutput(myEditorPanel.getOutput()); + } + + myCurrentTestData = myTestListPanel.getSelectedTestData() + .orElse(null); + + if (myCurrentTestData != null) { + myEditorPanel.setInput(myCurrentTestData.getInput()); + myEditorPanel.setOutput(myCurrentTestData.getOutput()); + myEditorPanel.setResult(myCurrentTestData.getResult()); + } + } + + public void saveAndClear() { + if (myCurrentTestData != null) { + myCurrentTestData.setInput(myEditorPanel.getInput()); + myCurrentTestData.setOutput(myEditorPanel.getOutput()); + } + + myCurrentTestData = null; + + myEditorPanel.clearAll(); + } +} diff --git a/src/main/java/com/example/pssupporter/ui/toolbar/ActionToolbarPanel.java b/src/main/java/com/example/pssupporter/ui/toolbar/ActionToolbarPanel.java new file mode 100644 index 0000000..bd69f2c --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/toolbar/ActionToolbarPanel.java @@ -0,0 +1,19 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.toolbar; + +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.ui.roots.ToolbarPanel; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; + +public abstract class ActionToolbarPanel extends ToolbarPanel implements Toolbar { + public ActionToolbarPanel(@NotNull JComponent contentComponent, @NotNull ActionGroup actions, @NotNull @NonNls String toolbarPlace, @Nullable JComponent targetComponent) { + super(contentComponent, actions, toolbarPlace, targetComponent); + } +} diff --git a/src/main/java/com/example/pssupporter/ui/MyToolbarPanel.java b/src/main/java/com/example/pssupporter/ui/toolbar/MyToolbarPanel.java similarity index 84% rename from src/main/java/com/example/pssupporter/ui/MyToolbarPanel.java rename to src/main/java/com/example/pssupporter/ui/toolbar/MyToolbarPanel.java index 270b6ff..2931dbc 100644 --- a/src/main/java/com/example/pssupporter/ui/MyToolbarPanel.java +++ b/src/main/java/com/example/pssupporter/ui/toolbar/MyToolbarPanel.java @@ -2,18 +2,17 @@ * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. */ -package com.example.pssupporter.ui; +package com.example.pssupporter.ui.toolbar; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.wm.impl.welcomeScreen.BottomLineBorder; import com.intellij.ui.components.JBPanel; -import com.intellij.ui.roots.ToolbarPanel; import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; -public class MyToolbarPanel extends ToolbarPanel { +public class MyToolbarPanel extends ActionToolbarPanel { public MyToolbarPanel(@NotNull ActionGroup actions, JComponent component) { super(new JBPanel(new BorderLayout()), actions, "toolbarPlace", component); this.setBorder(new BottomLineBorder()); diff --git a/src/main/java/com/example/pssupporter/ui/toolbar/Toolbar.java b/src/main/java/com/example/pssupporter/ui/toolbar/Toolbar.java new file mode 100644 index 0000000..951b241 --- /dev/null +++ b/src/main/java/com/example/pssupporter/ui/toolbar/Toolbar.java @@ -0,0 +1,8 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.toolbar; + +public interface Toolbar { +} diff --git a/src/main/java/com/example/pssupporter/utils/thread/GlobalThreadStore.java b/src/main/java/com/example/pssupporter/utils/thread/MyThreadStore.java similarity index 91% rename from src/main/java/com/example/pssupporter/utils/thread/GlobalThreadStore.java rename to src/main/java/com/example/pssupporter/utils/thread/MyThreadStore.java index b80ba90..c5483e3 100644 --- a/src/main/java/com/example/pssupporter/utils/thread/GlobalThreadStore.java +++ b/src/main/java/com/example/pssupporter/utils/thread/MyThreadStore.java @@ -16,24 +16,15 @@ /** * This class will support you to maintain and run threads group easier */ -public class GlobalThreadStore { - private static final GlobalThreadStore ourInstance = new GlobalThreadStore(); +public class MyThreadStore { private final Map myThreadStore; - private GlobalThreadStore() { + public MyThreadStore() { myThreadStore = new EnumMap<>(ThreadGroupName.class); Arrays.stream(ThreadGroupName.values()).forEach(tg -> myThreadStore.put(tg, tg.getThreadPoolExecutor())); } - - /** - * @return ourInstance singleton instance - */ - public static GlobalThreadStore getInstance() { - return ourInstance; - } - /** * This method returns threadPoolExecutor defined in ThreadGroupName. * When the threadPoolExecutor is shutdowned, a new threadPoolExecutor that defines in ThreadGroupName will return diff --git a/src/main/java/com/example/pssupporter/utils/thread/TestRunningThread.java b/src/main/java/com/example/pssupporter/utils/thread/TestRunningThread.java index ffcb31b..dd6f1d2 100644 --- a/src/main/java/com/example/pssupporter/utils/thread/TestRunningThread.java +++ b/src/main/java/com/example/pssupporter/utils/thread/TestRunningThread.java @@ -4,7 +4,7 @@ package com.example.pssupporter.utils.thread; -import com.example.pssupporter.ui.MyTestListItem; +import com.example.pssupporter.ui.list.MyTestListItem; import com.example.pssupporter.utils.runner.CodeRunner; import com.example.pssupporter.utils.runner.dto.CodeRunnerDTO; import com.example.pssupporter.vo.TestData; @@ -20,7 +20,7 @@ public TestRunningThread(String myFilePath, CodeRunner myCodeRunner, MyTestListI this.myFilePath = myFilePath; this.myCodeRunner = myCodeRunner; this.myTestListItem = myTestListItem; - this.myTestData = myTestListItem.getMyEditorPanel().getTestData(); + this.myTestData = myTestListItem.getTestData(); } @Override @@ -40,7 +40,7 @@ public void run() { myTestListItem.setStatus(TestStatus.FAIL); } - myTestListItem.getMyEditorPanel().setResult(result); + myTestData.setResult(result); } @Override diff --git a/src/main/java/com/example/pssupporter/vo/TestData.java b/src/main/java/com/example/pssupporter/vo/TestData.java index ddbe324..617315a 100644 --- a/src/main/java/com/example/pssupporter/vo/TestData.java +++ b/src/main/java/com/example/pssupporter/vo/TestData.java @@ -20,6 +20,13 @@ public TestData() { public TestData(String myInput, String myOutput) { setInput(myInput); setOutput(myOutput); + setResult(""); + } + + public TestData(String myInput, String myOutput, String myResult) { + setInput(myInput); + setOutput(myOutput); + setResult(myResult); } public String getInput() { @@ -41,4 +48,17 @@ public void setOutput(String myOutput) { public void setResult(String myResult) { this.myResult = StringUtils.rTrim(StringUtils.removeCarriageReturn(myResult)); } + + public String getResult() { + return StringUtils.rTrim(StringUtils.removeCarriageReturn(myResult)); + } + + @Override + public String toString() { + return "TestData{" + + "myInput='" + myInput + '\'' + + ", myOutput='" + myOutput + '\'' + + ", myResult='" + myResult + '\'' + + '}'; + } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 35ae3a6..340d3e4 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -46,31 +46,7 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/test/java/com/example/pssupporter/actions/MyAddTestActionTest.java b/src/test/java/com/example/pssupporter/actions/MyAddTestActionTest.java new file mode 100644 index 0000000..919ac68 --- /dev/null +++ b/src/test/java/com/example/pssupporter/actions/MyAddTestActionTest.java @@ -0,0 +1,110 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.actions; + +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.utils.thread.MyThreadStore; +import com.example.pssupporter.utils.thread.vo.ThreadGroupName; +import com.example.pssupporter.vo.TestData; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.Presentation; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class MyAddTestActionTest { + @Mock + private TestListPanel mockTestListPanel; + @Mock + private MyThreadStore mockThreadStore; + @Mock + private Presentation presentation; + @Mock + private AnActionEvent mockAnActionEvent; + + @InjectMocks + private MyAddTestAction addTestAction; + + @Nested + @DisplayName("[UpdateTest]") + class UpdateTest { + boolean isEnabled; + + @BeforeEach + void init() { + when(mockAnActionEvent.getPresentation()) + .thenReturn(presentation); + doAnswer(invocation -> { + Boolean argument = invocation.getArgument(0, Boolean.class); + isEnabled = argument; + return isEnabled; + }).when(presentation).setEnabled(anyBoolean()); + } + + @Test + void disableWhenRunningThreadsExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(true); + + //when + addTestAction.update(mockAnActionEvent); + + //then + assertFalse(isEnabled); + } + + @Test + void enableWhenRunningThreadsNotExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(false); + + //when + addTestAction.update(mockAnActionEvent); + + //then + assertTrue(isEnabled); + } + } + + @Nested + @DisplayName("[ActionPerformed]") + class ActionPerformedTest { + List testDataList = new ArrayList<>(); + + @BeforeEach + void init() { + doAnswer(invocation -> { + testDataList.add(new TestData()); + return null; + }).when(mockTestListPanel).addTestData(); + } + + @Test + void increaseTestListItem() { + //given + + //when + addTestAction.actionPerformed(mockAnActionEvent); + + //then + assertEquals(1, testDataList.size()); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/example/pssupporter/actions/MyRemoveAllTestActionTest.java b/src/test/java/com/example/pssupporter/actions/MyRemoveAllTestActionTest.java new file mode 100644 index 0000000..f130cea --- /dev/null +++ b/src/test/java/com/example/pssupporter/actions/MyRemoveAllTestActionTest.java @@ -0,0 +1,126 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.actions; + +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.utils.thread.MyThreadStore; +import com.example.pssupporter.utils.thread.vo.ThreadGroupName; +import com.example.pssupporter.vo.TestData; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.Presentation; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class MyRemoveAllTestActionTest { + @Mock + private TestListPanel mockTestListPanel; + @Mock + private EditorPanel mockEditorPanel; + @Mock + private MyThreadStore mockThreadStore; + @Mock + private Presentation presentation; + @Mock + private AnActionEvent mockAnActionEvent; + + @InjectMocks + private MyRemoveAllTestAction removeAllTestAction; + + @Nested + @DisplayName("[UpdateTest]") + class UpdateTest { + boolean isEnabled; + + @BeforeEach + void init() { + when(mockAnActionEvent.getPresentation()) + .thenReturn(presentation); + doAnswer(invocation -> { + Boolean argument = invocation.getArgument(0, Boolean.class); + isEnabled = argument; + return isEnabled; + }).when(presentation).setEnabled(anyBoolean()); + } + + @Test + void disableWhenRunningThreadsExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(true); + + //when + removeAllTestAction.update(mockAnActionEvent); + + //then + assertFalse(isEnabled); + } + + @Test + void enableWhenRunningThreadsNotExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(false); + + //when + removeAllTestAction.update(mockAnActionEvent); + + //then + assertTrue(isEnabled); + } + } + + @Nested + @DisplayName("[actionPerformed]") + class ActionPerformedTest { + String input = "input"; + String output = "output"; + String result = "result"; + List testDataList = new ArrayList<>(); + + @BeforeEach + void init() { + doAnswer(invocation -> { + input = null; + output = null; + result = null; + return null; + }).when(mockEditorPanel).clearAll(); + doAnswer(invocation -> { + testDataList.clear(); + return null; + }).when(mockTestListPanel).removeAllTestDatas(); + } + + @Test + void clearEditorAndTestListWhenRemoveActionPerformed() { + //given + testDataList.add(new TestData()); + + //when + removeAllTestAction.actionPerformed(mockAnActionEvent); + + //then + assertTrue(testDataList.isEmpty()); + assertNull(input); + assertNull(output); + assertNull(result); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/example/pssupporter/actions/MyRemoveTestActionTest.java b/src/test/java/com/example/pssupporter/actions/MyRemoveTestActionTest.java new file mode 100644 index 0000000..2a17314 --- /dev/null +++ b/src/test/java/com/example/pssupporter/actions/MyRemoveTestActionTest.java @@ -0,0 +1,134 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.actions; + +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.utils.thread.MyThreadStore; +import com.example.pssupporter.utils.thread.vo.ThreadGroupName; +import com.example.pssupporter.vo.TestData; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.Presentation; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class MyRemoveTestActionTest { + @Mock + private TestListPanel mockTestListPanel; + @Mock + private EditorPanel mockEditorPanel; + @Mock + private MyThreadStore mockThreadStore; + @Mock + private Presentation presentation; + @Mock + private AnActionEvent mockAnActionEvent; + + @InjectMocks + private MyRemoveTestAction removeTestAction; + + @Nested + @DisplayName("[UpdateTest]") + class UpdateTest { + boolean isEnabled; + + @BeforeEach + void init() { + when(mockAnActionEvent.getPresentation()) + .thenReturn(presentation); + doAnswer(invocation -> { + Boolean argument = invocation.getArgument(0, Boolean.class); + isEnabled = argument; + return isEnabled; + }).when(presentation).setEnabled(anyBoolean()); + } + + @Test + void disableWhenRunningThreadsExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(true); + + //when + removeTestAction.update(mockAnActionEvent); + + //then + assertFalse(isEnabled); + } + + @Test + void enableWhenRunningThreadsNotExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(false); + + //when + removeTestAction.update(mockAnActionEvent); + + //then + assertTrue(isEnabled); + } + } + + @Nested + @DisplayName("[actionPerformed]") + class ActionPerformedTest{ + String input = "input"; + String output = "output"; + String result = "result"; + List testDataList = new ArrayList<>(); + + @BeforeEach + void init(){ + doAnswer(invocation -> { + input = null; + output = null; + result = null; + return null; + }).when(mockEditorPanel).clearAll(); + doAnswer(invocation -> { + Integer index = invocation.getArgument(0, Integer.class); + testDataList.remove(index.intValue()); + return null; + }).when(mockTestListPanel).removeTestData(anyInt()); + } + + @Test + void clearEditorAndRemoveSelectedTestWhenRemoveActionPerformed(){ + //given + when(mockTestListPanel.getSelectedIndex()) + .thenReturn(1); + TestData testData1 = new TestData("1", "1"); + TestData testData2 = new TestData("2", "2"); + TestData testData3 = new TestData("3", "3"); + testDataList.add(testData1); + testDataList.add(testData2); + testDataList.add(testData3); + + //when + removeTestAction.actionPerformed(mockAnActionEvent); + + //then + assertEquals(2,testDataList.size()); + assertTrue(!testDataList.contains(testData2)); + assertNull(input); + assertNull(output); + assertNull(result); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/example/pssupporter/actions/MyRunAllTestsActionTest.java b/src/test/java/com/example/pssupporter/actions/MyRunAllTestsActionTest.java new file mode 100644 index 0000000..b8a2a1f --- /dev/null +++ b/src/test/java/com/example/pssupporter/actions/MyRunAllTestsActionTest.java @@ -0,0 +1,168 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.actions; + +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.list.MyTestListItem; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.ui.main.MyMainView; +import com.example.pssupporter.utils.IntellijUtils; +import com.example.pssupporter.utils.thread.MyThreadStore; +import com.example.pssupporter.utils.thread.vo.ThreadGroupName; +import com.example.pssupporter.vo.TestData; +import com.intellij.mock.MockVirtualFile; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.*; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +public class MyRunAllTestsActionTest { + @Mock + private TestListPanel mockTestListPanel; + @Mock + private EditorPanel mockEditorPanel; + @Mock + private MyMainView mockMainView; + @Mock + private MyThreadStore mockThreadStore; + @Mock + private Presentation presentation; + @Mock + private AnActionEvent mockAnActionEvent; + @Mock + private Project mockProject; + + @InjectMocks + private MyRunAllTestsAction runAllTestsAction; + + @Nested + @DisplayName("[UpdateTest]") + class UpdateTest { + boolean isEnabled; + + @BeforeEach + void init() { + when(mockAnActionEvent.getPresentation()) + .thenReturn(presentation); + doAnswer(invocation -> { + Boolean argument = invocation.getArgument(0, Boolean.class); + isEnabled = argument; + return isEnabled; + }).when(presentation).setEnabled(anyBoolean()); + } + + @Test + void disableWhenRunningThreadsExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(true); + + //when + runAllTestsAction.update(mockAnActionEvent); + + //then + assertFalse(isEnabled); + } + + @Test + void enableWhenRunningThreadsNotExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(false); + + //when + runAllTestsAction.update(mockAnActionEvent); + + //then + assertTrue(isEnabled); + } + } + + @Nested + @DisplayName("[ActionPerformed]") + class ActionPerformedTest { + MockedStatic mockIntellijUtils; + VirtualFile mockFile = new MockVirtualFile("mockFile"); + Map> threadContainer = new HashMap<>(); + + @BeforeEach + void init() { + mockIntellijUtils = mockStatic(IntellijUtils.class); + + } + + @AfterEach + void close() { + mockIntellijUtils.close(); + } + + @Test + void runOneTest() { + //given + when(IntellijUtils.getSelectedFile(any())) + .thenReturn(Optional.ofNullable(mockFile)); + when(mockAnActionEvent.getProject()) + .thenReturn(mockProject); + doAnswer(invocation -> { + ThreadGroupName threadGroupName = invocation.getArgument(0, ThreadGroupName.class); + Thread threads = invocation.getArgument(1, Thread.class); + List list = threadContainer.getOrDefault(threadGroupName, new ArrayList<>()); + list.add(threads); + threadContainer.put(threadGroupName, list); + return null; + }).when(mockThreadStore).executeThreads(any(ThreadGroupName.class), any(Thread.class)); + when(mockTestListPanel.getMyTestListItems()) + .thenReturn(List.of(new MyTestListItem(new TestData()))); + + //when + runAllTestsAction.actionPerformed(mockAnActionEvent); + + //then + assertEquals(1, threadContainer.get(ThreadGroupName.TEST_RUNNING).size()); + } + + @Test + void runManyTests() { + //given + when(IntellijUtils.getSelectedFile(any())) + .thenReturn(Optional.ofNullable(mockFile)); + when(mockAnActionEvent.getProject()) + .thenReturn(mockProject); + Map> threadContainer = new HashMap<>(); + doAnswer(invocation -> { + ThreadGroupName threadGroupName = invocation.getArgument(0, ThreadGroupName.class); + Thread threads1 = invocation.getArgument(1, Thread.class); + Thread threads2 = invocation.getArgument(2, Thread.class); + Thread threads3 = invocation.getArgument(2, Thread.class); + List list = threadContainer.getOrDefault(threadGroupName, new ArrayList<>()); + list.add(threads1); + list.add(threads2); + list.add(threads3); + threadContainer.put(threadGroupName, list); + return null; + }).when(mockThreadStore).executeThreads(any(ThreadGroupName.class), any(Thread.class), any(Thread.class), any(Thread.class)); + when(mockTestListPanel.getMyTestListItems()) + .thenReturn(List.of(new MyTestListItem(new TestData()), new MyTestListItem(new TestData()), new MyTestListItem(new TestData()))); + + //when + runAllTestsAction.actionPerformed(mockAnActionEvent); + + //then + assertEquals(3, threadContainer.get(ThreadGroupName.TEST_RUNNING).size()); + } + } +} diff --git a/src/test/java/com/example/pssupporter/actions/MyRunTestActionTest.java b/src/test/java/com/example/pssupporter/actions/MyRunTestActionTest.java new file mode 100644 index 0000000..4586732 --- /dev/null +++ b/src/test/java/com/example/pssupporter/actions/MyRunTestActionTest.java @@ -0,0 +1,138 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.actions; + +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.list.MyTestListItem; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.ui.main.MyMainView; +import com.example.pssupporter.utils.IntellijUtils; +import com.example.pssupporter.utils.thread.MyThreadStore; +import com.example.pssupporter.utils.thread.vo.ThreadGroupName; +import com.example.pssupporter.vo.TestData; +import com.intellij.mock.MockVirtualFile; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.*; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +public class MyRunTestActionTest { + @Mock + private TestListPanel mockTestListPanel; + @Mock + private EditorPanel mockEditorPanel; + @Mock + private MyMainView mockMainView; + @Mock + private MyThreadStore mockThreadStore; + @Mock + private Presentation presentation; + @Mock + private AnActionEvent mockAnActionEvent; + @Mock + private Project mockProject; + + @InjectMocks + private MyRunAllTestsAction runAllTestsAction; + + @Nested + @DisplayName("[UpdateTest]") + class UpdateTest { + boolean isEnabled; + + @BeforeEach + void init() { + when(mockAnActionEvent.getPresentation()) + .thenReturn(presentation); + doAnswer(invocation -> { + Boolean argument = invocation.getArgument(0, Boolean.class); + isEnabled = argument; + return isEnabled; + }).when(presentation).setEnabled(anyBoolean()); + } + + @Test + void disableWhenRunningThreadsExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(true); + + //when + runAllTestsAction.update(mockAnActionEvent); + + //then + assertFalse(isEnabled); + } + + @Test + void enableWhenRunningThreadsNotExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(false); + + //when + runAllTestsAction.update(mockAnActionEvent); + + //then + assertTrue(isEnabled); + } + } + + @Nested + @DisplayName("[ActionPerformed]") + class ActionPerformedTest { + MockedStatic mockIntellijUtils; + VirtualFile mockFile = new MockVirtualFile("mockFile"); + Map> threadContainer = new HashMap<>(); + + @BeforeEach + void init() { + mockIntellijUtils = mockStatic(IntellijUtils.class); + + } + + @AfterEach + void close() { + mockIntellijUtils.close(); + } + + @Test + void runOneTest() { + //given + when(IntellijUtils.getSelectedFile(any())) + .thenReturn(Optional.ofNullable(mockFile)); + when(mockAnActionEvent.getProject()) + .thenReturn(mockProject); + doAnswer(invocation -> { + ThreadGroupName threadGroupName = invocation.getArgument(0, ThreadGroupName.class); + Thread threads = invocation.getArgument(1, Thread.class); + List list = threadContainer.getOrDefault(threadGroupName, new ArrayList<>()); + list.add(threads); + threadContainer.put(threadGroupName, list); + return null; + }).when(mockThreadStore).executeThreads(any(ThreadGroupName.class), any(Thread.class)); + when(mockTestListPanel.getMyTestListItems()) + .thenReturn(List.of(new MyTestListItem(new TestData()))); + + //when + runAllTestsAction.actionPerformed(mockAnActionEvent); + + //then + assertEquals(1, threadContainer.get(ThreadGroupName.TEST_RUNNING).size()); + } + } +} diff --git a/src/test/java/com/example/pssupporter/actions/MyStopAllTestsActionTest.java b/src/test/java/com/example/pssupporter/actions/MyStopAllTestsActionTest.java new file mode 100644 index 0000000..601d231 --- /dev/null +++ b/src/test/java/com/example/pssupporter/actions/MyStopAllTestsActionTest.java @@ -0,0 +1,111 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.actions; + +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.ui.main.MyMainView; +import com.example.pssupporter.utils.thread.MyThreadStore; +import com.example.pssupporter.utils.thread.vo.ThreadGroupName; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.project.Project; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.*; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +public class MyStopAllTestsActionTest { + @Mock + private TestListPanel mockTestListPanel; + @Mock + private EditorPanel mockEditorPanel; + @Mock + private MyMainView mockMainView; + @Mock + private MyThreadStore mockThreadStore; + @Mock + private Presentation presentation; + @Mock + private AnActionEvent mockAnActionEvent; + @Mock + private Project mockProject; + + @InjectMocks + private MyStopAllTestsAction stopAllTestsAction; + + @Nested + @DisplayName("[UpdateTest]") + class UpdateTest { + boolean isEnabled; + + @BeforeEach + void init() { + when(mockAnActionEvent.getPresentation()) + .thenReturn(presentation); + doAnswer(invocation -> { + Boolean argument = invocation.getArgument(0, Boolean.class); + isEnabled = argument; + return isEnabled; + }).when(presentation).setEnabled(anyBoolean()); + } + + @Test + void disableWhenRunningThreadsExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(true); + + //when + stopAllTestsAction.update(mockAnActionEvent); + + //then + assertTrue(isEnabled); + } + + @Test + void enableWhenRunningThreadsNotExist() { + //given + when(mockThreadStore.hasRunningThreads(any(ThreadGroupName.class))).thenReturn(false); + + //when + stopAllTestsAction.update(mockAnActionEvent); + + //then + assertFalse(isEnabled); + } + } + @Nested + @DisplayName("[ActionPerformed]") + class ActionPerformedTest { + @Test + void stopAllRunningTests() { + //given + Map> threadContainer = new HashMap<>(); + List testList = new ArrayList<>(); + testList.add(new Thread()); + threadContainer.put(ThreadGroupName.TEST_RUNNING,testList); + doAnswer(invocation -> { + ThreadGroupName threadGroupName = invocation.getArgument(0, ThreadGroupName.class); + threadContainer.getOrDefault(threadGroupName,new ArrayList<>()).clear(); + return null; + }).when(mockThreadStore).interruptThreads(any(ThreadGroupName.class)); + + //when + stopAllTestsAction.actionPerformed(mockAnActionEvent); + + //then + assertEquals(0,threadContainer.get(ThreadGroupName.TEST_RUNNING).size()); + } + } +} diff --git a/src/test/java/com/example/pssupporter/ui/editor/EditorPanelTest.java b/src/test/java/com/example/pssupporter/ui/editor/EditorPanelTest.java new file mode 100644 index 0000000..5784ccf --- /dev/null +++ b/src/test/java/com/example/pssupporter/ui/editor/EditorPanelTest.java @@ -0,0 +1,80 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.editor; + +import com.example.pssupporter.ui.editor.panel.InputEditorPanel; +import com.example.pssupporter.ui.editor.panel.OutputEditorPanel; +import com.example.pssupporter.ui.editor.panel.ResultEditorPanel; +import com.example.pssupporter.ui.fake.FakeInputEditorPanel; +import com.example.pssupporter.ui.fake.FakeOutputEditorPanel; +import com.example.pssupporter.ui.fake.FakeResultEditorPanel; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class EditorPanelTest { + private InputEditorPanel inputEditorPanel = new FakeInputEditorPanel(); + private OutputEditorPanel outputEditorPanel = new FakeOutputEditorPanel(); + private ResultEditorPanel resultEditorPanel = new FakeResultEditorPanel(); + private EditorPanel editorPanel = new MyEditorPanel(inputEditorPanel, outputEditorPanel, resultEditorPanel); + + @Test + void inputDataTest() { + //given + String testText = "For Input Test"; + editorPanel.setInput(testText); + + //when + String input = editorPanel.getInput(); + + //then + assertEquals(testText, input); + } + + @Test + void outputDataTest() { + //given + String testText = "For Output Test"; + editorPanel.setOutput(testText); + + //when + String output = editorPanel.getOutput(); + + //then + assertEquals(testText, output); + } + + @Test + void resultDataTest() { + //given + String testText = "For Result Test"; + editorPanel.setResult(testText); + + //when + String result = editorPanel.getResult(); + + //then + assertEquals(testText, result); + } + + @Test + void clearAllTest() { + //given + String testInput = "For Input Test"; + String testOutput = "For Output Test"; + String testResult = "For Result Test"; + editorPanel.setInput(testInput); + editorPanel.setOutput(testOutput); + editorPanel.setResult(testResult); + + //when + editorPanel.clearAll(); + + //then + assertEquals("", editorPanel.getInput()); + assertEquals("", editorPanel.getOutput()); + assertEquals("", editorPanel.getResult()); + } +} \ No newline at end of file diff --git a/src/test/java/com/example/pssupporter/ui/factory/JLabelFactoryTest.java b/src/test/java/com/example/pssupporter/ui/factory/JLabelFactoryTest.java new file mode 100644 index 0000000..d0c4793 --- /dev/null +++ b/src/test/java/com/example/pssupporter/ui/factory/JLabelFactoryTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.factory; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import javax.swing.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class JLabelFactoryTest { + @Nested + @DisplayName("[GetJLabelWithText]") + class GetJLabelWithTextTest { + @Test + @DisplayName("Success : Get an instance with text") + void getAnInstanceWithText_Success() { + JLabel jLabel = JLabelFactory.getJLabel("test"); + assertNotNull(jLabel); + assertEquals("test", jLabel.getText()); + } + + @Test + @DisplayName("Success : Get same instances") + void getSameInstances_Success() { + JLabel jLabel1 = JLabelFactory.getJLabel("test"); + JLabel jLabel2 = JLabelFactory.getJLabel("test"); + + assertEquals(jLabel1, jLabel2); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/example/pssupporter/ui/factory/JTitleBorderFactoryTest.java b/src/test/java/com/example/pssupporter/ui/factory/JTitleBorderFactoryTest.java new file mode 100644 index 0000000..96d7c4b --- /dev/null +++ b/src/test/java/com/example/pssupporter/ui/factory/JTitleBorderFactoryTest.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.factory; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import javax.swing.border.Border; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class JTitleBorderFactoryTest { + @Nested + @DisplayName("[GetTitleBorder]") + class GetTitleBorderTest { + @Test + @DisplayName("Success : Get an instance with title") + void getAnInstanceWithTitle_Success() { + Border border = JTitleBorderFactory.getBorder("test"); + assertNotNull(border); + } + + @Test + @DisplayName("Success : Get same instances") + void getSameInstances_Success() { + Border border1 = JTitleBorderFactory.getBorder("test"); + Border border2 = JTitleBorderFactory.getBorder("test"); + + assertEquals(border1, border2); + } + } +} \ No newline at end of file diff --git a/src/test/java/com/example/pssupporter/ui/fake/FakeInputEditorPanel.java b/src/test/java/com/example/pssupporter/ui/fake/FakeInputEditorPanel.java new file mode 100644 index 0000000..609d52b --- /dev/null +++ b/src/test/java/com/example/pssupporter/ui/fake/FakeInputEditorPanel.java @@ -0,0 +1,21 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.fake; + +import com.example.pssupporter.ui.editor.panel.InputEditorPanel; + +public class FakeInputEditorPanel extends InputEditorPanel { + private String input; + + @Override + public void setInput(String input) { + this.input = input; + } + + @Override + public String getInput() { + return this.input; + } +} diff --git a/src/test/java/com/example/pssupporter/ui/fake/FakeOutputEditorPanel.java b/src/test/java/com/example/pssupporter/ui/fake/FakeOutputEditorPanel.java new file mode 100644 index 0000000..5ba11ef --- /dev/null +++ b/src/test/java/com/example/pssupporter/ui/fake/FakeOutputEditorPanel.java @@ -0,0 +1,20 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.fake; + +import com.example.pssupporter.ui.editor.panel.OutputEditorPanel; + +public class FakeOutputEditorPanel extends OutputEditorPanel { + private String output; + @Override + public void setOutput(String output) { + this.output = output; + } + + @Override + public String getOutput() { + return this.output; + } +} diff --git a/src/test/java/com/example/pssupporter/ui/fake/FakeResultEditorPanel.java b/src/test/java/com/example/pssupporter/ui/fake/FakeResultEditorPanel.java new file mode 100644 index 0000000..c331b1f --- /dev/null +++ b/src/test/java/com/example/pssupporter/ui/fake/FakeResultEditorPanel.java @@ -0,0 +1,20 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.fake; + +import com.example.pssupporter.ui.editor.panel.ResultEditorPanel; + +public class FakeResultEditorPanel extends ResultEditorPanel { + private String result; + @Override + public void setResult(String result) { + this.result = result; + } + + @Override + public String getResult() { + return this.result; + } +} diff --git a/src/test/java/com/example/pssupporter/ui/fake/FakeSubTestList.java b/src/test/java/com/example/pssupporter/ui/fake/FakeSubTestList.java new file mode 100644 index 0000000..ffbe098 --- /dev/null +++ b/src/test/java/com/example/pssupporter/ui/fake/FakeSubTestList.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.fake; + +import com.example.pssupporter.ui.list.MyTestListItem; +import com.example.pssupporter.ui.list.panel.SubTestList; +import com.example.pssupporter.vo.TestData; + +import java.util.ArrayList; +import java.util.List; + +public class FakeSubTestList extends SubTestList { + List lists = new ArrayList<>(); + int selectedIndex = -1; + + @Override + public void setSelectedIndex(int index) { + this.selectedIndex = index; + } + + @Override + public int getSelectedIndex() { + return this.selectedIndex; + } + + @Override + public void addTest() { + lists.add(new MyTestListItem()); + } + + @Override + public void addTest(TestData testData) { + lists.add(new MyTestListItem(testData)); + } + + @Override + public void removeTest(int index) { + lists.remove(index); + } + + @Override + public void removeAllTests() { + lists.clear(); + } + + @Override + public List getMyTestListItems() { + return lists; + } + + @Override + public MyTestListItem getMyTestListItem(int index) { + return index < 0 || index >= lists.size() ? null : lists.get(index); + } +} diff --git a/src/test/java/com/example/pssupporter/ui/list/SubTestListTest.java b/src/test/java/com/example/pssupporter/ui/list/SubTestListTest.java new file mode 100644 index 0000000..ca0b109 --- /dev/null +++ b/src/test/java/com/example/pssupporter/ui/list/SubTestListTest.java @@ -0,0 +1,202 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.list; + +import com.example.pssupporter.vo.TestData; +import com.example.pssupporter.vo.TestStatus; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +class SubTestListTest { + private MyCellRenderer myCellRenderer = new MyCellRenderer(); + private MySubTestList mySubTestList = new MySubTestList(myCellRenderer); + + @Test + void addTestWithoutParam() { + //given + + //when + mySubTestList.addTest(); + + //then + List myTestListItems = mySubTestList.getMyTestListItems(); + assertEquals(1, myTestListItems.size()); + MyTestListItem item = myTestListItems.get(0); + assertEquals("", item.getTestData().getInput()); + assertEquals("", item.getTestData().getOutput()); + assertEquals("", item.getTestData().getResult()); + assertEquals(TestStatus.READY, item.getStatus()); + } + + @Test + void addTestWithParam() { + //given + String testInput = "testInput"; + String testOutput = "testOutput"; + String testResult = "testResult"; + TestData testData = new TestData(testInput, testOutput, testResult); + + //when + mySubTestList.addTest(testData); + + //then + List myTestListItems = mySubTestList.getMyTestListItems(); + assertEquals(1, myTestListItems.size()); + MyTestListItem item = myTestListItems.get(0); + assertEquals(testInput, item.getTestData().getInput()); + assertEquals(testOutput, item.getTestData().getOutput()); + assertEquals(testResult, item.getTestData().getResult()); + assertEquals(TestStatus.READY, item.getStatus()); + } + + @Test + void removeTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(mySubTestList::addTest); + int removeIndex = 2; + + //when + mySubTestList.removeTest(removeIndex); + + //then + List items = mySubTestList.getMyTestListItems(); + assertEquals(testDatas.size() - 1, items.size()); + for (int i = 0; i < items.size(); i++) { + int index = i >= removeIndex ? i + 1 : i; + assertEquals(testDatas.get(index).getInput(), items.get(i).getTestData().getInput()); + assertEquals(testDatas.get(index).getOutput(), items.get(i).getTestData().getOutput()); + assertEquals(testDatas.get(index).getResult(), items.get(i).getTestData().getResult()); + } + } + + @Test + void removeOutOfIndexTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(mySubTestList::addTest); + int removeIndex = testDatas.size() + 10; + + //when + mySubTestList.removeTest(removeIndex); + + //then + List items = mySubTestList.getMyTestListItems(); + assertEquals(testDatas.size(), items.size()); + for (int i = 0; i < items.size(); i++) { + assertEquals(testDatas.get(i).getInput(), items.get(i).getTestData().getInput()); + assertEquals(testDatas.get(i).getOutput(), items.get(i).getTestData().getOutput()); + assertEquals(testDatas.get(i).getResult(), items.get(i).getTestData().getResult()); + } + } + + @Test + void removeAllTests() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(mySubTestList::addTest); + + //when + mySubTestList.removeAllTests(); + + //then + assertEquals(0, mySubTestList.getMyTestListItems().size()); + } + + @Test + void getMyTestListItemsTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(mySubTestList::addTest); + + //when + List items = mySubTestList.getMyTestListItems(); + assertEquals(testDatas.size(), items.size()); + } + + @Test + void getMyTestListItemWithSelectedIndexTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(mySubTestList::addTest); + int selectedIndex = 2; + + //when + MyTestListItem item = mySubTestList.getMyTestListItem(selectedIndex); + assertEquals(testDatas.get(selectedIndex).getInput(), item.getTestData().getInput()); + assertEquals(testDatas.get(selectedIndex).getOutput(), item.getTestData().getOutput()); + assertEquals(testDatas.get(selectedIndex).getResult(), item.getTestData().getResult()); + } + + @Test + void getMyTestListItemWithNoneSelectTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(mySubTestList::addTest); + int selectedIndex = -1;//select none item + + //when + MyTestListItem item = mySubTestList.getMyTestListItem(selectedIndex); + assertNull(item); + } + + @Test + void getMyTestListItemWithOverIndexTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(mySubTestList::addTest); + int selectedIndex = testDatas.size() + 10; + + //when + MyTestListItem item = mySubTestList.getMyTestListItem(selectedIndex); + assertNull(item); + } +} \ No newline at end of file diff --git a/src/test/java/com/example/pssupporter/ui/list/TestListPanelTest.java b/src/test/java/com/example/pssupporter/ui/list/TestListPanelTest.java new file mode 100644 index 0000000..622c0ad --- /dev/null +++ b/src/test/java/com/example/pssupporter/ui/list/TestListPanelTest.java @@ -0,0 +1,201 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.list; + +import com.example.pssupporter.ui.fake.FakeSubTestList; +import com.example.pssupporter.ui.list.panel.SubTestList; +import com.example.pssupporter.vo.TestData; +import org.junit.jupiter.api.Test; + +import javax.swing.event.ListSelectionListener; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +class TestListPanelTest { + private SubTestList subTestList = new FakeSubTestList(); + private int clickCount = 0; + private ListSelectionListener listener = (e) -> { + clickCount++; + }; + private TestListPanel testListPanel = new MyTestListPanel(subTestList, listener); + + @Test + void addTestDataWithoutParam() { + //given + + //when + testListPanel.addTestData(); + + //then + assertEquals(1, subTestList.getMyTestListItems().size()); + } + + @Test + void addTestDataWithParam() { + //given + String testInput = "testInput"; + String testOutput = "testOutput"; + String testResult = "testResult"; + TestData testData = new TestData(testInput, testOutput, testResult); + + //when + testListPanel.addTestData(testData); + + //then + List items = subTestList.getMyTestListItems(); + assertEquals(1, items.size()); + MyTestListItem item = items.get(0); + assertEquals(testInput, item.getTestData().getInput()); + assertEquals(testOutput, item.getTestData().getOutput()); + assertEquals(testResult, item.getTestData().getResult()); + } + + @Test + void removeTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(subTestList::addTest); + int removeIndex = 2; + + //when + testListPanel.removeTestData(removeIndex); + + //then + List items = subTestList.getMyTestListItems(); + assertEquals(testDatas.size() - 1, items.size()); + for (int i = 0; i < items.size(); i++) { + int index = i >= removeIndex ? i + 1 : i; + assertEquals(testDatas.get(index).getInput(), items.get(i).getTestData().getInput()); + assertEquals(testDatas.get(index).getOutput(), items.get(i).getTestData().getOutput()); + assertEquals(testDatas.get(index).getResult(), items.get(i).getTestData().getResult()); + } + } + + @Test + void removeOutOfIndexTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(subTestList::addTest); + int removeIndex = testDatas.size() + 10; + + //when + testListPanel.removeTestData(removeIndex); + + //then + List items = subTestList.getMyTestListItems(); + assertEquals(testDatas.size(), items.size()); + for (int i = 0; i < items.size(); i++) { + assertEquals(testDatas.get(i).getInput(), items.get(i).getTestData().getInput()); + assertEquals(testDatas.get(i).getOutput(), items.get(i).getTestData().getOutput()); + assertEquals(testDatas.get(i).getResult(), items.get(i).getTestData().getResult()); + } + } + + @Test + void removeAllTests() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(subTestList::addTest); + + //when + testListPanel.removeAllTestDatas(); + + //then + assertEquals(0, subTestList.getMyTestListItems().size()); + } + + @Test + void getMyTestListItemsTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(subTestList::addTest); + + //when + List items = testListPanel.getMyTestListItems(); + assertEquals(testDatas.size(), items.size()); + } + + @Test + void getMyTestListItemWithSelectedIndexTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(subTestList::addTest); + int selectedIndex = 2; + + //when + MyTestListItem item = testListPanel.getMyTestList(selectedIndex); + assertEquals(testDatas.get(selectedIndex).getInput(), item.getTestData().getInput()); + assertEquals(testDatas.get(selectedIndex).getOutput(), item.getTestData().getOutput()); + assertEquals(testDatas.get(selectedIndex).getResult(), item.getTestData().getResult()); + } + + @Test + void getMyTestListItemWithNoneSelectTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(subTestList::addTest); + int selectedIndex = -1;//select none item + + //when + MyTestListItem item = testListPanel.getMyTestList(selectedIndex); + assertNull(item); + } + + @Test + void getMyTestListItemWithOverIndexTest() { + //given + List testDatas = List.of( + new TestData("0", "0", "0") + , new TestData("1", "1", "1") + , new TestData("2", "2", "2") + , new TestData("3", "3", "3") + , new TestData("4", "4", "4") + , new TestData("2", "2", "2")); + testDatas.stream().forEach(subTestList::addTest); + int selectedIndex = testDatas.size() + 10; + + //when + MyTestListItem item = testListPanel.getMyTestList(selectedIndex); + assertNull(item); + } +} \ No newline at end of file diff --git a/src/test/java/com/example/pssupporter/ui/main/MainPanelTest.java b/src/test/java/com/example/pssupporter/ui/main/MainPanelTest.java new file mode 100644 index 0000000..03b1468 --- /dev/null +++ b/src/test/java/com/example/pssupporter/ui/main/MainPanelTest.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. + */ + +package com.example.pssupporter.ui.main; + +import com.example.pssupporter.ui.editor.EditorPanel; +import com.example.pssupporter.ui.editor.MyEditorPanel; +import com.example.pssupporter.ui.editor.panel.InputEditorPanel; +import com.example.pssupporter.ui.editor.panel.OutputEditorPanel; +import com.example.pssupporter.ui.editor.panel.ResultEditorPanel; +import com.example.pssupporter.ui.fake.FakeInputEditorPanel; +import com.example.pssupporter.ui.fake.FakeOutputEditorPanel; +import com.example.pssupporter.ui.fake.FakeResultEditorPanel; +import com.example.pssupporter.ui.fake.FakeSubTestList; +import com.example.pssupporter.ui.list.MyTestListPanel; +import com.example.pssupporter.ui.list.TestListPanel; +import com.example.pssupporter.ui.list.panel.SubTestList; +import com.example.pssupporter.vo.TestData; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; + +class MainPanelTest { + + private SubTestList fakeSubTestList = new FakeSubTestList(); + private TestListPanel fakeTestListPanel = new MyTestListPanel(fakeSubTestList, e -> { + }); + private InputEditorPanel fakeInputEditorPanel = new FakeInputEditorPanel(); + private OutputEditorPanel fakeOutputEditorPanel = new FakeOutputEditorPanel(); + private ResultEditorPanel fakeResultEditorPanel = new FakeResultEditorPanel(); + private EditorPanel fakeEditorPanel = new MyEditorPanel(fakeInputEditorPanel, fakeOutputEditorPanel, fakeResultEditorPanel); + private MyMainView myMainView = new MyMainView(fakeTestListPanel, fakeEditorPanel, true); + + @Test + void changeTestDataTest() { + //given + TestData beforeTestData = new TestData("beforeInput", "beforeOutput"); + TestData afterTestData = new TestData("afterInput", "afterOutput"); + fakeTestListPanel.addTestData(beforeTestData); + fakeTestListPanel.addTestData(afterTestData); + fakeSubTestList.setSelectedIndex(0);//Initialize the selection of subTestList to the first data(beforeTestData) + + //when + myMainView.changeTestData(); + + //then + assertEquals(beforeTestData.getInput(), fakeEditorPanel.getInput()); + assertEquals(beforeTestData.getOutput(), fakeEditorPanel.getOutput()); + assertEquals(beforeTestData.getResult(), fakeEditorPanel.getResult()); + + //when + fakeEditorPanel.setInput("changeInputData"); + fakeEditorPanel.setOutput("changeOutputData"); + fakeEditorPanel.setResult("changeResultData"); + fakeSubTestList.setSelectedIndex(1);//change selection of subTestList to the second data(afterTestData) + myMainView.changeTestData(); + + //then + assertEquals("changeInputData", beforeTestData.getInput()); + assertEquals("changeOutputData", beforeTestData.getOutput()); + } + + @Test + void saveAndClearTest() { + //given + TestData testData = new TestData("testInput", "testOutput", "testResult"); + fakeSubTestList.addTest(testData); + fakeSubTestList.setSelectedIndex(0); + myMainView.changeTestData(); + + //when + fakeEditorPanel.setInput("changeInput"); + fakeEditorPanel.setOutput("changeOutput"); + fakeEditorPanel.setResult("changeResult"); + myMainView.saveAndClear(); + + //then + assertEquals("", fakeEditorPanel.getInput()); + assertEquals("", fakeEditorPanel.getOutput()); + assertEquals("", fakeEditorPanel.getResult()); + + assertEquals("changeInput", testData.getInput()); + assertEquals("changeOutput", testData.getOutput()); + } +} diff --git a/src/test/java/com/example/pssupporter/utils/GlobalThreadStoreTest.java b/src/test/java/com/example/pssupporter/utils/MyThreadStoreTest.java similarity index 70% rename from src/test/java/com/example/pssupporter/utils/GlobalThreadStoreTest.java rename to src/test/java/com/example/pssupporter/utils/MyThreadStoreTest.java index fb9e0b0..ca65e1a 100644 --- a/src/test/java/com/example/pssupporter/utils/GlobalThreadStoreTest.java +++ b/src/test/java/com/example/pssupporter/utils/MyThreadStoreTest.java @@ -4,12 +4,9 @@ package com.example.pssupporter.utils; -import com.example.pssupporter.utils.thread.GlobalThreadStore; +import com.example.pssupporter.utils.thread.MyThreadStore; import com.example.pssupporter.utils.thread.vo.ThreadGroupName; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.mockito.Mockito; import java.lang.reflect.Field; @@ -21,7 +18,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -class GlobalThreadStoreTest { +class MyThreadStoreTest { class TestThread extends Thread { private boolean flag = true; @@ -38,45 +35,20 @@ public void interrupt() { } } + private MyThreadStore myThreadStore; + + @BeforeEach + void init() { + myThreadStore = new MyThreadStore(); + } + @AfterEach void shutdownAllExecutor() { Arrays.stream(ThreadGroupName.values()).forEach(tg -> { - GlobalThreadStore.getInstance().getThreadExecutorByName(tg).shutdownNow(); + myThreadStore.getThreadExecutorByName(tg).shutdownNow(); }); } - @Nested - @DisplayName("[GetInstance]") - class GetInstanceTest { - @Test - @DisplayName("Success : Singleton pattern") - void singletonPattern_Success() { - GlobalThreadStore instance1 = GlobalThreadStore.getInstance(); - GlobalThreadStore instance2 = GlobalThreadStore.getInstance(); - - assertEquals(instance1, instance2); - } - - @Test - @DisplayName("Success : Getting an instance") - void getInstance_Success() { - assertNotNull(GlobalThreadStore.getInstance()); - } - - @Test - @DisplayName("Success : Initial instance must have PoolExecutor defined in ThreadGroupName set") - void instanceWithDefinedExecutorInThreadGroupName_Success() { - Arrays.stream(ThreadGroupName.values()).forEach(tg -> { - ThreadPoolExecutor threadPoolExecutor = GlobalThreadStore.getInstance().getThreadExecutorByName(tg); - assertNotNull(threadPoolExecutor); - assertEquals(0, threadPoolExecutor.getActiveCount()); - assertFalse(threadPoolExecutor.isShutdown()); - assertFalse(threadPoolExecutor.isTerminating()); - assertFalse(threadPoolExecutor.isTerminated()); - }); - } - } - @Nested @DisplayName("[GetThreadExecutorByName]") class GetThreadExecutorByNameTest { @@ -84,7 +56,7 @@ class GetThreadExecutorByNameTest { @DisplayName("Success : Getting ThreadExecutor by name") void success() { ThreadGroupName groupName = ThreadGroupName.TEST_RUNNING; - ThreadPoolExecutor threadPoolExecutor = GlobalThreadStore.getInstance().getThreadExecutorByName(groupName); + ThreadPoolExecutor threadPoolExecutor = myThreadStore.getThreadExecutorByName(groupName); assertNotNull(threadPoolExecutor); assertEquals(0, threadPoolExecutor.getActiveCount()); assertFalse(threadPoolExecutor.isTerminated()); @@ -96,8 +68,8 @@ void success() { @DisplayName("Success : Getting same thread executor when executor not shutdowned or terminated") void getSameThreadExecutorWhenWasNotShutdownedOrTerminated_Success() { ThreadGroupName groupName = ThreadGroupName.TEST_RUNNING; - ThreadPoolExecutor threadPoolExecutor1 = GlobalThreadStore.getInstance().getThreadExecutorByName(groupName); - ThreadPoolExecutor threadPoolExecutor2 = GlobalThreadStore.getInstance().getThreadExecutorByName(groupName); + ThreadPoolExecutor threadPoolExecutor1 = myThreadStore.getThreadExecutorByName(groupName); + ThreadPoolExecutor threadPoolExecutor2 = myThreadStore.getThreadExecutorByName(groupName); assertEquals(threadPoolExecutor1, threadPoolExecutor2); } @@ -106,13 +78,13 @@ void getSameThreadExecutorWhenWasNotShutdownedOrTerminated_Success() { @DisplayName("Success : Getting same thread executor when executor working") void getSameThreadExecutorWhenWorking_Success() { ThreadGroupName groupName = ThreadGroupName.TEST_RUNNING; - ThreadPoolExecutor threadPoolExecutor1 = GlobalThreadStore.getInstance().getThreadExecutorByName(groupName); + ThreadPoolExecutor threadPoolExecutor1 = myThreadStore.getThreadExecutorByName(groupName); Thread testThread = new TestThread(); threadPoolExecutor1.execute(testThread); assertEquals(1, threadPoolExecutor1.getActiveCount()); - ThreadPoolExecutor threadPoolExecutor2 = GlobalThreadStore.getInstance().getThreadExecutorByName(groupName); + ThreadPoolExecutor threadPoolExecutor2 = myThreadStore.getThreadExecutorByName(groupName); assertEquals(threadPoolExecutor1, threadPoolExecutor2); assertEquals(1, threadPoolExecutor2.getActiveCount()); @@ -124,8 +96,8 @@ void getSameThreadExecutorWhenWorking_Success() { @Test @DisplayName("Fail : Trying to get with not exist GroupName") void withNotExistGroupName_Failure() throws NoSuchFieldException, IllegalAccessException { - GlobalThreadStore instance = GlobalThreadStore.getInstance(); - Field myThreadStoreField = GlobalThreadStore.class.getDeclaredField("myThreadStore"); + MyThreadStore instance = myThreadStore; + Field myThreadStoreField = MyThreadStore.class.getDeclaredField("myThreadStore"); myThreadStoreField.setAccessible(true); EnumMap origin = (EnumMap) myThreadStoreField.get(instance); try { @@ -155,7 +127,7 @@ class ExecuteThreadsTest { @DisplayName("Success : execute only one thread") void executeOneThread_Success() { ThreadGroupName groupName = ThreadGroupName.TEST_RUNNING; - GlobalThreadStore instance = GlobalThreadStore.getInstance(); + MyThreadStore instance = myThreadStore; TestThread testThread = new TestThread(); instance.executeThreads(groupName, testThread); @@ -173,7 +145,7 @@ void executeLotsOfThreads_Success() { for (int i = 0; i < threads.length; i++) { threads[i] = new TestThread(); } - GlobalThreadStore instance = GlobalThreadStore.getInstance(); + MyThreadStore instance = myThreadStore; ThreadGroupName groupName = ThreadGroupName.TEST_RUNNING; instance.executeThreads(groupName, threads); @@ -189,7 +161,7 @@ class InterruptThreadsTest { @DisplayName("Success : interrupt all threads by groupName") void interruptAllThreads_Success() { ThreadGroupName groupName = ThreadGroupName.TEST_RUNNING; - GlobalThreadStore instance = GlobalThreadStore.getInstance(); + MyThreadStore instance = myThreadStore; ThreadPoolExecutor executor = instance.getThreadExecutorByName(groupName); Thread[] testThreads = new TestThread[10]; @@ -215,7 +187,7 @@ class HasRunningThreadsTest { @Test @DisplayName("Success : Return false when running threads not exist") void returnFalseWhenNotExistRunningThreads_Success() { - GlobalThreadStore instance = GlobalThreadStore.getInstance(); + MyThreadStore instance = myThreadStore; ThreadGroupName groupName = ThreadGroupName.TEST_RUNNING; assertFalse(instance.hasRunningThreads(groupName)); @@ -224,7 +196,7 @@ void returnFalseWhenNotExistRunningThreads_Success() { @Test @DisplayName("Success : Return true when running threads exists") void returnTrueWhenExistsRunningThreads_Success() { - GlobalThreadStore instance = GlobalThreadStore.getInstance(); + MyThreadStore instance = myThreadStore; ThreadGroupName groupName = ThreadGroupName.TEST_RUNNING; instance.executeThreads(groupName, new TestThread()); @@ -235,7 +207,7 @@ void returnTrueWhenExistsRunningThreads_Success() { @Test @DisplayName("Success : Return false when shutdown executor") void returnFalseWhenShutdown_Success() { - GlobalThreadStore instance = GlobalThreadStore.getInstance(); + MyThreadStore instance = myThreadStore; ThreadGroupName groupName = ThreadGroupName.TEST_RUNNING; instance.executeThreads(groupName, new TestThread());