From 20c8a3c33e5b42904e5e8a1c3f94e276374b0e66 Mon Sep 17 00:00:00 2001 From: Marcin Mielnicki Date: Thu, 1 Jun 2023 21:06:24 +0200 Subject: [PATCH] Throw exception on empty name of task, section or mark --- .../mermaid/core/MermaidGanttDiagram.kt | 20 +++++++-- .../MermaidGanttDiagramBuilderTest.groovy | 42 +++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/core/MermaidGanttDiagramBuilderTest.groovy diff --git a/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/mermaid/core/MermaidGanttDiagram.kt b/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/mermaid/core/MermaidGanttDiagram.kt index 3b8f27f..a3233ac 100644 --- a/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/mermaid/core/MermaidGanttDiagram.kt +++ b/src/main/kotlin/io/github/platan/tests_execution_chart/reporters/mermaid/core/MermaidGanttDiagram.kt @@ -6,9 +6,23 @@ data class MermaidGanttDiagram( val entries: List ) { sealed interface Entry - data class Section(val name: String) : Entry - data class Task(val name: String, val type: String?, val start: Long, val end: Long) : Entry - data class Milestone(val name: String, val timestamp: Long) : Entry + data class Section(val name: String) : Entry { + init { + require(name.isNotBlank()) { "Section name cannot be blank" } + } + } + + data class Task(val name: String, val type: String?, val start: Long, val end: Long) : Entry { + init { + require(name.isNotBlank()) { "Task name cannot be blank" } + } + } + + data class Milestone(val name: String, val timestamp: Long) : Entry { + init { + require(name.isNotBlank()) { "Mark name cannot be blank" } + } + } class MermaidGanttDiagramBuilder { private val entries: MutableList = mutableListOf() diff --git a/src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/core/MermaidGanttDiagramBuilderTest.groovy b/src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/core/MermaidGanttDiagramBuilderTest.groovy new file mode 100644 index 0000000..d5f39d0 --- /dev/null +++ b/src/test/groovy/io/github/platan/tests_execution_chart/reporters/mermaid/core/MermaidGanttDiagramBuilderTest.groovy @@ -0,0 +1,42 @@ +package io.github.platan.tests_execution_chart.reporters.mermaid.core + +import spock.lang.Specification + +class MermaidGanttDiagramBuilderTest extends Specification { + + def "should return error for blank mark name"() { + when: + new MermaidGanttDiagram.MermaidGanttDiagramBuilder().addMilestone(name, 0) + + then: + def e = thrown(IllegalArgumentException) + e.message == 'Mark name cannot be blank' + + where: + name << ['', ' '] + } + + def "should return error for blank task name"() { + when: + new MermaidGanttDiagram.MermaidGanttDiagramBuilder().addTask(name, 'active', 0, 1) + + then: + def e = thrown(IllegalArgumentException) + e.message == 'Task name cannot be blank' + + where: + name << ['', ' '] + } + + def "should return error for blank section name"() { + when: + new MermaidGanttDiagram.MermaidGanttDiagramBuilder().addSection(name) + + then: + def e = thrown(IllegalArgumentException) + e.message == 'Section name cannot be blank' + + where: + name << ['', ' '] + } +}