Skip to content

Commit

Permalink
Migrate junit.framework.Assert.assertEquals to kotlin.test.assertEquals
Browse files Browse the repository at this point in the history
Also fix some warnings, e.g. shadowed variables.
  • Loading branch information
hiqua committed Jul 25, 2023
1 parent 6b793c7 commit 4127eb2
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package org.isoron.uhabits.acceptance.steps

import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES
import androidx.annotation.StringRes
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.Espresso
Expand All @@ -33,11 +32,11 @@ import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until
import junit.framework.Assert.assertTrue
import org.hamcrest.CoreMatchers
import org.isoron.uhabits.BaseUserInterfaceTest
import org.isoron.uhabits.R
import org.isoron.uhabits.activities.habits.list.ListHabitsActivity
import org.junit.Assert.assertTrue

object CommonSteps : BaseUserInterfaceTest() {
fun pressBack() {
Expand Down Expand Up @@ -148,15 +147,19 @@ object CommonSteps : BaseUserInterfaceTest() {
Screen.LIST_HABITS ->
Espresso.onView(ViewMatchers.withClassName(CoreMatchers.endsWith("ListHabitsRootView")))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))

Screen.SHOW_HABIT ->
Espresso.onView(ViewMatchers.withId(R.id.subtitleCard))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))

Screen.EDIT_HABIT ->
Espresso.onView(ViewMatchers.withId(R.id.questionInput))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))

Screen.SELECT_HABIT_TYPE ->
Espresso.onView(ViewMatchers.withText(R.string.yes_or_no_example))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))

else -> throw IllegalStateException()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ package org.isoron.uhabits.acceptance.steps
import android.os.Build.VERSION.SDK_INT
import androidx.test.uiautomator.UiScrollable
import androidx.test.uiautomator.UiSelector
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.isoron.uhabits.BaseUserInterfaceTest
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue

