├── settings.gradle ├── src ├── test │ ├── resources │ │ └── mockito-extensions │ │ │ └── org.mockito.plugins.MockMaker │ └── kotlin │ │ └── nl │ │ └── jovmit │ │ └── katas │ │ ├── sales │ │ ├── CatalogShould.kt │ │ ├── DisplayShould.kt │ │ ├── SalesFeature.kt │ │ └── SaleShould.kt │ │ ├── banking │ │ ├── ClockShould.kt │ │ ├── AccountShould.kt │ │ ├── TransactionRepositoryShould.kt │ │ ├── PrintStatementFeature.kt │ │ └── StatementPrinterShould.kt │ │ ├── legacy │ │ ├── UserContextBuilder.java │ │ ├── ActionsWeeklyReportDefaultCardBuilder.java │ │ ├── InMemoryDefaultCardRepository.java │ │ ├── InMemoryDefaultCardRepositoryShould.java │ │ └── LegacyShould.java │ │ ├── password │ │ └── PasswordVerifierTest.kt │ │ ├── fizzbuzz │ │ └── FizzBuzzTest.kt │ │ ├── string │ │ └── TestCalculate.kt │ │ ├── greet │ │ └── GreetingTest.kt │ │ └── roman │ │ └── RomanConverterTest.kt └── main │ └── kotlin │ └── nl │ └── jovmit │ └── katas │ ├── banking │ ├── Transaction.kt │ ├── Console.kt │ ├── Clock.kt │ ├── BankKataApp.kt │ ├── Account.kt │ ├── TransactionRepository.kt │ └── StatementPrinter.kt │ ├── sales │ ├── Console.kt │ ├── Catalog.kt │ ├── Display.kt │ └── Sale.kt │ ├── legacy │ ├── UserContext.java │ ├── Card.java │ ├── CardsRepository.java │ ├── WeeklyReportedDefaultCard.java │ └── Legacy.java │ ├── string │ └── Calculator.kt │ ├── fizzbuzz │ └── FizzBuzz.kt │ ├── roman │ └── RomanConverter.kt │ ├── password │ └── PasswordVerifier.kt │ └── greet │ └── Greeter.kt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradlew.bat ├── readme.md ├── gradlew └── LICENSE /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'nl.jovmit.katas' 2 | 3 | -------------------------------------------------------------------------------- /src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker: -------------------------------------------------------------------------------- 1 | mock-maker-inline -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mitrejcevski/katas/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/banking/Transaction.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | data class Transaction(val date: String, val amount: Int) 4 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/sales/Console.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.sales 2 | 3 | class Console { 4 | 5 | fun print(message: String) { 6 | println(message) 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/banking/Console.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | open class Console { 4 | 5 | open fun printLine(text: String) { 6 | println(text) 7 | } 8 | } -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/sales/Catalog.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.sales 2 | 3 | class Catalog(private val pricesByBarcode: Map) { 4 | 5 | fun findPrice(barcode: String): String? { 6 | return pricesByBarcode[barcode] 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jun 28 21:01:15 CEST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/sales/Display.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.sales 2 | 3 | class Display(private val console: Console) { 4 | 5 | fun displayPrice(price: String) { 6 | console.print(price) 7 | } 8 | 9 | fun displayProductNotFoundMessage(barcode: String) { 10 | console.print("Product not found for $barcode") 11 | } 12 | 13 | fun displayEmptyBarcodeMessage() { 14 | console.print("Scanning error: empty barcode") 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS-specific files 2 | .DS_Store 3 | 4 | # Compiled class file 5 | *.class 6 | 7 | # Log file 8 | *.log 9 | 10 | # BlueJ files 11 | *.ctxt 12 | 13 | # Mobile Tools for Java (J2ME) 14 | .mtj.tmp/ 15 | 16 | # Package Files # 17 | *.jar 18 | *.war 19 | *.nar 20 | *.ear 21 | *.zip 22 | *.tar.gz 23 | *.rar 24 | 25 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 26 | hs_err_pid* 27 | 28 | .gradle/ 29 | .idea/ 30 | .build/ 31 | build/ 32 | .out/ 33 | out/ -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/banking/Clock.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | import java.time.LocalDate 4 | import java.time.format.DateTimeFormatter 5 | 6 | open class Clock { 7 | 8 | private companion object { 9 | private val DD_MM_YYYY = DateTimeFormatter.ofPattern("dd/MM/yyyy") 10 | } 11 | 12 | open fun todayAsString(): String { 13 | return today().format(DD_MM_YYYY) 14 | } 15 | 16 | protected open fun today(): LocalDate = LocalDate.now() 17 | } 18 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/banking/BankKataApp.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | fun main(args: Array) { 4 | 5 | val clock = Clock() 6 | val transactionRepository = TransactionRepository(clock) 7 | val console = Console() 8 | val statementPrinter = StatementPrinter(console) 9 | val account = Account(transactionRepository, statementPrinter) 10 | 11 | account.deposit(1000) 12 | account.withdraw(400) 13 | account.deposit(100) 14 | account.printStatement() 15 | } -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/banking/Account.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | 4 | class Account(private val transactionRepository: TransactionRepository, 5 | private val statementPrinter: StatementPrinter) { 6 | 7 | fun deposit(amount: Int) { 8 | transactionRepository.addDeposit(amount) 9 | } 10 | 11 | fun withdraw(amount: Int) { 12 | transactionRepository.addWithdraw(amount) 13 | } 14 | 15 | fun printStatement() { 16 | statementPrinter.print(transactionRepository.allTransactions()) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/sales/Sale.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.sales 2 | 3 | class Sale(private val display: Display, 4 | private val catalog: Catalog) { 5 | 6 | fun onBarcode(barcode: String) { 7 | if (barcode.isBlank()) { 8 | display.displayEmptyBarcodeMessage() 9 | return 10 | } 11 | val price = catalog.findPrice(barcode) 12 | if (price == null) { 13 | display.displayProductNotFoundMessage(barcode) 14 | } else { 15 | display.displayPrice(price) 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/sales/CatalogShould.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.sales 2 | 3 | import org.junit.Assert.assertEquals 4 | import org.junit.Before 5 | import org.junit.Test 6 | 7 | class CatalogShould { 8 | 9 | private val pricesByBarcode = mapOf("12345" to "$7.25", "23456" to "$12.50") 10 | 11 | private lateinit var catalog: Catalog 12 | 13 | @Before 14 | fun initialize() { 15 | catalog = Catalog(pricesByBarcode) 16 | } 17 | 18 | @Test 19 | fun findPriceForGivenBarcode() { 20 | assertEquals("$7.25", catalog.findPrice("12345")) 21 | } 22 | } -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/banking/ClockShould.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | import org.junit.Assert.assertEquals 4 | import org.junit.Test 5 | import java.time.LocalDate 6 | 7 | class ClockShould { 8 | 9 | @Test 10 | fun return_todays_date_in_dd_MM_yyyy_format() { 11 | val clock = TestableClock() 12 | 13 | val date = clock.todayAsString() 14 | 15 | assertEquals("24/04/2015", date) 16 | } 17 | 18 | inner class TestableClock : Clock() { 19 | 20 | override fun today(): LocalDate { 21 | return LocalDate.of(2015, 4, 24) 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/legacy/UserContext.java: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.legacy; 2 | 3 | import java.util.UUID; 4 | 5 | class UserContext { 6 | 7 | private boolean isFeatureEnabled; 8 | private UUID userId; 9 | 10 | public UUID getUserId() { 11 | return userId; 12 | } 13 | 14 | boolean isFeatureEnabled() { 15 | return isFeatureEnabled; 16 | } 17 | 18 | public void setFeatureEnabled(boolean isFeatureEnabled) { 19 | this.isFeatureEnabled = isFeatureEnabled; 20 | } 21 | 22 | public void setUserId(UUID userId) { 23 | this.userId = userId; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/banking/TransactionRepository.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | open class TransactionRepository(private val clock: Clock) { 4 | 5 | private val transactions = ArrayList() 6 | 7 | open fun addDeposit(amount: Int) { 8 | val deposit = Transaction(clock.todayAsString(), amount) 9 | transactions.add(deposit) 10 | } 11 | 12 | open fun addWithdraw(amount: Int) { 13 | val withdraw = Transaction(clock.todayAsString(), -amount) 14 | transactions.add(withdraw) 15 | } 16 | 17 | open fun allTransactions(): List { 18 | return transactions.toList() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/legacy/Card.java: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.legacy; 2 | 3 | import java.util.Objects; 4 | 5 | class Card { 6 | 7 | private final String cardName; 8 | 9 | public Card(String cardName) { 10 | this.cardName = cardName; 11 | } 12 | 13 | public String name() { 14 | return cardName; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object o) { 19 | if (this == o) return true; 20 | if (o == null || getClass() != o.getClass()) return false; 21 | Card card = (Card) o; 22 | return Objects.equals(cardName, card.cardName); 23 | } 24 | 25 | @Override 26 | public int hashCode() { 27 | return Objects.hash(cardName); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/legacy/CardsRepository.java: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.legacy; 2 | 3 | import java.util.UUID; 4 | 5 | class CardsRepository { 6 | public void deleteIfExists(UUID userId) { 7 | throw new UnsupportedOperationException("Not Implemented"); 8 | } 9 | 10 | public WeeklyReportedDefaultCard find(UUID userId, String name) { 11 | throw new UnsupportedOperationException("Not Implemented"); 12 | } 13 | 14 | public void save(WeeklyReportedDefaultCard weeklyReportedDefaultCard) { 15 | throw new UnsupportedOperationException("Not Implemented"); 16 | } 17 | 18 | public void delete(UUID userId, Card card) { 19 | throw new UnsupportedOperationException("Not Implemented"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/string/Calculator.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.string 2 | 3 | class Calculator { 4 | 5 | fun calculate(input: String): Int { 6 | val numbers = input.split(",", "\n") 7 | return if (input.isBlank()) 0 else calculateSum(numbers) 8 | } 9 | 10 | private fun calculateSum(numbers: List): Int { 11 | val values = numbers.map { it.trim().toInt() } 12 | requireNoNegativeNumbers(values) 13 | return values.filter { it < 1000 }.sum() 14 | } 15 | 16 | private fun requireNoNegativeNumbers(values: List) { 17 | values.forEach { 18 | if (it.isNegative) { 19 | throw IllegalArgumentException("No negative numbers allowed!") 20 | } 21 | } 22 | } 23 | 24 | private val Int.isNegative: Boolean 25 | get() = this < 0 26 | } 27 | -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/legacy/UserContextBuilder.java: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.legacy; 2 | 3 | import java.util.UUID; 4 | 5 | class UserContextBuilder { 6 | 7 | private boolean isFeatureEnabled; 8 | private UUID userId; 9 | 10 | public static UserContextBuilder aUserContext() { 11 | return new UserContextBuilder(); 12 | } 13 | 14 | public UserContextBuilder withFeatureEnabled() { 15 | this.isFeatureEnabled = true; 16 | return this; 17 | } 18 | 19 | public UserContextBuilder withUserId(UUID userId) { 20 | this.userId = userId; 21 | return this; 22 | } 23 | 24 | public UserContext build() { 25 | UserContext userContext = new UserContext(); 26 | userContext.setUserId(userId); 27 | userContext.setFeatureEnabled(isFeatureEnabled); 28 | return userContext; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/fizzbuzz/FizzBuzz.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.fizzbuzz 2 | 3 | class FizzBuzz { 4 | 5 | fun buildNumbersSequence(input: Int = 0): String { 6 | return if (input == 0) { 7 | buildString { 8 | (1..100).forEach { 9 | append(convertNumber(it)) 10 | append(System.lineSeparator()) 11 | } 12 | } 13 | } else { 14 | convertNumber(input) 15 | } 16 | } 17 | 18 | private fun convertNumber(it: Int): String { 19 | return when { 20 | it % 3 == 0 && it % 5 == 0 -> "FizzBuzz" 21 | it % 3 == 0 || containsDigit(it, 3) -> "Fizz" 22 | it % 5 == 0 || containsDigit(it, 5) -> "Buzz" 23 | else -> it.toString() 24 | } 25 | } 26 | 27 | private fun containsDigit(number: Int, digitToLookFor: Int): Boolean { 28 | var numberValue = number 29 | while (numberValue > 0) { 30 | if (numberValue % 10 == digitToLookFor) 31 | return true 32 | numberValue /= 10 33 | } 34 | return false 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/sales/DisplayShould.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.sales 2 | 3 | import com.nhaarman.mockitokotlin2.verify 4 | import org.junit.Before 5 | import org.junit.Test 6 | import org.junit.runner.RunWith 7 | import org.mockito.Mock 8 | import org.mockito.junit.MockitoJUnitRunner 9 | 10 | @RunWith(MockitoJUnitRunner::class) 11 | class DisplayShould { 12 | 13 | @Mock 14 | private lateinit var console: Console 15 | 16 | private lateinit var display: Display 17 | 18 | @Before 19 | fun initialize() { 20 | display = Display(console) 21 | } 22 | 23 | @Test 24 | fun printPrice() { 25 | val price = "$7.15" 26 | 27 | display.displayPrice(price) 28 | 29 | verify(console).print(price) 30 | } 31 | 32 | @Test 33 | fun printProductNotFound() { 34 | val barcode = "12345" 35 | 36 | display.displayProductNotFoundMessage(barcode) 37 | 38 | verify(console).print("Product not found for $barcode") 39 | } 40 | 41 | @Test 42 | fun printEmptyBarcodeMessage() { 43 | display.displayEmptyBarcodeMessage() 44 | 45 | verify(console).print("Scanning error: empty barcode") 46 | } 47 | } -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/legacy/ActionsWeeklyReportDefaultCardBuilder.java: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.legacy; 2 | 3 | import java.util.UUID; 4 | 5 | class ActionsWeeklyReportDefaultCardBuilder { 6 | 7 | private UUID userId; 8 | private String cardName; 9 | private int timesNotShown; 10 | 11 | public static ActionsWeeklyReportDefaultCardBuilder aWeeklyCard() { 12 | return new ActionsWeeklyReportDefaultCardBuilder(); 13 | } 14 | 15 | public ActionsWeeklyReportDefaultCardBuilder withUserId(UUID userId) { 16 | this.userId = userId; 17 | return this; 18 | } 19 | 20 | public ActionsWeeklyReportDefaultCardBuilder withCardName(String cardName) { 21 | this.cardName = cardName; 22 | return this; 23 | } 24 | 25 | public ActionsWeeklyReportDefaultCardBuilder withTimesNotShown( 26 | int timesNotShown) { 27 | this.timesNotShown = timesNotShown; 28 | return this; 29 | } 30 | 31 | public WeeklyReportedDefaultCard build() { 32 | WeeklyReportedDefaultCard card = 33 | new WeeklyReportedDefaultCard(userId, cardName, 0); 34 | card.setTimesNotShown(timesNotShown); 35 | return card; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/password/PasswordVerifierTest.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.password 2 | 3 | import org.junit.Assert.assertFalse 4 | import org.junit.Assert.assertTrue 5 | import org.junit.Before 6 | import org.junit.Test 7 | 8 | class PasswordVerifierTest { 9 | 10 | private lateinit var verifier: PasswordVerifier 11 | 12 | @Before 13 | fun setup() { 14 | verifier = PasswordVerifier() 15 | } 16 | 17 | @Test(expected = IllegalArgumentException::class) 18 | fun shouldThrowPasswordTooShortException() { 19 | verifier.verify("short") 20 | } 21 | 22 | @Test(expected = IllegalArgumentException::class) 23 | fun passwordShouldHaveAtLeastOneUpperCaseLetter() { 24 | verifier.verify("lowercase") 25 | } 26 | 27 | @Test(expected = IllegalArgumentException::class) 28 | fun passwordShouldHaveAtLeastOneLowerCaseLetter() { 29 | assertFalse(verifier.verify("UPPERCASE")) 30 | } 31 | 32 | @Test(expected = IllegalArgumentException::class) 33 | fun passwordShouldHaveAtLeastOneDigit() { 34 | assertFalse(verifier.verify("camelCase")) 35 | } 36 | 37 | @Test 38 | fun shouldReturnOkWhenAllConditionsMet() { 39 | assertTrue(verifier.verify("longPass1")) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/sales/SalesFeature.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.sales 2 | 3 | import org.junit.Before 4 | import org.junit.Test 5 | import org.junit.runner.RunWith 6 | import org.mockito.Mock 7 | import org.mockito.Mockito.inOrder 8 | import org.mockito.junit.MockitoJUnitRunner 9 | 10 | @RunWith(MockitoJUnitRunner::class) 11 | class SalesFeature { 12 | 13 | @Mock 14 | private lateinit var console: Console 15 | 16 | private val pricesByBarcode = mapOf("12345" to "$7.25", "23456" to "$12.50") 17 | 18 | private lateinit var sale: Sale 19 | 20 | @Before 21 | fun initialize() { 22 | val display = Display(console) 23 | val catalog = Catalog(pricesByBarcode) 24 | sale = Sale(display, catalog) 25 | } 26 | 27 | @Test 28 | fun shouldDisplayPricesForScannedBarcode() { 29 | sale.onBarcode("12345") 30 | sale.onBarcode("23456") 31 | sale.onBarcode("99999") 32 | sale.onBarcode("") 33 | 34 | val inOrder = inOrder(console) 35 | inOrder.verify(console).print("$7.25") 36 | inOrder.verify(console).print("$12.50") 37 | inOrder.verify(console).print("Product not found for 99999") 38 | inOrder.verify(console).print("Scanning error: empty barcode") 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/banking/StatementPrinter.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | import java.text.DecimalFormat 4 | import java.util.concurrent.atomic.AtomicInteger 5 | 6 | open class StatementPrinter(private val console: Console) { 7 | 8 | private companion object { 9 | private const val STATEMENT_HEADER = "DATE | AMOUNT | BALANCE" 10 | private val decimalFormatter = DecimalFormat("#.00") 11 | } 12 | 13 | open fun print(transactions: List) { 14 | console.printLine(STATEMENT_HEADER) 15 | printStatementLines(transactions) 16 | } 17 | 18 | private fun printStatementLines(transactions: List) { 19 | val runningBalance = AtomicInteger(0) 20 | transactions.map { statementLine(it, runningBalance) } 21 | .asReversed() 22 | .forEach(console::printLine) 23 | } 24 | 25 | private fun statementLine(transaction: Transaction, 26 | runningBalance: AtomicInteger): String { 27 | 28 | return with(transaction) { 29 | val formattedRunningBalance = decimalFormatter.format(runningBalance.addAndGet(amount)) 30 | "$date | ${decimalFormatter.format(amount)} | $formattedRunningBalance" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/roman/RomanConverter.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.roman 2 | 3 | class RomanConverter { 4 | 5 | fun convert(input: String): Int { 6 | var result = 0 7 | var index = 0 8 | val romanNumerals = input.toUpperCase() 9 | while (index < romanNumerals.length) { 10 | val currentValue = convertSingleChar(romanNumerals[index]) 11 | if (index + 1 < romanNumerals.length) { 12 | val nextValue = convertSingleChar(romanNumerals[index + 1]) 13 | if (currentValue >= nextValue) { 14 | result += currentValue 15 | } else { 16 | result += (nextValue - currentValue) 17 | index++ 18 | } 19 | } else { 20 | result += currentValue 21 | index++ 22 | } 23 | index++ 24 | } 25 | return result 26 | } 27 | 28 | private fun convertSingleChar(input: Char): Int { 29 | return when (input) { 30 | 'I' -> 1 31 | 'V' -> 5 32 | 'X' -> 10 33 | 'L' -> 50 34 | 'C' -> 100 35 | 'D' -> 500 36 | 'M' -> 1000 37 | else -> 0 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/password/PasswordVerifier.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.password 2 | 3 | class PasswordVerifier { 4 | 5 | companion object { 6 | private const val MIN_PASSWORD_LENGTH_REQUIREMENT = 8 7 | } 8 | 9 | fun verify(password: String): Boolean { 10 | return when { 11 | !password.satisfiesLengthRequirement() -> 12 | throw IllegalArgumentException("Password too short") 13 | !password.containsUpperCase() -> 14 | throw IllegalArgumentException("At least one upper case letter required") 15 | !password.containsLowerCase() -> 16 | throw IllegalArgumentException("At least one lower case letter required") 17 | !password.containsDigit() -> 18 | throw IllegalArgumentException("At least one digit required") 19 | else -> true 20 | } 21 | } 22 | 23 | private fun String.satisfiesLengthRequirement() = 24 | this.length >= MIN_PASSWORD_LENGTH_REQUIREMENT 25 | 26 | private fun String.containsUpperCase() = 27 | this != this.toLowerCase() 28 | 29 | private fun String.containsLowerCase() = 30 | this != this.toUpperCase() 31 | 32 | private fun String.containsDigit() = 33 | this.matches(Regex(".*\\d+.*")) 34 | } 35 | -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/banking/AccountShould.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | import com.nhaarman.mockitokotlin2.given 4 | import com.nhaarman.mockitokotlin2.verify 5 | import org.junit.Before 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | import org.mockito.Mock 9 | import org.mockito.junit.MockitoJUnitRunner 10 | 11 | @RunWith(MockitoJUnitRunner::class) 12 | class AccountShould { 13 | 14 | @Mock 15 | private lateinit var transactionRepository: TransactionRepository 16 | @Mock 17 | private lateinit var statementPrinter: StatementPrinter 18 | 19 | private lateinit var account: Account 20 | 21 | @Before 22 | fun initialize() { 23 | account = Account(transactionRepository, statementPrinter) 24 | } 25 | 26 | @Test 27 | fun store_a_deposit_transaction() { 28 | account.deposit(100) 29 | 30 | verify(transactionRepository).addDeposit(100) 31 | } 32 | 33 | @Test 34 | fun store_a_withdraw_transaction() { 35 | account.withdraw(100) 36 | 37 | verify(transactionRepository).addWithdraw(100) 38 | } 39 | 40 | @Test 41 | fun print_a_statement() { 42 | val transactions: List = listOf(Transaction("12/05/2015", 100)) 43 | given(transactionRepository.allTransactions()).willReturn(transactions) 44 | 45 | account.printStatement() 46 | 47 | verify(statementPrinter).print(transactions) 48 | } 49 | } -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/fizzbuzz/FizzBuzzTest.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.fizzbuzz 2 | 3 | import org.junit.Assert.assertEquals 4 | import org.junit.Before 5 | import org.junit.Test 6 | 7 | class FizzBuzzTest { 8 | 9 | private lateinit var fizzBuzz: FizzBuzz 10 | 11 | @Before 12 | fun setup() { 13 | fizzBuzz = FizzBuzz() 14 | } 15 | 16 | @Test 17 | fun shouldPrintFizzForNumbersDividableBy3InsteadOfNumber() { 18 | assertEquals("Fizz", fizzBuzz.buildNumbersSequence(3)) 19 | assertEquals("Fizz", fizzBuzz.buildNumbersSequence(6)) 20 | } 21 | 22 | @Test 23 | fun shouldPrintBuzzForNumbersDividableBy5InsteadOfNumber() { 24 | assertEquals("Buzz", fizzBuzz.buildNumbersSequence(5)) 25 | assertEquals("Buzz", fizzBuzz.buildNumbersSequence(10)) 26 | } 27 | 28 | @Test 29 | fun shouldPrintFizzBuzzForNumbersDividableByBoth3and5() { 30 | assertEquals("FizzBuzz", fizzBuzz.buildNumbersSequence(15)) 31 | assertEquals("FizzBuzz", fizzBuzz.buildNumbersSequence(30)) 32 | } 33 | 34 | @Test 35 | fun shouldPrintFizzForNumbersContainingDigit3() { 36 | assertEquals("Fizz", fizzBuzz.buildNumbersSequence(13)) 37 | assertEquals("14", fizzBuzz.buildNumbersSequence(14)) 38 | } 39 | 40 | @Test 41 | fun shouldPrintBuzzForNumbersContainingDigit5() { 42 | assertEquals("Buzz", fizzBuzz.buildNumbersSequence(25)) 43 | assertEquals("16", fizzBuzz.buildNumbersSequence(16)) 44 | } 45 | } -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/string/TestCalculate.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.string 2 | 3 | import org.junit.Assert.assertEquals 4 | import org.junit.Before 5 | import org.junit.Test 6 | 7 | class TestCalculate { 8 | 9 | private lateinit var calculator: Calculator 10 | 11 | @Before 12 | fun setup() { 13 | calculator = Calculator() 14 | } 15 | 16 | @Test 17 | fun emptyStringShouldReturnsZero() { 18 | assertEquals(0, calculator.calculate("")) 19 | } 20 | 21 | @Test 22 | fun singleNumberShouldReturnTheValue() { 23 | assertEquals(2, calculator.calculate("2")) 24 | } 25 | 26 | @Test 27 | fun twoComaDelimitedNumbersShouldReturnSum() { 28 | assertEquals(4, calculator.calculate("2,2")) 29 | } 30 | 31 | @Test 32 | fun twoEnterDelimitedNumbersShouldReturnSum() { 33 | assertEquals(4, calculator.calculate("2\n2")) 34 | } 35 | 36 | @Test 37 | fun threeNumbersDelimitedEitherWayShouldReturnSum() { 38 | assertEquals(6, calculator.calculate("1,2,3")) 39 | } 40 | 41 | @Test 42 | fun spacesInNumbersShouldNotNotMakeTroubles() { 43 | assertEquals(6, calculator.calculate("1 , 2, 3")) 44 | } 45 | 46 | @Test(expected = IllegalArgumentException::class) 47 | fun negativeInputThrowsException() { 48 | calculator.calculate("-1,2") 49 | } 50 | 51 | @Test 52 | fun shouldIgnoreNumbersGreaterThenThousand() { 53 | assertEquals(20, calculator.calculate("15,5,1000")) 54 | } 55 | } -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/banking/TransactionRepositoryShould.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | import com.nhaarman.mockitokotlin2.given 4 | import org.hamcrest.core.Is.`is` 5 | import org.junit.Assert.assertThat 6 | import org.junit.Before 7 | import org.junit.Test 8 | import org.junit.runner.RunWith 9 | import org.mockito.Mock 10 | import org.mockito.junit.MockitoJUnitRunner 11 | 12 | @RunWith(MockitoJUnitRunner::class) 13 | class TransactionRepositoryShould { 14 | 15 | @Mock 16 | private lateinit var clock: Clock 17 | private lateinit var transactionRepository: TransactionRepository 18 | 19 | private val today = "12/05/2015" 20 | 21 | @Before 22 | fun initialize() { 23 | transactionRepository = TransactionRepository(clock) 24 | given(clock.todayAsString()).willReturn(today) 25 | } 26 | 27 | @Test 28 | fun create_and_store_a_deposit_transaction() { 29 | transactionRepository.addDeposit(100) 30 | 31 | val transactions = transactionRepository.allTransactions() 32 | 33 | assertThat(transactions.size, `is`(1)) 34 | assertThat(transactions.first(), `is`(Transaction(today, 100))) 35 | } 36 | 37 | @Test 38 | fun create_and_store_a_withdrawal_transaction() { 39 | transactionRepository.addWithdraw(200) 40 | 41 | val transactions = transactionRepository.allTransactions() 42 | 43 | assertThat(transactions.size, `is`(1)) 44 | assertThat(transactions.first(), `is`(Transaction(today, -200))) 45 | } 46 | } -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/sales/SaleShould.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.sales 2 | 3 | import com.nhaarman.mockitokotlin2.given 4 | import com.nhaarman.mockitokotlin2.verify 5 | import org.junit.Before 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | import org.mockito.Mock 9 | import org.mockito.junit.MockitoJUnitRunner 10 | 11 | @RunWith(MockitoJUnitRunner::class) 12 | class SaleShould { 13 | 14 | @Mock 15 | private lateinit var catalog: Catalog 16 | @Mock 17 | private lateinit var display: Display 18 | 19 | private val barcode = "1234" 20 | private val price = "$7.15" 21 | private val productNotFound = null 22 | 23 | private lateinit var sale: Sale 24 | 25 | @Before 26 | fun initialize() { 27 | sale = Sale(display, catalog) 28 | } 29 | 30 | @Test 31 | fun displayPriceForGivenBarcode() { 32 | given(catalog.findPrice(barcode)).willReturn(price) 33 | 34 | sale.onBarcode(barcode) 35 | 36 | verify(display).displayPrice(price) 37 | } 38 | 39 | @Test 40 | fun displayProductNotFoundErrorMessageForUnknownBarcode() { 41 | given(catalog.findPrice(barcode)).willReturn(productNotFound) 42 | 43 | sale.onBarcode(barcode) 44 | 45 | verify(display).displayProductNotFoundMessage(barcode) 46 | } 47 | 48 | @Test 49 | fun displayEmptyBarcodeMessage() { 50 | val emptyBarcode = "" 51 | 52 | sale.onBarcode(emptyBarcode) 53 | 54 | verify(display).displayEmptyBarcodeMessage() 55 | } 56 | } -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/banking/PrintStatementFeature.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | import com.nhaarman.mockitokotlin2.given 4 | import com.nhaarman.mockitokotlin2.inOrder 5 | import org.junit.Before 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | import org.mockito.Mock 9 | import org.mockito.junit.MockitoJUnitRunner 10 | 11 | @RunWith(MockitoJUnitRunner::class) 12 | class PrintStatementFeature { 13 | 14 | @Mock 15 | private lateinit var console: Console 16 | @Mock 17 | private lateinit var clock: Clock 18 | 19 | private lateinit var account: Account 20 | 21 | @Before 22 | fun initialize() { 23 | val transactionRepository = TransactionRepository(clock) 24 | val statementPrinter = StatementPrinter(console) 25 | account = Account(transactionRepository, statementPrinter) 26 | } 27 | 28 | @Test 29 | fun printStatementContainingAllTransactions() { 30 | given(clock.todayAsString()).willReturn("01/04/2014", "02/04/2014", "10/04/2014") 31 | 32 | account.deposit(1000) 33 | account.withdraw(100) 34 | account.deposit(500) 35 | account.printStatement() 36 | 37 | val inOrder = inOrder(console) 38 | inOrder.verify(console).printLine("DATE | AMOUNT | BALANCE") 39 | inOrder.verify(console).printLine("10/04/2014 | 500.00 | 1400.00") 40 | inOrder.verify(console).printLine("02/04/2014 | -100.00 | 900.00") 41 | inOrder.verify(console).printLine("01/04/2014 | 1000.00 | 1000.00") 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/legacy/InMemoryDefaultCardRepository.java: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.legacy; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.UUID; 6 | import java.util.stream.Collectors; 7 | 8 | class InMemoryDefaultCardRepository extends CardsRepository { 9 | 10 | private List cards = new ArrayList<>(); 11 | 12 | @Override 13 | public void deleteIfExists(UUID userId) { 14 | List matchingItems = cards.stream() 15 | .filter(it -> it.getUserId().equals(userId)) 16 | .collect(Collectors.toList()); 17 | cards.removeAll(matchingItems); 18 | } 19 | 20 | @Override 21 | public WeeklyReportedDefaultCard find(UUID userId, String name) { 22 | return cards.stream() 23 | .filter(it -> it.getUserId().equals(userId) && 24 | it.getName().equals(name)) 25 | .findFirst() 26 | .orElse(null); 27 | } 28 | 29 | @Override 30 | public void save(WeeklyReportedDefaultCard weeklyReportedDefaultCard) { 31 | cards.add(weeklyReportedDefaultCard); 32 | } 33 | 34 | @Override 35 | public void delete(UUID userId, Card card) { 36 | List matchingItems = cards.stream() 37 | .filter(it -> it.getUserId().equals(userId) && 38 | it.getCardType().equals(card)) 39 | .collect(Collectors.toList()); 40 | cards.removeAll(matchingItems); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/greet/GreetingTest.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.greet 2 | 3 | import org.junit.Assert.assertEquals 4 | import org.junit.Before 5 | import org.junit.Test 6 | 7 | class GreetingTest { 8 | 9 | private lateinit var greeter: Greeter 10 | 11 | @Before 12 | fun setup() { 13 | greeter = Greeter() 14 | } 15 | 16 | @Test 17 | fun shouldReturnGreetingForGivenName() { 18 | assertEquals("Hello, Bob.", greeter.greet("Bob")) 19 | } 20 | 21 | @Test 22 | fun shouldReturnGeneralGreetForGivenEmptyName() { 23 | assertEquals("Hello, my friend.", greeter.greet("")) 24 | } 25 | 26 | @Test 27 | fun shouldReturnShoutingForGivenShoutingName() { 28 | assertEquals("HELLO JERRY!", greeter.greet("JERRY")) 29 | } 30 | 31 | @Test 32 | fun shouldReturnGreetingForBothWhenTwoNamesProvided() { 33 | assertEquals("Hello, Jill and Jane.", greeter.greet("Jill", "Jane")) 34 | } 35 | 36 | @Test 37 | fun shouldReturnGreetingForAllCommaSeparatedWhenMoreThenTwoNamesGiven() { 38 | assertEquals("Hello, Amy, Brain, and Charlotte.", greeter.greet("Amy", "Brain", "Charlotte")) 39 | } 40 | 41 | @Test 42 | fun shouldReturnMixedGreetingForShoutedAndNonShoutedGivenNames() { 43 | assertEquals("Hello, Amy and Charlotte. AND HELLO BRIAN!", greeter.greet("Amy", "BRIAN", "Charlotte")) 44 | } 45 | 46 | @Test 47 | fun shouldAutomaticallySplitCommaSeparatedNames() { 48 | assertEquals("Hello, Bob, Charlie, and Dianne.", greeter.greet("Bob", "Charlie, Dianne")) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/legacy/WeeklyReportedDefaultCard.java: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.legacy; 2 | 3 | import java.util.Objects; 4 | import java.util.UUID; 5 | 6 | class WeeklyReportedDefaultCard { 7 | 8 | private final UUID userId; 9 | private final String name; 10 | private final int initialCount; 11 | private int timesNotShown; 12 | 13 | public WeeklyReportedDefaultCard(UUID userId, String name, int initialCount) { 14 | this.userId = userId; 15 | this.name = name; 16 | this.initialCount = initialCount; 17 | } 18 | 19 | public UUID getUserId() { 20 | return userId; 21 | } 22 | 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | public int getNoTimesShown() { 28 | return timesNotShown; 29 | } 30 | 31 | public void setTimesNotShown(int timesNotShown) { 32 | this.timesNotShown = timesNotShown; 33 | } 34 | 35 | public Card getCardType() { 36 | return new Card(name); 37 | } 38 | 39 | @Override 40 | public boolean equals(Object o) { 41 | if (this == o) return true; 42 | if (o == null || getClass() != o.getClass()) return false; 43 | WeeklyReportedDefaultCard that = (WeeklyReportedDefaultCard) o; 44 | return initialCount == that.initialCount && 45 | Objects.equals(userId, that.userId) && 46 | Objects.equals(name, that.name) && 47 | Objects.equals(timesNotShown, that.timesNotShown); 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | return Objects.hash(userId, name, initialCount, timesNotShown); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/legacy/InMemoryDefaultCardRepositoryShould.java: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.legacy; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | 6 | import java.util.UUID; 7 | 8 | import static nl.jovmit.katas.legacy.ActionsWeeklyReportDefaultCardBuilder.aWeeklyCard; 9 | import static org.junit.Assert.assertEquals; 10 | import static org.junit.Assert.assertNull; 11 | 12 | public class InMemoryDefaultCardRepositoryShould { 13 | 14 | 15 | private static final UUID USER_ID = UUID.randomUUID(); 16 | private static final String CARD_NAME = "::irrelevant card name::"; 17 | private static final String ANOTHER_CARD_NAME = "::another irrelevant card name::"; 18 | 19 | private CardsRepository repository; 20 | private WeeklyReportedDefaultCard cardToSave; 21 | 22 | @Before 23 | public void initialize() { 24 | repository = new InMemoryDefaultCardRepository(); 25 | cardToSave = aWeeklyCard().withUserId(USER_ID).withCardName(CARD_NAME).build(); 26 | repository.save(cardToSave); 27 | } 28 | 29 | @Test 30 | public void save_new_card() { 31 | assertEquals(cardToSave, repository.find(USER_ID, CARD_NAME)); 32 | } 33 | 34 | @Test 35 | public void delete_cards_by_user_id() { 36 | WeeklyReportedDefaultCard anotherCardToSave = aWeeklyCard() 37 | .withUserId(USER_ID) 38 | .withCardName(ANOTHER_CARD_NAME) 39 | .build(); 40 | repository.save(anotherCardToSave); 41 | 42 | repository.deleteIfExists(USER_ID); 43 | 44 | assertNull(repository.find(USER_ID, CARD_NAME)); 45 | } 46 | 47 | @Test 48 | public void delete_cards_by_user_id_and_card_type() { 49 | Card card = new Card(CARD_NAME); 50 | 51 | repository.delete(USER_ID, card); 52 | 53 | assertNull(repository.find(USER_ID, CARD_NAME)); 54 | } 55 | } -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/roman/RomanConverterTest.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.roman 2 | 3 | import org.junit.Assert.assertEquals 4 | import org.junit.Before 5 | import org.junit.Test 6 | 7 | class RomanConverterTest { 8 | 9 | private lateinit var converter: RomanConverter 10 | 11 | @Before 12 | fun setUp() { 13 | converter = RomanConverter() 14 | } 15 | 16 | @Test 17 | fun shouldConvertTheIToOne() { 18 | assertEquals(1, converter.convert("I")) 19 | } 20 | 21 | @Test 22 | fun shouldConvertTheVToFive() { 23 | assertEquals(5, converter.convert("V")) 24 | } 25 | 26 | @Test 27 | fun shouldConvertTheXToTen() { 28 | assertEquals(10, converter.convert("X")) 29 | } 30 | 31 | @Test 32 | fun shouldConvertTheLToFifty() { 33 | assertEquals(50, converter.convert("L")) 34 | } 35 | 36 | @Test 37 | fun shouldConvertTheCToHundred() { 38 | assertEquals(100, converter.convert("C")) 39 | } 40 | 41 | @Test 42 | fun shouldConvertTheDToHundred() { 43 | assertEquals(500, converter.convert("D")) 44 | } 45 | 46 | @Test 47 | fun shouldConvertTheMToThousand() { 48 | assertEquals(1000, converter.convert("M")) 49 | } 50 | 51 | @Test 52 | fun shouldReturnSumForProvidedSameValueInRow() { 53 | assertEquals(2, converter.convert("II")) 54 | assertEquals(20, converter.convert("XX")) 55 | } 56 | 57 | @Test 58 | fun shouldReturnSumForProvidedSmallerValueAfterLargerValue() { 59 | assertEquals(6, converter.convert("VI")) 60 | assertEquals(21, converter.convert("XXI")) 61 | } 62 | 63 | @Test 64 | fun shouldReturnSubtractWhenSmallerValuePrecedeBiggerValue() { 65 | assertEquals(4, converter.convert("IV")) 66 | assertEquals(19, converter.convert("IXX")) 67 | } 68 | 69 | @Test 70 | fun shouldReturnCorrectValueForGivenInput() { 71 | assertEquals(2006, converter.convert("MMVI")) 72 | assertEquals(1944, converter.convert("MCMXLIV")) 73 | } 74 | } -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/banking/StatementPrinterShould.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.banking 2 | 3 | import com.nhaarman.mockitokotlin2.inOrder 4 | import com.nhaarman.mockitokotlin2.verify 5 | import org.junit.Before 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | import org.mockito.Mock 9 | import org.mockito.junit.MockitoJUnitRunner 10 | 11 | @RunWith(MockitoJUnitRunner::class) 12 | class StatementPrinterShould { 13 | 14 | @Mock 15 | private lateinit var console: Console 16 | 17 | private val noTransactions: List = emptyList() 18 | private lateinit var statementPrinter: StatementPrinter 19 | 20 | @Before 21 | fun initialize() { 22 | statementPrinter = StatementPrinter(console) 23 | } 24 | 25 | @Test 26 | fun always_print_the_header() { 27 | statementPrinter.print(noTransactions) 28 | 29 | verify(console).printLine("DATE | AMOUNT | BALANCE") 30 | } 31 | 32 | @Test 33 | fun print_transactions_in_reverse_chronological_order() { 34 | val transactions = transactionsContaining( 35 | deposit("01/04/2014", 1000), 36 | withdraw("02/04/2014", 100), 37 | deposit("10/04/2014", 500) 38 | ) 39 | statementPrinter.print(transactions) 40 | 41 | val inOrder = inOrder(console) 42 | inOrder.verify(console).printLine("DATE | AMOUNT | BALANCE") 43 | inOrder.verify(console).printLine("10/04/2014 | 500.00 | 1400.00") 44 | inOrder.verify(console).printLine("02/04/2014 | -100.00 | 900.00") 45 | inOrder.verify(console).printLine("01/04/2014 | 1000.00 | 1000.00") 46 | } 47 | 48 | private fun transactionsContaining(vararg transactions: Transaction): List { 49 | return transactions.toList() 50 | } 51 | 52 | private fun withdraw(date: String, amount: Int): Transaction { 53 | return Transaction(date, -amount) 54 | } 55 | 56 | private fun deposit(date: String, amount: Int): Transaction { 57 | return Transaction(date, amount) 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/greet/Greeter.kt: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.greet 2 | 3 | class Greeter { 4 | 5 | fun greet(vararg names: String): String { 6 | val parsed = parseInput(names) 7 | return when (parsed.size) { 8 | 0 -> "Hello, my friend." 9 | 1 -> greetingForSingleInput(parsed) 10 | 2 -> "Hello, ${names.first()} and ${names.last()}." 11 | else -> makeComplexGreeting(parsed.toTypedArray()) 12 | } 13 | } 14 | 15 | private fun greetingForSingleInput(parsed: List): String { 16 | val name = parsed.last() 17 | return if (name.toUpperCase() == name) "HELLO $name!" 18 | else "Hello, ${parsed.last()}." 19 | } 20 | 21 | private fun makeComplexGreeting(input: Array): String { 22 | val defaultNames = input.filter { it.toUpperCase() != it }.toTypedArray() 23 | val shoutedNames = input.filter { it.toUpperCase() == it } 24 | return buildString { 25 | appendGreetingForDefaultNames(defaultNames) 26 | if (shoutedNames.isNotEmpty()) { 27 | appendGreetingForShoutedNames(shoutedNames) 28 | } 29 | } 30 | } 31 | 32 | private fun StringBuilder.appendGreetingForShoutedNames(shoutedNames: List) { 33 | append(" AND HELLO ") 34 | if (shoutedNames.size > 1) { 35 | for (index in 0 until shoutedNames.size - 1) { 36 | if (index > 0) { 37 | append(",") 38 | } 39 | append(" ${shoutedNames[index]}") 40 | } 41 | append(" AND ${shoutedNames.last()}!") 42 | } else { 43 | append("${shoutedNames.last()}!") 44 | } 45 | } 46 | 47 | private fun StringBuilder.appendGreetingForDefaultNames(defaultNames: Array) { 48 | if (defaultNames.size == 2) { 49 | append(greet(*defaultNames)) 50 | } else { 51 | append("Hello, ") 52 | for (index in 0 until defaultNames.size - 1) { 53 | append("${defaultNames[index]}, ") 54 | } 55 | append("and ${defaultNames.last()}.") 56 | } 57 | } 58 | 59 | private fun parseInput(names: Array) = 60 | names.flatMap { it.split(",") } 61 | .map { it.trim() } 62 | .filter { it.isNotBlank() } 63 | } 64 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /src/main/kotlin/nl/jovmit/katas/legacy/Legacy.java: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.legacy; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.UUID; 6 | 7 | class Legacy { 8 | 9 | private static final List WEEKLY_REPORTED_DEFAULT_CARDS = Collections.emptyList(); 10 | private static final int TOP_PRIORITY_INDEX = 0; 11 | private static final int INITIAL_COUNT = 0; 12 | private static final int MAX_TIMES_NOT_SHOWN = 0; 13 | 14 | private final CardsRepository cardsRepository; 15 | private final List weeklyDefaultCards; 16 | 17 | public Legacy(CardsRepository repository) { 18 | this(repository, WEEKLY_REPORTED_DEFAULT_CARDS); 19 | } 20 | 21 | public Legacy(CardsRepository repository, 22 | List weeklyDefaultCards) { 23 | this.cardsRepository = repository; 24 | this.weeklyDefaultCards = weeklyDefaultCards; 25 | } 26 | 27 | public void validateThenUpdateDefaultCard( 28 | UserContext userContext, 29 | List configuredActionCardsInOrder) { 30 | if (validate(userContext, configuredActionCardsInOrder)) { 31 | updateDefaultCard(userContext, configuredActionCardsInOrder); 32 | } 33 | } 34 | 35 | private boolean validate(UserContext userContext, List configuredActionCardsInOrder) { 36 | return userContext.isFeatureEnabled() && !configuredActionCardsInOrder.isEmpty(); 37 | } 38 | 39 | private void updateDefaultCard(UserContext userContext, List configuredActionCardsInOrder) { 40 | final UUID userId = userContext.getUserId(); 41 | if (!weeklyDefaultCards.contains(configuredActionCardsInOrder.get(TOP_PRIORITY_INDEX).name())) { 42 | cardsRepository.deleteIfExists(userId); 43 | } else { 44 | promoteNewWeeklyCard(userContext, configuredActionCardsInOrder, userId); 45 | } 46 | } 47 | 48 | private void promoteNewWeeklyCard(UserContext userContext, List configuredActionCardsInOrder, UUID userId) { 49 | Card defaultCardConfigured = configuredActionCardsInOrder.get(TOP_PRIORITY_INDEX); 50 | WeeklyReportedDefaultCard weeklyReportedDefaultCard = 51 | cardsRepository.find(userId, defaultCardConfigured.name()); 52 | if (weeklyReportedDefaultCard == null) { 53 | promoteDefaultCardFor(userId, defaultCardConfigured); 54 | } else if (weeklyReportedDefaultCard.getNoTimesShown() == MAX_TIMES_NOT_SHOWN) { 55 | cardsRepository.delete(userId, weeklyReportedDefaultCard.getCardType()); 56 | configuredActionCardsInOrder.remove(TOP_PRIORITY_INDEX); 57 | validateThenUpdateDefaultCard(userContext, configuredActionCardsInOrder); 58 | } 59 | } 60 | 61 | private void promoteDefaultCardFor(UUID userId, Card defaultCardConfigured) { 62 | cardsRepository.deleteIfExists(userId); 63 | WeeklyReportedDefaultCard weeklyReportedDefaultCard = 64 | new WeeklyReportedDefaultCard(userId, defaultCardConfigured.name(), INITIAL_COUNT); 65 | cardsRepository.save(weeklyReportedDefaultCard); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/kotlin/nl/jovmit/katas/legacy/LegacyShould.java: -------------------------------------------------------------------------------- 1 | package nl.jovmit.katas.legacy; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.UUID; 10 | 11 | import static nl.jovmit.katas.legacy.ActionsWeeklyReportDefaultCardBuilder.aWeeklyCard; 12 | import static org.junit.Assert.assertEquals; 13 | import static org.junit.Assert.assertNull; 14 | 15 | public class LegacyShould { 16 | 17 | private static final UUID USER_ID = UUID.randomUUID(); 18 | private static final String CARD_NAME = "::irrelevant card name::"; 19 | private static final String FIRST_CARD_NAME = "::card 1::"; 20 | private static final String SECOND_CARD_NAME = "::card 2::"; 21 | 22 | private UserContext userContext = UserContextBuilder.aUserContext() 23 | .withUserId(USER_ID) 24 | .withFeatureEnabled() 25 | .build(); 26 | private Card card1 = new Card(FIRST_CARD_NAME); 27 | private Card card2 = new Card(SECOND_CARD_NAME); 28 | private List configuredCardsInOrder = new ArrayList() {{ 29 | add(card1); 30 | add(card2); 31 | }}; 32 | 33 | private CardsRepository repository = new InMemoryDefaultCardRepository(); 34 | private Legacy legacy; 35 | 36 | @Before 37 | public void setUp() { 38 | List weeklyDefaultCards = Arrays.asList(FIRST_CARD_NAME, SECOND_CARD_NAME); 39 | legacy = new Legacy(repository, weeklyDefaultCards); 40 | } 41 | 42 | @Test 43 | public void delete_by_user_id_when_weekly_cards_collection_does_not_contain_top_priority_card() { 44 | Legacy legacy = new Legacy(repository); 45 | 46 | legacy.validateThenUpdateDefaultCard(userContext, configuredCardsInOrder); 47 | 48 | assertNull(repository.find(USER_ID, CARD_NAME)); 49 | } 50 | 51 | @Test 52 | public void save_new_weekly_default_card() { 53 | WeeklyReportedDefaultCard weeklyCard = aWeeklyCard() 54 | .withCardName(FIRST_CARD_NAME) 55 | .withUserId(USER_ID) 56 | .build(); 57 | 58 | legacy.validateThenUpdateDefaultCard(userContext, configuredCardsInOrder); 59 | 60 | assertEquals(weeklyCard, repository.find(USER_ID, FIRST_CARD_NAME)); 61 | } 62 | 63 | @Test 64 | public void remove_old_weekly_reported_default_card() { 65 | WeeklyReportedDefaultCard oldWeeklyCard = aWeeklyCard() 66 | .withUserId(USER_ID) 67 | .withCardName(CARD_NAME) 68 | .build(); 69 | repository.save(oldWeeklyCard); 70 | 71 | legacy.validateThenUpdateDefaultCard(userContext, configuredCardsInOrder); 72 | 73 | assertNull(repository.find(USER_ID, CARD_NAME)); 74 | } 75 | 76 | @Test 77 | public void do_nothing_when_weekly_default_card_not_shown_times_differs_from_default() { 78 | int differentThanDefault = 5; 79 | WeeklyReportedDefaultCard weeklyCard = aWeeklyCard() 80 | .withUserId(USER_ID) 81 | .withCardName(FIRST_CARD_NAME) 82 | .withTimesNotShown(differentThanDefault) 83 | .build(); 84 | repository.save(weeklyCard); 85 | 86 | legacy.validateThenUpdateDefaultCard(userContext, configuredCardsInOrder); 87 | 88 | assertEquals(weeklyCard, repository.find(USER_ID, FIRST_CARD_NAME)); 89 | } 90 | 91 | @Test 92 | public void delete_weekly_default_card_when_times_not_shown_is_same_as_default() { 93 | int sameAsDefault = 0; 94 | WeeklyReportedDefaultCard weeklyCard = aWeeklyCard() 95 | .withUserId(USER_ID) 96 | .withCardName(FIRST_CARD_NAME) 97 | .withTimesNotShown(sameAsDefault) 98 | .build(); 99 | repository.save(weeklyCard); 100 | 101 | legacy.validateThenUpdateDefaultCard(userContext, configuredCardsInOrder); 102 | 103 | assertNull(repository.find(USER_ID, FIRST_CARD_NAME)); 104 | } 105 | 106 | @Test 107 | public void remove_top_priority_record_from_configured_cards_in_order() { 108 | int sameAsDefault = 0; 109 | WeeklyReportedDefaultCard weeklyCard = aWeeklyCard() 110 | .withUserId(USER_ID) 111 | .withCardName(FIRST_CARD_NAME) 112 | .withTimesNotShown(sameAsDefault) 113 | .build(); 114 | repository.save(weeklyCard); 115 | 116 | legacy.validateThenUpdateDefaultCard(userContext, configuredCardsInOrder); 117 | 118 | assertEquals(1, configuredCardsInOrder.size()); 119 | assertEquals(SECOND_CARD_NAME, configuredCardsInOrder.get(0).name()); 120 | } 121 | 122 | @Test 123 | public void promote_new_card() { 124 | WeeklyReportedDefaultCard currentWeeklyCard = aWeeklyCard() 125 | .withUserId(USER_ID) 126 | .withCardName(FIRST_CARD_NAME) 127 | .build(); 128 | repository.save(currentWeeklyCard); 129 | 130 | WeeklyReportedDefaultCard newWeeklyCard = aWeeklyCard() 131 | .withUserId(USER_ID) 132 | .withCardName(SECOND_CARD_NAME) 133 | .build(); 134 | 135 | legacy.validateThenUpdateDefaultCard(userContext, configuredCardsInOrder); 136 | 137 | assertEquals(newWeeklyCard, repository.find(USER_ID, SECOND_CARD_NAME)); 138 | } 139 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Kata's 2 | 3 | ## Description 4 | A project containing Kata`s for practicing TDD using Kotlin. Each kata has its own package, and each exercise goals are described below. 5 | 6 | #### 1. String Calculator 7 | ##### package name: `string` 8 | 1. An empty string returns zero 9 | 2. A single number returns the value 10 | 3. Two numbers, comma delimited, returns the sum 11 | 4. Two numbers, new line delimited, returns the sum 12 | 5. Three numbers, delimited either way, returns the sum 13 | 6. Negative numbers throw an exception 14 | 7. Numbers greater then 1000 are ignored 15 | 16 | #### 2. Password Verifier 17 | ##### package name: `password` 18 | 1. Password should be larger than 8 chars 19 | 2. Password should have one uppercase letter at least 20 | 3. Password should have one lowercase letter at least 21 | 4. Password should have one number at least 22 | 5. Each one of these should throw an exception with a different message of your choosing 23 | 6. Password is OK if the previous conditions are satisfied 24 | 25 | #### 3. Greeter 26 | ##### package name `greet` 27 | 1. Should return greeting for given name: 28 | input ```"name"``` 29 | output ```Hello, name.``` 30 | 2. Should return generic greeting when no or empty name provided: 31 | input ```"" or null``` 32 | output ```Hello, my fiend``` 33 | 3. Should return shouting greeting when shouting name provided: 34 | input ```"NAME"``` 35 | output ```HELLO NAME!``` 36 | 4. Should return greeting for both when two names provided: 37 | input ```"name1", "name2"``` 38 | output ```Hello, name1 and name2.``` 39 | 5. Should return greeting for all when more than two names provided: 40 | input ```"name1", "name2", "name3"``` 41 | output ```Hello, name1, name2 and name3.``` 42 | 6. Should return greeting when mixing shouting names with normal names: 43 | input ```"name1", "NAME2", "name3"``` 44 | output ```Hello, name1 and name3. AND HELLO NAME2!``` 45 | 7. Should return greeting when coma separated names provided as input: 46 | input ```"name1", "name2, name3"``` 47 | output ```Hello, name1, name2, and name3.``` 48 | 49 | #### 4. FizzBuzz 50 | ##### package name `fizzbuzz` 51 | 1. Should print numbers from 1 to 100 52 | 2. For the multiples of 3 print `Fizz` instead of the number 53 | 3. For the multiples of 5 print `Buzz` instead of the number 54 | 4. For the multiples of both 3 and 5 print `FizzBuzz` instead of the number 55 | 5. A number is `Fizz` if it is dividable by 3 or if it contains 3 inside 56 | 6. A number is `Buzz` if it is dividable by 5 or if it contains 5 inside 57 | 58 | #### 5. Roman to decimal numbers 59 | ##### package name `roman` 60 | Converter to resolve input from Roman numerals into decimal. The values of the roman numerals are shown in the following table. 61 | 62 | | Symbol | Value | 63 | |:------:|:-----:| 64 | | I | 1 | 65 | | V | 5 | 66 | | X | 10 | 67 | | L | 50 | 68 | | C | 100 | 69 | | D | 500 | 70 | | M | 100 | 71 | 72 | Numbers are formed by combining symbols together and adding the values. Generally, symbols are placed in order of value, starting with the largest values. When smaller values precede larger values, the smaller values are subtracted from the larger values, and the result is added to the total: 73 | 74 | | Roman Number | Computation | Value | Comment | 75 | |:------------:|:-----------------------------------------:|:-----:|:-------: | 76 | |IV | 5 - 1 | 4 | only subtraction | 77 | |VI | 5 + 1 | 6 | only addition | 78 | |MMVI | 1000 + 1000 + 5 + 1 | 2006 | only addition | 79 | |MCMXLIV | 1000 + (1000 - 100) + (50 - 10) + (5 - 1) | 1944 | addition and subtraction | 80 | 81 | #### 6. Banking Kata 82 | ##### package name `banking` 83 | Simple bank application with the following features 84 | 85 | - Deposit into Account 86 | - Withdraw from an Account 87 | - Print the Account statement to the console 88 | 89 | Statement should have transactions in the following format: 90 | 91 | DATE | AMOUNT | BALANCE 92 | 10/04/2014 | 500.00 | 1400.00 93 | 02/04/2014 | -100.00 | 900.00 94 | 01/04/2014 | 1000.00 | 1000.00 95 | 96 | Constraints: 97 | 1. Start with a class with the following structure 98 | 99 | ``` 100 | public class Account { 101 | 102 | public void deposit(int amount) 103 | 104 | public void withdraw(int amount) 105 | 106 | public void printStatement() 107 | } 108 | ``` 109 | 2. You are not allowed to add any other public methods in this class 110 | 3. Use Strings and Integers for dates and amounts (keep it simple) 111 | 4. Don't worry about the spacing in the statement printed in the console 112 | 113 | #### 6. Point of sale Kata 114 | ##### package name `sales` 115 | Simple app for scanning bar codes to sell products 116 | 117 | ##### Stage 1 - Sell one item 118 | Scanning a barcode should display its price 119 | 120 | - Barcode '12345' should display price '$7.25' 121 | - Barcode '23456' should display price '$12.50' 122 | - Barcode '99999' should display 'Error: barcode not found' 123 | - Empty barcode should display 'Error: empty barcode' 124 | 125 | ##### Stage 2 - Sell multiple items 126 | 127 | - Introduce a concept of scanning multiple items 128 | - Introduce a concept of `total` command that would display the sum of the scanned products 129 | 130 | #### 7. Refactoring legacy code 131 | ##### package name `legacy` 132 | Legacy code that has to be improved. We have to make the code better while making sure 133 | we preserve the same behaviour. The idea is to cover the legacy code with tests to make sure we won't break its functionality, and once we are confident we can start refactoring, use as much as possible automated refactoring and minimise the manual refactoring for extra safety. 134 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------