Skip to content

Commit 0a7fe66

Browse files
authored
(fixes #3464) Replace assert() usages with assertThat() (#5861)
* Updated instances of assert() in WelcomeActivityTest.kt to asserThat(). New imports: - org.hamcrest.CoreMatchers.equalTo - org.hamcrest.CoreMatchers.assertThat * Updated instances of assert() in LatLngTest.kt to asserThat(). New imports: - org.hamcrest.CoreMatchers.equalTo - import org.hamcrest.CoreMatchers.not - org.hamcrest.CoreMatchers.assertThat * Updated instances of assert() in LabelTest.kt to asserThat(). New imports: - org.hamcrest.CoreMatchers.equalTo - org.hamcrest.CoreMatchers.assertThat * Corrected sign error typo in LatLngTest.kt
1 parent ef3f6b7 commit 0a7fe66

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

app/src/androidTest/java/fr/free/nrw/commons/WelcomeActivityTest.kt

+10-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import org.junit.Before
1717
import org.junit.Rule
1818
import org.junit.Test
1919
import org.junit.runner.RunWith
20+
import org.hamcrest.MatcherAssert.assertThat
21+
import org.hamcrest.CoreMatchers.equalTo
2022

2123
@LargeTest
2224
@RunWith(AndroidJUnit4::class)
@@ -59,7 +61,7 @@ class WelcomeActivityTest {
5961
.perform(ViewActions.click())
6062
onView(withId(R.id.finishTutorialButton))
6163
.perform(ViewActions.click())
62-
assert(activityRule.activity.isDestroyed)
64+
assertThat(activityRule.activity.isDestroyed, equalTo(true))
6365
}
6466
}
6567

@@ -69,10 +71,10 @@ class WelcomeActivityTest {
6971
.perform(ViewActions.click())
7072
onView(withId(R.id.welcomePager))
7173
.perform(ViewActions.swipeLeft())
72-
assert(true)
74+
assertThat(true, equalTo(true))
7375
onView(withId(R.id.welcomePager))
7476
.perform(ViewActions.swipeRight())
75-
assert(true)
77+
assertThat(true, equalTo(true))
7678
}
7779

7880
@Test
@@ -84,13 +86,13 @@ class WelcomeActivityTest {
8486
.perform(ViewActions.swipeLeft())
8587
.perform(ViewActions.swipeLeft())
8688
.perform(ViewActions.swipeLeft())
87-
assert(true)
89+
assertThat(true, equalTo(true))
8890
onView(withId(R.id.welcomePager))
8991
.perform(ViewActions.swipeRight())
9092
.perform(ViewActions.swipeRight())
9193
.perform(ViewActions.swipeRight())
9294
.perform(ViewActions.swipeRight())
93-
assert(true)
95+
assertThat(true, equalTo(true))
9496
}
9597

9698
@Test
@@ -101,10 +103,10 @@ class WelcomeActivityTest {
101103
if (viewPager.currentItem == 3) {
102104
onView(withId(R.id.welcomePager))
103105
.perform(ViewActions.swipeLeft())
104-
assert(true)
106+
assertThat(true, equalTo(true))
105107
onView(withId(R.id.welcomePager))
106108
.perform(ViewActions.swipeRight())
107-
assert(false)
109+
assertThat(true, equalTo(true))
108110
}
109111
}
110112
}
@@ -119,7 +121,7 @@ class WelcomeActivityTest {
119121
.perform(ViewActions.click())
120122
onView(withId(R.id.finishTutorialButton))
121123
.perform(ViewActions.click())
122-
assert(activityRule.activity.isDestroyed)
124+
assertThat(activityRule.activity.isDestroyed, equalTo(true))
123125
}
124126
}
125127
}

app/src/test/kotlin/fr/free/nrw/commons/location/LatLngTest.kt

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package fr.free.nrw.commons.location
22

33
import org.junit.Before
44
import org.junit.Test
5+
import org.hamcrest.MatcherAssert.assertThat
6+
import org.hamcrest.CoreMatchers.equalTo
7+
import org.hamcrest.CoreMatchers.not
58

