Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
test(desktop): use interface Book in test
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaBrighi committed May 11, 2023
1 parent f92fb17 commit 3fc27ab
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<ISBNException> {
BookCopy.build {
Book.build {
this.isbn = "978885152159"
this.rfidCode = rfidCode
this.title = title
this.authors = authors
}
Expand All @@ -46,9 +47,8 @@ class TestBookCopy : StringSpec({

"Create a book with a not valid ISBN with a letter, not X at the end" {
shouldThrow<ISBNException> {
BookCopy.build {
this.isbn = "9788851521599"
this.rfidCode = rfidCode
Book.build {
this.isbn = "978885152159A"
this.title = title
this.authors = authors
}
Expand All @@ -57,9 +57,8 @@ class TestBookCopy : StringSpec({

"Create a book with a not valid ISBN with wrong check digit" {
shouldThrow<ISBNException> {
BookCopy.build {
this.isbn = "97888515215A0"
this.rfidCode = rfidCode
Book.build {
this.isbn = "9788851521591"
this.title = title
this.authors = authors
}
Expand All @@ -68,29 +67,36 @@ class TestBookCopy : StringSpec({

"Create a book with an missing title" {
shouldThrow<IllegalStateException> {
BookCopy.build() {
this.isbn = isbn
this.rfidCode = rfidCode
Book.build {
this.isbn = "978885152159"
this.authors = authors
}
}
}

"Create a book with an missing author" {
shouldThrow<IllegalStateException> {
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<IllegalStateException> {
BookCopy.build() {
Book.build {
this.isbn = isbn
this.rfidCode = rfidCode
this.title = ""
this.authors = authors
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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" {
Expand All @@ -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
Expand Down

0 comments on commit 3fc27ab

Please sign in to comment.