mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 19:29:54 +01:00
Convert tests from Hamcrest -> AssertK.
This commit is contained in:
committed by
Greyson Parrelli
parent
33c918defd
commit
1509e3ed79
@@ -8,19 +8,25 @@ package org.thoughtcrime.securesms.conversation
|
||||
import android.app.Application
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import assertk.all
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.hasSize
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isNotNull
|
||||
import assertk.assertions.isNull
|
||||
import assertk.assertions.prop
|
||||
import assertk.assertions.single
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.thoughtcrime.securesms.assertIs
|
||||
import org.thoughtcrime.securesms.assertIsNull
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList.BodyRange
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList.BodyRange.Style
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(manifest = Config.NONE, application = Application::class)
|
||||
class MessageStylerTest {
|
||||
|
||||
private lateinit var text: Spannable
|
||||
|
||||
@Before
|
||||
@@ -33,21 +39,23 @@ class MessageStylerTest {
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 0, 5)
|
||||
MessageStyler.toggleStyle(Style.ITALIC, text, 10, 15)
|
||||
|
||||
val bodyRange = MessageStyler.getStyling(text)!!
|
||||
val bodyRange = MessageStyler.getStyling(text)
|
||||
|
||||
bodyRange.ranges.size assertIs 2
|
||||
|
||||
bodyRange.ranges[0].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 0
|
||||
length assertIs 5
|
||||
}
|
||||
|
||||
bodyRange.ranges[1].apply {
|
||||
style assertIs Style.ITALIC
|
||||
start assertIs 10
|
||||
length assertIs 5
|
||||
}
|
||||
assertThat(bodyRange)
|
||||
.isNotNull()
|
||||
.transform {
|
||||
assertThat(it.ranges).hasSize(2)
|
||||
assertThat(it.ranges[0]).all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(0)
|
||||
prop(BodyRange::length).isEqualTo(5)
|
||||
}
|
||||
assertThat(it.ranges[1]).all {
|
||||
prop(BodyRange::style).isEqualTo(Style.ITALIC)
|
||||
prop(BodyRange::start).isEqualTo(10)
|
||||
prop(BodyRange::length).isEqualTo(5)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,21 +63,23 @@ class MessageStylerTest {
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 0, 5)
|
||||
MessageStyler.toggleStyle(Style.ITALIC, text, 3, 10)
|
||||
|
||||
val bodyRange = MessageStyler.getStyling(text)!!
|
||||
val bodyRange = MessageStyler.getStyling(text)
|
||||
|
||||
bodyRange.ranges.size assertIs 2
|
||||
|
||||
bodyRange.ranges[0].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 0
|
||||
length assertIs 5
|
||||
}
|
||||
|
||||
bodyRange.ranges[1].apply {
|
||||
style assertIs Style.ITALIC
|
||||
start assertIs 3
|
||||
length assertIs 7
|
||||
}
|
||||
assertThat(bodyRange)
|
||||
.isNotNull()
|
||||
.transform {
|
||||
assertThat(it.ranges).hasSize(2)
|
||||
assertThat(it.ranges[0]).all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(0)
|
||||
prop(BodyRange::length).isEqualTo(5)
|
||||
}
|
||||
assertThat(it.ranges[1]).all {
|
||||
prop(BodyRange::style).isEqualTo(Style.ITALIC)
|
||||
prop(BodyRange::start).isEqualTo(3)
|
||||
prop(BodyRange::length).isEqualTo(7)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,15 +87,17 @@ class MessageStylerTest {
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 3, 10)
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 0, 5)
|
||||
|
||||
val bodyRange = MessageStyler.getStyling(text)!!
|
||||
val bodyRange = MessageStyler.getStyling(text)
|
||||
|
||||
bodyRange.ranges.size assertIs 1
|
||||
|
||||
bodyRange.ranges[0].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 0
|
||||
length assertIs 10
|
||||
}
|
||||
assertThat(bodyRange)
|
||||
.isNotNull()
|
||||
.transform { it.ranges }
|
||||
.single()
|
||||
.all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(0)
|
||||
prop(BodyRange::length).isEqualTo(10)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,15 +105,17 @@ class MessageStylerTest {
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 0, 5)
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 3, 10)
|
||||
|
||||
val bodyRange = MessageStyler.getStyling(text)!!
|
||||
val bodyRange = MessageStyler.getStyling(text)
|
||||
|
||||
bodyRange.ranges.size assertIs 1
|
||||
|
||||
bodyRange.ranges[0].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 0
|
||||
length assertIs 10
|
||||
}
|
||||
assertThat(bodyRange)
|
||||
.isNotNull()
|
||||
.transform { it.ranges }
|
||||
.single()
|
||||
.all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(0)
|
||||
prop(BodyRange::length).isEqualTo(10)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,21 +123,23 @@ class MessageStylerTest {
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 0, 10)
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 4, 6)
|
||||
|
||||
val bodyRange = MessageStyler.getStyling(text)!!
|
||||
val bodyRange = MessageStyler.getStyling(text)
|
||||
|
||||
bodyRange.ranges.size assertIs 2
|
||||
|
||||
bodyRange.ranges[0].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 0
|
||||
length assertIs 4
|
||||
}
|
||||
|
||||
bodyRange.ranges[1].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 6
|
||||
length assertIs 4
|
||||
}
|
||||
assertThat(bodyRange)
|
||||
.isNotNull()
|
||||
.transform {
|
||||
assertThat(it.ranges).hasSize(2)
|
||||
assertThat(it.ranges[0]).all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(0)
|
||||
prop(BodyRange::length).isEqualTo(4)
|
||||
}
|
||||
assertThat(it.ranges[1]).all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(6)
|
||||
prop(BodyRange::length).isEqualTo(4)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,15 +147,17 @@ class MessageStylerTest {
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 4, 6)
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 0, 10)
|
||||
|
||||
val bodyRange = MessageStyler.getStyling(text)!!
|
||||
val bodyRange = MessageStyler.getStyling(text)
|
||||
|
||||
bodyRange.ranges.size assertIs 1
|
||||
|
||||
bodyRange.ranges[0].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 0
|
||||
length assertIs 10
|
||||
}
|
||||
assertThat(bodyRange)
|
||||
.isNotNull()
|
||||
.transform { it.ranges }
|
||||
.single()
|
||||
.all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(0)
|
||||
prop(BodyRange::length).isEqualTo(10)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,7 +167,7 @@ class MessageStylerTest {
|
||||
|
||||
val bodyRange = MessageStyler.getStyling(text)
|
||||
|
||||
bodyRange.assertIsNull()
|
||||
assertThat(bodyRange).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,15 +176,17 @@ class MessageStylerTest {
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 6, 8)
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 0, 10)
|
||||
|
||||
val bodyRange = MessageStyler.getStyling(text)!!
|
||||
val bodyRange = MessageStyler.getStyling(text)
|
||||
|
||||
bodyRange.ranges.size assertIs 1
|
||||
|
||||
bodyRange.ranges[0].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 0
|
||||
length assertIs 10
|
||||
}
|
||||
assertThat(bodyRange)
|
||||
.isNotNull()
|
||||
.transform { it.ranges }
|
||||
.single()
|
||||
.all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(0)
|
||||
prop(BodyRange::length).isEqualTo(10)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,15 +195,17 @@ class MessageStylerTest {
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 6, 8)
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 2, 7)
|
||||
|
||||
val bodyRange = MessageStyler.getStyling(text)!!
|
||||
val bodyRange = MessageStyler.getStyling(text)
|
||||
|
||||
bodyRange.ranges.size assertIs 1
|
||||
|
||||
bodyRange.ranges[0].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 0
|
||||
length assertIs 8
|
||||
}
|
||||
assertThat(bodyRange)
|
||||
.isNotNull()
|
||||
.transform { it.ranges }
|
||||
.single()
|
||||
.all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(0)
|
||||
prop(BodyRange::length).isEqualTo(8)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,20 +213,22 @@ class MessageStylerTest {
|
||||
MessageStyler.toggleStyle(Style.BOLD, text, 0, 10)
|
||||
MessageStyler.clearStyling(text, 3, 7)
|
||||
|
||||
val bodyRange = MessageStyler.getStyling(text)!!
|
||||
val bodyRange = MessageStyler.getStyling(text)
|
||||
|
||||
bodyRange.ranges.size assertIs 2
|
||||
|
||||
bodyRange.ranges[0].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 0
|
||||
length assertIs 3
|
||||
}
|
||||
|
||||
bodyRange.ranges[1].apply {
|
||||
style assertIs Style.BOLD
|
||||
start assertIs 7
|
||||
length assertIs 3
|
||||
}
|
||||
assertThat(bodyRange)
|
||||
.isNotNull()
|
||||
.transform {
|
||||
assertThat(it.ranges).hasSize(2)
|
||||
assertThat(it.ranges[0]).all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(0)
|
||||
prop(BodyRange::length).isEqualTo(3)
|
||||
}
|
||||
assertThat(it.ranges[1]).all {
|
||||
prop(BodyRange::style).isEqualTo(Style.BOLD)
|
||||
prop(BodyRange::start).isEqualTo(7)
|
||||
prop(BodyRange::length).isEqualTo(3)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user