Cotton code
43 lines · 1.6 KB · KotlinRaw
package com.cottondb.messages.chatimport org.junit.Assert.assertEqualsimport org.junit.Assert.assertNullimport org.junit.Test/** * SEND'S WORDS (the emulator's faults, kept): typed straight after Send, the next message lost its first letters * ("Live message 2" went as "ive message 2"), and two quick taps sent one message twice. The words now leave the * field at the tap. */class ComposerStateTest {    private fun ComposerState.type(text: String) = field.edit { append(text) }    @Test    fun what_is_typed_after_send_is_kept_and_a_second_tap_sends_nothing() {        val c = ComposerState()        c.type("Live message 1")        assertEquals("Live message 1", c.take())        assertEquals("", c.field.text.toString())        // A second tap before the core answers: nothing to send twice.        assertNull(c.take())        // The next message begun at once is the person's, whole, whatever the first send's answer does after.        c.type("Live message 2")        assertEquals("Live message 2", c.field.text.toString())    }    @Test    fun blank_words_are_not_sent_and_a_refused_send_gives_its_words_back_only_to_an_empty_field() {        val c = ComposerState()        c.type("   ")        assertNull(c.take())        c.field.edit { replace(0, length, "") }        c.type("Seven at the usual place?")        val sent = c.take()!!        c.giveBack(sent)        assertEquals("Seven at the usual place?", c.field.text.toString())        val again = c.take()!!        c.type("Something new")        c.giveBack(again)        assertEquals("Something new", c.field.text.toString())    }}