object WidgetSteps {
@Throws(Exception::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class JavaUserFile(val path: Path) : UserFile {
@Suppress("NewApi")
class JavaFileOpener : FileOpener {
override fun openUserFile(path: String): UserFile {
val path = Paths.get("/tmp/$path")
return JavaUserFile(path)
val resolvedPath = Paths.get("/tmp/$path")
return JavaUserFile(resolvedPath)
}

override fun openResourceFile(path: String): ResourceFile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ internal class Tokenizer(
if (s == null || s.isEmpty()) {
return false
}
if (s[0].toInt() != mCurrent) {
if (s[0].code != mCurrent) {
return false
}
val len = s.length
mStream.mark(len - 1)
for (n in 1 until len) {
val value = mStream.read()
if (value != s[n].toInt()) {
if (value != s[n].code) {
mStream.reset()
return false
}
Expand All @@ -68,10 +68,9 @@ object SQLParser {
private const val STATE_COMMENT_BLOCK = 3

fun parse(stream: InputStream): List<String> {
val buffer = BufferedInputStream(stream)
val commands: MutableList<String> = ArrayList()
val sb = StringBuffer()
buffer.use { buffer ->
BufferedInputStream(stream).use { buffer ->
val tokenizer = Tokenizer(buffer)
var state = STATE_NONE
while (tokenizer.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ fun interface Task {
fun onAttached(runner: TaskRunner) {}
fun onPostExecute() {}
fun onPreExecute() {}
fun onProgressUpdate(value: Int) {}
fun onProgressUpdate(currentPosition: Int) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class HabitListHeader(

repeat(nButtons) { index ->
val date = today.minus(nButtons - index - 1)
val name = fmt.shortWeekdayName(date).toUpperCase()
val name = fmt.shortWeekdayName(date).uppercase()
val number = date.day.toString()

val x = width - (index + 1) * buttonSize + buttonSize / 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

package org.isoron.platform.gui

import junit.framework.Assert.fail
import kotlinx.coroutines.runBlocking
import org.isoron.platform.io.JavaFileOpener
import org.junit.Assert.fail
import org.junit.Test
import java.awt.image.BufferedImage
import java.awt.image.BufferedImage.TYPE_INT_ARGB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
package org.isoron.uhabits.core.commands

import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.isoron.uhabits.core.BaseUnitTest
import org.isoron.uhabits.core.models.Habit
import org.junit.Before
import org.junit.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class ArchiveHabitsCommandTest : BaseUnitTest() {
private lateinit var command: ArchiveHabitsCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.isoron.uhabits.core.commands

import junit.framework.Assert.assertTrue
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.isoron.uhabits.core.BaseUnitTest
Expand All @@ -27,6 +26,7 @@ import org.isoron.uhabits.core.models.Reminder
import org.isoron.uhabits.core.models.WeekdayList
import org.junit.Before
import org.junit.Test
import kotlin.test.assertTrue

class CreateHabitCommandTest : BaseUnitTest() {
private lateinit var command: CreateHabitCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
package org.isoron.uhabits.core.commands

import junit.framework.Assert.assertEquals
import org.isoron.uhabits.core.BaseUnitTest
import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.models.Timestamp
import org.isoron.uhabits.core.utils.DateUtils.Companion.getToday
import org.junit.Before
import org.junit.Test
import kotlin.test.assertEquals

class CreateRepetitionCommandTest : BaseUnitTest() {
private lateinit var command: CreateRepetitionCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
package org.isoron.uhabits.core.commands

import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.isoron.uhabits.core.BaseUnitTest
import org.isoron.uhabits.core.models.Habit
import org.junit.Before
import org.junit.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class UnarchiveHabitsCommandTest : BaseUnitTest() {
private lateinit var command: UnarchiveHabitsCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.isoron.uhabits.core.database

import junit.framework.Assert.assertNull
import org.apache.commons.lang3.builder.EqualsBuilder
import org.apache.commons.lang3.builder.HashCodeBuilder
import org.apache.commons.lang3.builder.ToStringBuilder
Expand All @@ -27,6 +26,7 @@ import org.hamcrest.core.IsEqual.equalTo
import org.isoron.uhabits.core.BaseUnitTest
import org.junit.Before
import org.junit.Test
import kotlin.test.assertNull

class RepositoryTest : BaseUnitTest() {
private lateinit var repository: Repository<ThingRecord>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.isoron.uhabits.core.io

import junit.framework.Assert.assertTrue
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils
import org.isoron.uhabits.core.BaseUnitTest
Expand All @@ -29,8 +28,9 @@ import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.nio.file.Files
import java.util.LinkedList
import java.util.*
import java.util.zip.ZipFile
import kotlin.test.assertTrue

class HabitsCSVExporterTest : BaseUnitTest() {
private lateinit var baseDir: File
Expand Down Expand Up @@ -102,9 +102,8 @@ class HabitsCSVExporterTest : BaseUnitTest() {
private fun assertAbsolutePathExists(s: String) {
val file = File(s)
assertTrue(
String.format("File %s should exist", file.absolutePath),
file.exists()
)
String.format("File %s should exist", file.absolutePath)
) { file.exists() }
}

private fun assertFileAndReferenceAreEqual(s: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.isoron.uhabits.core.io

import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.IsEqual.equalTo
import org.isoron.uhabits.core.BaseUnitTest
Expand All @@ -34,6 +32,8 @@ import org.junit.Before
import org.junit.Test
import java.io.File
import java.io.IOException
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class ImportTest : BaseUnitTest() {
@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
package org.isoron.uhabits.core.models

import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertNull
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.not
import org.hamcrest.MatcherAssert.assertThat
Expand All @@ -31,6 +28,9 @@ import org.junit.rules.ExpectedException
import java.io.IOException
import java.io.StringWriter
import java.util.ArrayList
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNull

class HabitListTest : BaseUnitTest() {
@get:Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
*/
package org.isoron.uhabits.core.models

import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.IsEqual.equalTo
import org.isoron.uhabits.core.BaseUnitTest
import org.isoron.uhabits.core.utils.DateUtils.Companion.getToday
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class HabitTest : BaseUnitTest() {
@get:Rule
Expand All @@ -55,7 +56,7 @@ class HabitTest : BaseUnitTest() {
model.reminder = Reminder(8, 30, WeekdayList(1))
val habit = modelFactory.buildHabit()
habit.copyFrom(model)
assertTrue(habit.isArchived == model.isArchived)
assertEquals(habit.isArchived, model.isArchived)
assertThat(habit.isArchived, `is`(model.isArchived))
assertThat(habit.color, `is`(model.color))
assertThat(habit.frequency, equalTo(model.frequency))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.isoron.uhabits.core.models

import junit.framework.Assert.assertTrue
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.number.IsCloseTo
import org.hamcrest.number.OrderingComparison
Expand All @@ -28,6 +27,7 @@ import org.isoron.uhabits.core.utils.DateUtils.Companion.getToday
import org.junit.Before
import org.junit.Test
import java.util.ArrayList
import kotlin.test.assertTrue

open class BaseScoreListTest : BaseUnitTest() {
protected lateinit var habit: Habit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/
package org.isoron.uhabits.core.models

import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.greaterThan
import org.hamcrest.Matchers.lessThan
import org.isoron.uhabits.core.BaseUnitTest
import org.isoron.uhabits.core.utils.DateUtils.Companion.getToday
import org.junit.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class TimestampTest : BaseUnitTest() {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
package org.isoron.uhabits.core.models

import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.isoron.uhabits.core.BaseUnitTest
import org.junit.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class WeekdayListTest : BaseUnitTest() {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.isoron.uhabits.core.models.sqlite

import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertNull
import org.isoron.uhabits.core.BaseUnitTest.Companion.buildMemoryDatabase
import org.isoron.uhabits.core.database.Repository
import org.isoron.uhabits.core.models.Entry
Expand All @@ -30,6 +28,8 @@ import org.isoron.uhabits.core.models.sqlite.records.EntryRecord
import org.isoron.uhabits.core.utils.DateUtils
import org.junit.Before
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class SQLiteEntryListTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package org.isoron.uhabits.core.models.sqlite

import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.verify
import junit.framework.Assert.assertNull
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.isoron.uhabits.core.BaseUnitTest
Expand All @@ -38,6 +37,7 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import java.util.ArrayList
import kotlin.test.assertNull

class SQLiteHabitListTest : BaseUnitTest() {
@get:Rule
Expand Down
Loading

0 comments on commit 4127eb2

Please sign in to comment.