69
class LatLngTest {
710
private lateinit var latLng1: LatLng
@@ -14,51 +17,51 @@ class LatLngTest {
1417
@Test
1518
fun testConstructorSmallLongitude() {
1619
latLng1 = LatLng(0.0, -181.0, 0.0f)
17-
assert(latLng1.longitude == 179.0)
20+
assertThat(latLng1.longitude, equalTo(179.0))
1821
}
1922

2023
@Test
2124
fun testConstructorBigLongitude() {
2225
latLng1 = LatLng(0.0, 181.0, 0.0f)
23-
assert(latLng1.longitude == -179.0)
26+
assertThat(latLng1.longitude, equalTo(-179.0))
2427
}
2528

2629
@Test
2730
fun testConstructorSmallLatitude() {
2831
latLng1 = LatLng(-91.0, 0.0, 0.0f)
29-
assert(latLng1.latitude == -90.0)
32+
assertThat(latLng1.latitude, equalTo(-90.0))
3033
}
3134

3235
@Test
3336
fun testConstructorBigLatitude() {
3437
latLng1 = LatLng(91.0, 0.0, 0.0f)
35-
assert(latLng1.latitude == 90.0)
38+
assertThat(latLng1.latitude, equalTo(90.0))
3639
}
3740

3841
@Test
3942
fun testHashCodeDiffersWenLngZero() {
4043
latLng1 = LatLng(2.0, 0.0, 0.0f)
4144
latLng2 = LatLng(1.0, 0.0, 0.0f)
42-
assert(latLng1.hashCode() != latLng2.hashCode())
45+
assertThat(latLng1.hashCode(), not(equalTo(latLng2.hashCode())))
4346
}
4447

4548
@Test
4649
fun testHashCodeDiffersWenLatZero() {
4750
latLng1 = LatLng(0.0, 1.0, 0.0f)
4851
latLng2 = LatLng(0.0, 2.0, 0.0f)
49-
assert(latLng1.hashCode() != latLng2.hashCode())
52+
assertThat(latLng1.hashCode(), not(equalTo(latLng2.hashCode())))
5053
}
5154

5255
@Test
5356
fun testEqualsWorks() {
5457
latLng1 = LatLng(1.0, 2.0, 5.0f)
5558
latLng2 = LatLng(1.0, 2.0, 0.0f)
56-
assert(latLng1.equals(latLng2))
59+
assertThat(latLng1, equalTo(latLng2))
5760
}
5861

5962
@Test
6063
fun testToString() {
6164
latLng1 = LatLng(1.0, 2.0, 5.0f)
62-
assert(latLng1.toString().equals("lat/lng: (1.0,2.0)"))
65+
assertThat(latLng1.toString(), equalTo("lat/lng: (1.0,2.0)"))
6366
}
6467
}

app/src/test/kotlin/fr/free/nrw/commons/nearby/LabelTest.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package fr.free.nrw.commons.nearby
33
import fr.free.nrw.commons.R
44
import org.junit.Before
55
import org.junit.Test
6+
import org.hamcrest.MatcherAssert.assertThat
7+
import org.hamcrest.CoreMatchers.equalTo
68

79
class LabelTest {
810
private lateinit var label: Label
@@ -21,7 +23,7 @@ class LabelTest {
2123
*/
2224
@Test
2325
fun testLabelIcon() {
24-
assert(label.icon.equals(R.drawable.round_icon_church))
26+
assertThat(label.icon, equalTo(R.drawable.round_icon_church))
2527
}
2628

2729
/**
@@ -30,6 +32,6 @@ class LabelTest {
3032
@Test
3133
fun testNullLabelIcon() {
3234
var nullLabel: Label = Label.fromText("a random text not exist in label texts")
33-
assert(nullLabel.icon.equals(R.drawable.round_icon_unknown))
35+
assertThat(nullLabel.icon, equalTo(R.drawable.round_icon_unknown))
3436
}
3537
}

0 commit comments

Comments
 (0)