Skip to content

Commit

Permalink
Throw exception on empty name of task, section or mark
Browse files Browse the repository at this point in the history
  • Loading branch information
platan committed Jun 1, 2023
1 parent cc17e35 commit 20c8a3c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@ data class MermaidGanttDiagram(
val entries: List<Entry>
) {
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<Entry> = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
@@ -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 << ['', ' ']
}
}

0 comments on commit 20c8a3c

Please sign in to comment.