Skip to content

Commit 53fe218

Browse files
committed
Change string members to companion constant.
1 parent 1aee568 commit 53fe218

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
0 Bytes
Binary file not shown.

dataprotocol/src/test/java/com/corndog/dataprotocol/DelimProtocolBufferReaderTest.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import java.nio.ByteOrder
99

1010
class DelimProtocolBufferReaderTest {
1111

12-
val strings = arrayOf("hello", "world", "I", "love", "you")
13-
val string = strings.joinToString("\n")
14-
val stringResult = ArrayList<String>()
12+
companion object {
13+
private val STRINGS = arrayOf("hello", "world", "I", "love", "you")
14+
private val STRINGS_CONCAT = arrayOf("hello", "world", "I", "love", "you").joinToString("\n")
15+
}
16+
17+
private val stringResult = ArrayList<String>()
1518

1619
val bufferBig = stringToByteBuffer(ByteOrder.BIG_ENDIAN)
1720
val bufferLittle = stringToByteBuffer(ByteOrder.LITTLE_ENDIAN)
@@ -24,7 +27,7 @@ class DelimProtocolBufferReaderTest {
2427
reader.readByData()
2528

2629
stringResult.forEachIndexed {index, str->
27-
assertEquals(strings[index], str)
30+
assertEquals(STRINGS[index], str)
2831
}
2932

3033
stringResult.clear()
@@ -36,15 +39,15 @@ class DelimProtocolBufferReaderTest {
3639
reader.readByData()
3740

3841
stringResult.forEachIndexed {index, str->
39-
assertEquals(strings[index], str)
42+
assertEquals(STRINGS[index], str)
4043
}
4144

4245
stringResult.clear()
4346
}
4447

4548
private fun stringToByteBuffer(order: ByteOrder): ByteBuffer {
46-
return ByteBuffer.allocate(2 * string.length).also { buffer->
47-
string.toCharArray().forEach {character->
49+
return ByteBuffer.allocate(2 * STRINGS_CONCAT.length).also { buffer->
50+
STRINGS_CONCAT.toCharArray().forEach { character->
4851
buffer.order(order).putChar(character)
4952
}
5053
}

0 commit comments

Comments
 (0)