diff --git a/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/MutationTestToolWindowFactory.kt b/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/MutationTestToolWindowFactory.kt index 85de683a..00e2fc3f 100644 --- a/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/MutationTestToolWindowFactory.kt +++ b/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/MutationTestToolWindowFactory.kt @@ -2,6 +2,7 @@ // SPDX-FileCopyrightText: 2023 package com.amos.pitmutationmate.pitmutationmate +import com.amos.pitmutationmate.pitmutationmate.reporting.XMLParser import com.amos.pitmutationmate.pitmutationmate.visualization.BarGraph import com.amos.pitmutationmate.pitmutationmate.visualization.LatestPiTestReport import com.amos.pitmutationmate.pitmutationmate.visualization.LineGraph @@ -10,11 +11,19 @@ import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project import com.intellij.openapi.wm.ToolWindow import com.intellij.openapi.wm.ToolWindowFactory +import com.intellij.ui.components.JBLabel import com.intellij.ui.content.ContentFactory +import javax.swing.JPanel internal class MutationTestToolWindowFactory : ToolWindowFactory, DumbAware { override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { - val latestPiTestReport = ContentFactory.getInstance().createContent(LatestPiTestReport(), "Latest Result", false) + // TODO: fetch most recent results to display (e.g. when opening up the editor and previous Pitest runs are saved) + val lastCoverageReport: XMLParser.CoverageReport? = null + val latestPiTestReport = if (lastCoverageReport == null) { + ContentFactory.getInstance().createContent(displayErrorMessage(), "Latest Result", false) + } else { + ContentFactory.getInstance().createContent(LatestPiTestReport(lastCoverageReport), "Latest Result", false) + } val table = ContentFactory.getInstance().createContent(JTreeTable(), "Mutationtest Coverage", false) val lineChart = ContentFactory.getInstance().createContent(LineGraph(), "Line Chart", false) val barChart = ContentFactory.getInstance().createContent(BarGraph(), "Bar Chart", false) @@ -24,4 +33,19 @@ internal class MutationTestToolWindowFactory : ToolWindowFactory, DumbAware { toolWindow.contentManager.addContent(lineChart) toolWindow.contentManager.addContent(barChart) } + + fun updateReport(toolWindow: ToolWindow, newCoverageReport: XMLParser.CoverageReport) { + toolWindow.contentManager.findContent("Latest Result").component = LatestPiTestReport(newCoverageReport) + } + + private fun displayErrorMessage(): JPanel { + val panel = JPanel() + + // Displaying an error message in the panel + val errorMessage = "No results to display yet." + val errorLabel = JBLabel(errorMessage) + panel.add(errorLabel) + + return panel + } } diff --git a/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/actions/RunConfigurationAction.kt b/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/actions/RunConfigurationAction.kt index 2020f764..0d647ace 100644 --- a/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/actions/RunConfigurationAction.kt +++ b/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/actions/RunConfigurationAction.kt @@ -3,15 +3,20 @@ package com.amos.pitmutationmate.pitmutationmate.actions +import com.amos.pitmutationmate.pitmutationmate.MutationTestToolWindowFactory import com.amos.pitmutationmate.pitmutationmate.configuration.RunConfiguration import com.amos.pitmutationmate.pitmutationmate.configuration.RunConfigurationType import com.amos.pitmutationmate.pitmutationmate.reporting.XMLListener +import com.amos.pitmutationmate.pitmutationmate.reporting.XMLParser import com.intellij.execution.ExecutorRegistry import com.intellij.execution.ProgramRunnerUtil import com.intellij.execution.RunManager import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project +import com.intellij.openapi.wm.ToolWindow +import com.intellij.openapi.wm.ToolWindowManager +import org.jetbrains.kotlin.idea.gradleTooling.get import java.nio.file.Paths abstract class RunConfigurationAction : AnAction() { @@ -37,5 +42,21 @@ abstract class RunConfigurationAction : AnAction() { var xmlListener = XMLListener(dir, editor) xmlListener.listen() } + + // Update visualisation with mock results + // TODO: replace this by real results extracted by the HTMLParser + val toolWindow: ToolWindow? = ToolWindowManager.getInstance(project).getToolWindow("Pitest") + val mutationTestToolWindowFactorySingleton = MutationTestToolWindowFactory() + val coverageReport: XMLParser.CoverageReport = XMLParser.CoverageReport( + lineCoveragePercentage = 80, + lineCoverageTextRatio = "160/200", + mutationCoveragePercentage = 50, + mutationCoverageTextRatio = "100/200", + testStrengthPercentage = 40, + testStrengthTextRatio = "80/200" + ) + if (toolWindow != null) { + mutationTestToolWindowFactorySingleton.updateReport(toolWindow, coverageReport) + } } } diff --git a/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/reporting/XMLParser.kt b/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/reporting/XMLParser.kt index 335fc023..653ef1cb 100644 --- a/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/reporting/XMLParser.kt +++ b/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/reporting/XMLParser.kt @@ -102,6 +102,8 @@ class XMLParser { } data class ResultData( + // placeholder field for coverage report results to be displayed in visualisation + val coverageReport: CoverageReport? = null, val mutationResults: MutableList = mutableListOf() ) { fun addMutationResult(mutationResult: MutationResult) { @@ -129,4 +131,13 @@ class XMLParser { val killingTest: String, val description: String ) + + data class CoverageReport( + val lineCoveragePercentage: Int, + val lineCoverageTextRatio: String, + val mutationCoveragePercentage: Int, + val mutationCoverageTextRatio: String, + val testStrengthPercentage: Int, + val testStrengthTextRatio: String + ) } diff --git a/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/visualization/LatestPiTestReport.kt b/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/visualization/LatestPiTestReport.kt index 7fe98f1d..150fe94c 100644 --- a/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/visualization/LatestPiTestReport.kt +++ b/pitmutationmate/src/main/kotlin/com/amos/pitmutationmate/pitmutationmate/visualization/LatestPiTestReport.kt @@ -4,6 +4,7 @@ package com.amos.pitmutationmate.pitmutationmate.visualization +import com.amos.pitmutationmate.pitmutationmate.reporting.XMLParser import com.intellij.ui.components.JBLabel import com.intellij.ui.components.JBScrollPane import com.intellij.ui.table.JBTable @@ -18,12 +19,21 @@ import javax.swing.ListSelectionModel import javax.swing.table.DefaultTableCellRenderer import javax.swing.table.DefaultTableModel -class LatestPiTestReport : JPanel() { +class LatestPiTestReport( + coverageReport: XMLParser.CoverageReport = XMLParser.CoverageReport( + lineCoveragePercentage = 0, + lineCoverageTextRatio = "", + mutationCoveragePercentage = 0, + mutationCoverageTextRatio = "", + testStrengthPercentage = 0, + testStrengthTextRatio = "" + ) +) : JPanel() { init { - val lineCoverageBar = CustomProgressBar(30, "1/5") - val mutationCoverageBar = CustomProgressBar(50, "3000/30000") - val testStrengthBar = CustomProgressBar(93, "200/2000") + val lineCoverageBar = CustomProgressBar(coverageReport.lineCoveragePercentage, coverageReport.lineCoverageTextRatio) + val mutationCoverageBar = CustomProgressBar(coverageReport.mutationCoveragePercentage, coverageReport.mutationCoverageTextRatio) + val testStrengthBar = CustomProgressBar(coverageReport.testStrengthPercentage, coverageReport.testStrengthTextRatio) val data = arrayOf( arrayOf(getLabel("Class Name"), getLabel("Test.java")),