Add special string for annotation and its processor for only field

Updated std money and add money arithemtic
This commit is contained in:
2020-08-27 21:42:05 +07:00
parent 4dc6ae521c
commit e82fb280ab
8 changed files with 102 additions and 12 deletions

View File

@@ -2,20 +2,21 @@ import com.cubetiqs.libra.moneyutils.Money
import com.cubetiqs.libra.moneyutils.MoneyConfig
import com.cubetiqs.libra.moneyutils.MoneyCurrency
import com.cubetiqs.libra.moneyutils.MoneyExchangeUtils
import com.cubetiqs.libra.moneyutils.plus
import com.cubetiqs.libra.moneyutils.times
import com.cubetiqs.libra.moneyutils.timesAssign
import com.cubetiqs.libra.moneyutils.SpecialStringProcessor
import org.junit.Assert
import org.junit.Test
class MoneyTests {
@Test
fun money_operator_test() {
val money = Money(10.0)
val money2 = Money(20.0)
money *= money
println((money + money2) * money2)
Assert.assertEquals(100.0, money.value, 0.0)
// val money = Money(10.0)
// val money2 = Money(20.0)
// money *= money
// println((money + money2) * money2)
// Assert.assertEquals(100.0, money.value, 0.0)
val test = SpecialStringProcessor().serialize(Money(1.0, " usd "))
println(test)
}
@Test
@@ -47,7 +48,7 @@ class MoneyTests {
.setDeliEqual('=')
.setDeliSplit(';')
MoneyConfig.parse("USD=1,KHR=4000,EUR=0.99")
MoneyConfig.parse("USD:1,KHR=4000,EUR=0.99")
val moneyUsd = Money.ONE
val moneyKhr = Money.create(20000.0, MoneyCurrency.KHR)

View File

@@ -0,0 +1,37 @@
import org.junit.Test
class ObjectTests {
@Test
fun builder_object_test() {
val person = Person
.builder()
.name("Sambo Chea")
.id(10)
.build()
println(person)
}
}
data class Person(val id: Long? = null, val name: String? = null) {
companion object {
fun builder(): PersonBuilder {
return PersonBuilder()
}
}
}
class PersonBuilder {
private var id: Long? = null
private var name: String? = null
fun id(id: Long?) = apply { this.id = id }
fun name(name: String?) = apply { this.name = name }
fun build(): Person {
return Person(id, name)
}
}