= listOf("GDG", "Yangon", "DevFest") //Declare expected value val expected = "GDG,Yangon,DevFest" //Declare actual val actual = StringUtils.convertStringListToString(stringList) }
= listOf //Check if two values are equal("GDG", "Yangon", "DevFest") //Declare expected value val expected = "GDG,Yangon,DevFest" //Declare actual val actual = StringUtils.convertStringListToString(stringList) //Check if two values are equal org.junit.Assert.assertEquals(expected, actual) }
= listOf("GDG", "Yangon", "DevFest", "Android") //Declare expected value val expected = "GDG,Yangon,DevFest,Android" //Declare actual val actual = StringUtils.convertStringListToString(stringList) //Check if two values are equal org.junit.Assert.assertEquals(expected, actual) }
= listOf("GDG", "Yangon", "Best") //Declare expected value val expected = "GDG,Yangon,Best" //Declare actual val actual = StringUtils.convertStringListToString(stringList) //Check if two values are equal org.junit.Assert.assertEquals(expected, actual) }
stringList.forEachIndexed { index, string -> stringBuilder.append(string) //If Index is last, we don't append delimiter if (index != stringList.lastIndex) { stringBuilder.append(",") } } return stringBuilder.toString() }
stringList.forEachIndexed { index, string -> stringBuilder.append(string) //If Index is last, we don't append delimiter if (index != stringList.lastIndex) { stringBuilder.append(",") } } return stringBuilder.toString() }
• “Return a constant and gradually replace constants with variables until you have the real code” • Use Obvious Implementation • “Type in the real implementation.” /
= listOf("GDG", "Yangon", "Best") //Declare expected value val expected = "GDG|Yangon|Best" //Declare actual val actual = StringUtils.convertStringListToString(stringList) //Check if two values are equal org.junit.Assert.assertEquals(expected, actual) }
stringList.forEachIndexed { index, string -> stringBuilder.append(string) //If Index is last, we don't append delimiter if (index != stringList.lastIndex) { stringBuilder.append(",") } } return stringBuilder.toString() }
val stringBuilder = StringBuilder() stringList.forEachIndexed { index, string -> stringBuilder.append(string) //If Index is last, we don't append delimiter if (index != stringList.lastIndex) { stringBuilder.append(delimiter) } } return stringBuilder.toString() }
val stringBuilder = StringBuilder() stringList.forEachIndexed { index, string -> stringBuilder.append(string) //If Index is last, we don't append delimiter if (index != stringList.lastIndex) { stringBuilder.append(delimiter) } } return stringBuilder.toString() }
stringBuilder.append(string) //If Index is last, we don't append delimiter if (index != stringList.lastIndex) { stringBuilder.append(delimiter) } } return stringBuilder.toString()
{ override fun getValue(): Int { return 3 } override fun isSomething(): Boolean { return true } } val expected = 9 val getCalculatedValue = GetCalculatedValue() val actual = getCalculatedValue.execute() assertEquals(expected, actual) }
{ override fun getValue(): Int { return 3 } override fun isSomething(): Boolean { return true } } val expected = 9 val getCalculatedValue = GetCalculatedValue() val actual = getCalculatedValue.execute(fakeDataSource) assertEquals(expected, actual) }
{ override fun getValue(): Int { return 3 } override fun isSomething(): Boolean { return false } } val expected = 6 val getCalculatedValue = GetCalculatedValue() val actual = getCalculatedValue.execute(fakeDataSource) assertEquals(expected, actual) }
getValue(): Int { return 3 } override fun isSomething(): Boolean { return true } } val getCalculatedValue = GetCalculatedValue(fakeDataSource) val actual = getCalculatedValue.execute()
val getCalculatedValue = GetCalculatedValue(fakeDataSource) val actual = getCalculatedValue.execute() verify(fakeDataSource, times(1)).isSomething() verify(fakeDataSource, times(1)).getValue() assertEquals(expected, actual) }