From 3fc27abe3cc84f9a041d2000fe0ee05462749137 Mon Sep 17 00:00:00 2001 From: Andrea Brighi Date: Thu, 11 May 2023 20:59:17 +0200 Subject: [PATCH] test(desktop): use interface Book in test --- .../desktopdomain/TestBookCopy.kt | 56 ++++++++++--------- .../desktopdomain/TestDesktop.kt | 26 +++++---- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/desktopDomain/src/test/kotlin/com/intelligentbackpack/desktopdomain/TestBookCopy.kt b/desktopDomain/src/test/kotlin/com/intelligentbackpack/desktopdomain/TestBookCopy.kt index d6d0e322..4b8d68d6 100644 --- a/desktopDomain/src/test/kotlin/com/intelligentbackpack/desktopdomain/TestBookCopy.kt +++ b/desktopDomain/src/test/kotlin/com/intelligentbackpack/desktopdomain/TestBookCopy.kt @@ -1,5 +1,6 @@ package com.intelligentbackpack.desktopdomain +import com.intelligentbackpack.desktopdomain.entities.Book import com.intelligentbackpack.desktopdomain.entities.BookCopy import com.intelligentbackpack.desktopdomain.exception.ISBNException import io.kotest.assertions.throwables.shouldThrow @@ -9,35 +10,35 @@ import io.kotest.matchers.shouldBe class TestBookCopy : StringSpec({ val title = "The Lord of the Rings" - val authors = listOf("J. R. R. Tolkien") + val authors = setOf("J. R. R. Tolkien") val rfidCode = "FF:24:3E:C1" val isbn = "978885152159X" + val book = Book.build { + this.isbn = isbn + this.title = title + this.authors = authors + } "Create a book copy with a valid ISBN" { - val bookCopy = BookCopy.build() { - this.isbn = isbn + val bookCopy = BookCopy.build { this.rfidCode = rfidCode - this.title = title - this.authors = authors + this.book = book } - bookCopy.isbn shouldBe isbn + bookCopy.book.isbn shouldBe isbn } "Create a book copy with a valid RFID code" { val bookCopy = BookCopy.build { - this.isbn = isbn this.rfidCode = rfidCode - this.title = title - this.authors = authors + this.book = book } bookCopy.rfidCode shouldBe rfidCode } "Create a book with a not valid ISBN missing a digit" { shouldThrow { - BookCopy.build { + Book.build { this.isbn = "978885152159" - this.rfidCode = rfidCode this.title = title this.authors = authors } @@ -46,9 +47,8 @@ class TestBookCopy : StringSpec({ "Create a book with a not valid ISBN with a letter, not X at the end" { shouldThrow { - BookCopy.build { - this.isbn = "9788851521599" - this.rfidCode = rfidCode + Book.build { + this.isbn = "978885152159A" this.title = title this.authors = authors } @@ -57,9 +57,8 @@ class TestBookCopy : StringSpec({ "Create a book with a not valid ISBN with wrong check digit" { shouldThrow { - BookCopy.build { - this.isbn = "97888515215A0" - this.rfidCode = rfidCode + Book.build { + this.isbn = "9788851521591" this.title = title this.authors = authors } @@ -68,9 +67,8 @@ class TestBookCopy : StringSpec({ "Create a book with an missing title" { shouldThrow { - BookCopy.build() { - this.isbn = isbn - this.rfidCode = rfidCode + Book.build { + this.isbn = "978885152159" this.authors = authors } } @@ -78,19 +76,27 @@ class TestBookCopy : StringSpec({ "Create a book with an missing author" { shouldThrow { - BookCopy.build { - this.isbn = isbn - this.rfidCode = rfidCode + Book.build { + this.isbn = "978885152159" this.title = title } } } + "Create a book with an empty author" { + val anonymousBook = Book.build { + this.isbn = isbn + this.title = title + this.authors = setOf() + } + anonymousBook.authors shouldBe setOf() + } + "Create a book with an empty title" { shouldThrow { - BookCopy.build() { + Book.build { this.isbn = isbn - this.rfidCode = rfidCode + this.title = "" this.authors = authors } } diff --git a/desktopDomain/src/test/kotlin/com/intelligentbackpack/desktopdomain/TestDesktop.kt b/desktopDomain/src/test/kotlin/com/intelligentbackpack/desktopdomain/TestDesktop.kt index 7399169e..a7f10298 100644 --- a/desktopDomain/src/test/kotlin/com/intelligentbackpack/desktopdomain/TestDesktop.kt +++ b/desktopDomain/src/test/kotlin/com/intelligentbackpack/desktopdomain/TestDesktop.kt @@ -1,5 +1,6 @@ package com.intelligentbackpack.desktopdomain +import com.intelligentbackpack.desktopdomain.entities.Book import com.intelligentbackpack.desktopdomain.entities.BookCopy import com.intelligentbackpack.desktopdomain.entities.Desktop import com.intelligentbackpack.desktopdomain.entities.SchoolSupplyTypes @@ -10,11 +11,18 @@ import io.kotest.matchers.shouldBe class TestDesktop : StringSpec({ - val bookCopy = BookCopy.build() { - isbn = "978885152159X" - rfidCode = "FF:24:3E:C1" - title = "The Lord of the Rings" - authors = listOf("J. R. R. Tolkien") + val title = "The Lord of the Rings" + val authors = setOf("J. R. R. Tolkien") + val rfidCode = "FF:24:3E:C1" + val isbn = "978885152159X" + val book = Book.build { + this.isbn = isbn + this.title = title + this.authors = authors + } + val bookCopy = BookCopy.build { + this.rfidCode = rfidCode + this.book = book } "Create a Desktop" { @@ -26,11 +34,9 @@ class TestDesktop : StringSpec({ "Add a School Supply to Desktop" { val desktop = Desktop.create(setOf(bookCopy)) - val bookCopy2 = BookCopy.build() { - isbn = "978885152159X" - rfidCode = "FF:24:3E:C2" - title = "The Lord of the Rings" - authors = listOf("J. R. R. Tolkien") + val bookCopy2 = BookCopy.build { + this.rfidCode = "FF:24:3E:C2" + this.book = book } val newDesktop = desktop.addSchoolSupply(bookCopy2) desktop.schoolSupplies.size shouldBe 1