Skip to content

Commit

Permalink
Updates and comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperancinha committed Sep 30, 2022
1 parent fcd1c76 commit 30184ba
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ cookies.txt

# Logs
tmlog.lck
tmlog*.log
tmlog*.log
2 changes: 2 additions & 0 deletions jeorg-kotlin-masters/jeorg-kotlin-constructor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# PID
.attach_*
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jesperancinha.ktd.java;

import org.hibernate.validator.constraints.Range;

public class Book {

@Range(min = 15, max = 50)
private Long pages;

public Book(Long pages) {
this.pages = pages;
}

public Long getPages() {
return pages;
}

public void setPages(Long pages) {
this.pages = pages;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.jesperancinha.ktd.java;

public class BookBuilder {

private Long pages;

public BookBuilder withPages(Long pages) {
this.pages = pages;
return this;
}

public Book build() {
return new Book(pages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.fasterxml.jackson.module.kotlin.readValue
import io.kotest.matchers.shouldBe
import jakarta.validation.Validation.buildDefaultValidatorFactory
import jakarta.validation.Validator
import org.jesperancinha.ktd.java.BookBuilder
import org.junit.jupiter.api.Test


Expand Down Expand Up @@ -66,4 +67,27 @@ class BookTest {
validate.size.shouldBe(0)
}

@Test
fun `should create Java Book`(){
val book = BookBuilder().withPages(15)

val factory = buildDefaultValidatorFactory()
val validator: Validator = factory.validator

val validate = validator.validate(book)

validate.size.shouldBe(0)
}
@Test
fun `should not create Java Book`(){
val book = BookBuilder().withPages(200).build()

val factory = buildDefaultValidatorFactory()
val validator: Validator = factory.validator

val validate = validator.validate(book)

validate.size.shouldBe(1)
}

}

0 comments on commit 30184ba

Please sign in to comment.