|
| 1 | +package com.mapk.fastkfunction.argumentBucket |
| 2 | + |
| 3 | +import com.mapk.fastkfunction.argumentbucket.ArgumentBucket |
| 4 | +import com.mapk.fastkfunction.argumentbucket.BucketGenerator |
| 5 | +import org.junit.jupiter.api.Assertions.assertEquals |
| 6 | +import org.junit.jupiter.api.Assertions.assertNull |
| 7 | +import org.junit.jupiter.api.Nested |
| 8 | +import org.junit.jupiter.api.Test |
| 9 | + |
| 10 | +private class ArgumentBucketTest { |
| 11 | + private val parameters = ::sample.parameters |
| 12 | + private val bucket: ArgumentBucket = BucketGenerator(parameters, null).generateBucket() |
| 13 | + |
| 14 | + private fun sample(arg1: Short, arg2: Int, arg3: Long): Long = arg1.toLong() + arg2.toLong() + arg3 |
| 15 | + |
| 16 | + @Nested |
| 17 | + inner class SetAndGetTest { |
| 18 | + val index = 1 |
| 19 | + val firstValue = 10 |
| 20 | + val secondValue = 20 |
| 21 | + |
| 22 | + @Test |
| 23 | + fun byKParameter() { |
| 24 | + val param = parameters[index] |
| 25 | + |
| 26 | + assertNull(bucket.set(param, firstValue)) |
| 27 | + assertEquals(firstValue, bucket[param]) |
| 28 | + assertEquals(firstValue, bucket.set(param, secondValue)) |
| 29 | + assertEquals(secondValue, bucket[param]) |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + fun byIndex() { |
| 34 | + assertNull(bucket.set(index, firstValue)) |
| 35 | + assertEquals(firstValue, bucket[index]) |
| 36 | + assertEquals(firstValue, bucket.set(index, secondValue)) |
| 37 | + assertEquals(secondValue, bucket[index]) |
| 38 | + } |
| 39 | + } |
| 40 | +} |
0 commit comments