This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Weight(val grams: Int) | |
data class Coffee(val type: Bean, val intensity: Int, val weight: Weight) | |
fun bugPrevention() = println( | |
// Doesn't Compile, integer is not a Weight | |
// Coffee(Bean.ARABICA, 1000, 2) | |
// Also doesn't compile: type mismatch | |
// Coffee(Bean.ARABICA, Weight(1000), 2) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun doStuff() = print(Coffee(Bean.ARABICA, 1000, 2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class Bean { | |
ARABICA, | |
ROBUSTA, | |
BLEND | |
} | |
data class Coffee(val type: Bean, val intensity: Int, val weight: Int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void increased_readability_by_test_data_builder() { | |
Invoice invoice = | |
anInvoice() | |
.from(USA) | |
.with( | |
aPurchasedBook().of(aNovel().costing(50.0)) | |
).build(); | |
assertEquals(56.35, invoice.computeTotalAmount()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
void an_unreadable_test() { | |
Country country = new Country("USA", Currency.US_DOLLAR, Language.ENGLISH); | |
Author author = new Author("Oscar Wilde", country); | |
Novel novel = new Novel( | |
"The picture of dorian gray", | |
50.00, | |
author, | |
Language.ENGLISH, | |
Lists.newArrayList(Genre.MYSTERY) |
NewerOlder