Skip to content

Commit

Permalink
Merge pull request #130 from amosproj/Feature/98-connect-test-report-…
Browse files Browse the repository at this point in the history
…data-to-result-window

Feature/98 connect test report data to result window
  • Loading branch information
lfogarty98 authored Dec 12, 2023
2 parents bc1ee84 + e6f94f1 commit 4399d3f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MutationResult> = mutableListOf()
) {
fun addMutationResult(mutationResult: MutationResult) {
Expand Down Expand Up @@ -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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")),
Expand Down

0 comments on commit 4399d3f

Please sign in to comment.