mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Use assertThrows instead of ExpectedException
This commit is contained in:
@@ -62,6 +62,7 @@ kotlin {
|
|||||||
implementation("org.hamcrest:hamcrest:2.2")
|
implementation("org.hamcrest:hamcrest:2.2")
|
||||||
implementation("org.apache.commons:commons-io:1.3.2")
|
implementation("org.apache.commons:commons-io:1.3.2")
|
||||||
implementation("org.mockito.kotlin:mockito-kotlin:2.2.11")
|
implementation("org.mockito.kotlin:mockito-kotlin:2.2.11")
|
||||||
|
implementation("org.junit.jupiter:junit-jupiter:5.8.1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,18 +23,13 @@ import org.hamcrest.MatcherAssert.assertThat
|
|||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Rule
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.ExpectedException
|
import java.util.*
|
||||||
import java.util.LinkedList
|
|
||||||
|
|
||||||
class DeleteHabitsCommandTest : BaseUnitTest() {
|
class DeleteHabitsCommandTest : BaseUnitTest() {
|
||||||
private lateinit var command: DeleteHabitsCommand
|
private lateinit var command: DeleteHabitsCommand
|
||||||
private lateinit var selected: LinkedList<Habit>
|
private lateinit var selected: LinkedList<Habit>
|
||||||
|
|
||||||
@get:Rule
|
|
||||||
var thrown = ExpectedException.none()!!
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
|
|||||||
@@ -27,13 +27,10 @@ import org.isoron.uhabits.core.database.Database
|
|||||||
import org.isoron.uhabits.core.database.MigrationHelper
|
import org.isoron.uhabits.core.database.MigrationHelper
|
||||||
import org.isoron.uhabits.core.models.sqlite.SQLModelFactory
|
import org.isoron.uhabits.core.models.sqlite.SQLModelFactory
|
||||||
import org.isoron.uhabits.core.test.HabitFixtures
|
import org.isoron.uhabits.core.test.HabitFixtures
|
||||||
import org.junit.Rule
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.ExpectedException
|
import org.junit.jupiter.api.Assertions.assertThrows
|
||||||
|
|
||||||
class Version22Test : BaseUnitTest() {
|
class Version22Test : BaseUnitTest() {
|
||||||
@get:Rule
|
|
||||||
var exception = ExpectedException.none()!!
|
|
||||||
private lateinit var db: Database
|
private lateinit var db: Database
|
||||||
private lateinit var helper: MigrationHelper
|
private lateinit var helper: MigrationHelper
|
||||||
|
|
||||||
@@ -76,8 +73,8 @@ class Version22Test : BaseUnitTest() {
|
|||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testDisallowNewRepsWithInvalidRef() {
|
fun testDisallowNewRepsWithInvalidRef() {
|
||||||
helper.migrateTo(22)
|
helper.migrateTo(22)
|
||||||
exception.expectMessage(Matchers.containsString("SQLITE_CONSTRAINT"))
|
val exception = assertThrows(java.lang.RuntimeException::class.java) { db.execute("insert into Repetitions(habit, timestamp, value) values (99999, 100, 2)") }
|
||||||
db.execute("insert into Repetitions(habit, timestamp, value) values (99999, 100, 2)")
|
assertThat(exception.message, Matchers.containsString("SQLITE_CONSTRAINT"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -97,10 +94,14 @@ class Version22Test : BaseUnitTest() {
|
|||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testDisallowNullTimestamp() {
|
fun testDisallowNullTimestamp() {
|
||||||
helper.migrateTo(22)
|
helper.migrateTo(22)
|
||||||
exception.expectMessage(Matchers.containsString("SQLITE_CONSTRAINT"))
|
|
||||||
|
val exception = assertThrows(java.lang.RuntimeException::class.java) {
|
||||||
db.execute("insert into Repetitions(habit, value) " + "values (0, 2)")
|
db.execute("insert into Repetitions(habit, value) " + "values (0, 2)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertThat(exception.message, Matchers.containsString("SQLITE_CONSTRAINT"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testRemoveRepetitionsWithNullHabit() {
|
fun testRemoveRepetitionsWithNullHabit() {
|
||||||
@@ -118,10 +119,14 @@ class Version22Test : BaseUnitTest() {
|
|||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testDisallowNullHabit() {
|
fun testDisallowNullHabit() {
|
||||||
helper.migrateTo(22)
|
helper.migrateTo(22)
|
||||||
exception.expectMessage(Matchers.containsString("SQLITE_CONSTRAINT"))
|
|
||||||
|
val exception = assertThrows(java.lang.RuntimeException::class.java) {
|
||||||
db.execute("insert into Repetitions(timestamp, value) " + "values (5, 2)")
|
db.execute("insert into Repetitions(timestamp, value) " + "values (5, 2)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertThat(exception.message, Matchers.containsString("SQLITE_CONSTRAINT"))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testRemoveDuplicateRepetitions() {
|
fun testRemoveDuplicateRepetitions() {
|
||||||
@@ -142,7 +147,11 @@ class Version22Test : BaseUnitTest() {
|
|||||||
fun testDisallowNewDuplicateTimestamps() {
|
fun testDisallowNewDuplicateTimestamps() {
|
||||||
helper.migrateTo(22)
|
helper.migrateTo(22)
|
||||||
db.execute("insert into repetitions(habit, timestamp, value)values (0, 100, 2)")
|
db.execute("insert into repetitions(habit, timestamp, value)values (0, 100, 2)")
|
||||||
exception.expectMessage(Matchers.containsString("SQLITE_CONSTRAINT"))
|
|
||||||
|
val exception = assertThrows(java.lang.RuntimeException::class.java) {
|
||||||
db.execute("insert into repetitions(habit, timestamp, value)values (0, 100, 5)")
|
db.execute("insert into repetitions(habit, timestamp, value)values (0, 100, 5)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assertThat(exception.message, Matchers.containsString("SQLITE_CONSTRAINT"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,19 +22,15 @@ import org.hamcrest.CoreMatchers.equalTo
|
|||||||
import org.hamcrest.CoreMatchers.not
|
import org.hamcrest.CoreMatchers.not
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
import org.hamcrest.MatcherAssert.assertThat
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.junit.Rule
|
import org.junit.Assert.assertThrows
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.ExpectedException
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.StringWriter
|
import java.io.StringWriter
|
||||||
import java.util.ArrayList
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
|
|
||||||
class HabitListTest : BaseUnitTest() {
|
class HabitListTest : BaseUnitTest() {
|
||||||
@get:Rule
|
|
||||||
var thrown = ExpectedException.none()!!
|
|
||||||
private lateinit var habitsArray: ArrayList<Habit>
|
private lateinit var habitsArray: ArrayList<Habit>
|
||||||
private lateinit var activeHabits: HabitList
|
private lateinit var activeHabits: HabitList
|
||||||
private lateinit var reminderHabits: HabitList
|
private lateinit var reminderHabits: HabitList
|
||||||
@@ -173,9 +169,10 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
fun testReorder_withInvalidArguments() {
|
fun testReorder_withInvalidArguments() {
|
||||||
val h1 = habitsArray[0]
|
val h1 = habitsArray[0]
|
||||||
val h2 = fixtures.createEmptyHabit()
|
val h2 = fixtures.createEmptyHabit()
|
||||||
thrown.expect(IllegalArgumentException::class.java)
|
assertThrows(IllegalArgumentException::class.java) {
|
||||||
habitList.reorder(h1, h2)
|
habitList.reorder(h1, h2)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOrder_inherit() {
|
fun testOrder_inherit() {
|
||||||
@@ -235,25 +232,28 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testAdd_withFilteredList() {
|
fun testAdd_withFilteredList() {
|
||||||
thrown.expect(IllegalStateException::class.java)
|
assertThrows(IllegalStateException::class.java) {
|
||||||
activeHabits.add(fixtures.createEmptyHabit())
|
activeHabits.add(fixtures.createEmptyHabit())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testRemove_onFilteredList() {
|
fun testRemove_onFilteredList() {
|
||||||
thrown.expect(IllegalStateException::class.java)
|
assertThrows(IllegalStateException::class.java) {
|
||||||
activeHabits.remove(fixtures.createEmptyHabit())
|
activeHabits.remove(fixtures.createEmptyHabit())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testReorder_onFilteredList() {
|
fun testReorder_onFilteredList() {
|
||||||
val h1 = fixtures.createEmptyHabit()
|
val h1 = fixtures.createEmptyHabit()
|
||||||
val h2 = fixtures.createEmptyHabit()
|
val h2 = fixtures.createEmptyHabit()
|
||||||
thrown.expect(IllegalStateException::class.java)
|
assertThrows(IllegalStateException::class.java) {
|
||||||
activeHabits.reorder(h1, h2)
|
activeHabits.reorder(h1, h2)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
@@ -261,7 +261,8 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
habitList.primaryOrder = HabitList.Order.BY_SCORE_DESC
|
habitList.primaryOrder = HabitList.Order.BY_SCORE_DESC
|
||||||
val h1 = habitsArray[1]
|
val h1 = habitsArray[1]
|
||||||
val h2 = habitsArray[2]
|
val h2 = habitsArray[2]
|
||||||
thrown.expect(IllegalStateException::class.java)
|
assertThrows(IllegalStateException::class.java) {
|
||||||
habitList.reorder(h1, h2)
|
habitList.reorder(h1, h2)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,16 +24,12 @@ import org.hamcrest.core.IsEqual.equalTo
|
|||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.utils.DateUtils.Companion.getToday
|
import org.isoron.uhabits.core.utils.DateUtils.Companion.getToday
|
||||||
import org.junit.Assert.assertNotEquals
|
import org.junit.Assert.assertNotEquals
|
||||||
import org.junit.Rule
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.ExpectedException
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class HabitTest : BaseUnitTest() {
|
class HabitTest : BaseUnitTest() {
|
||||||
@get:Rule
|
|
||||||
val exception = ExpectedException.none()!!
|
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
|
|||||||
@@ -31,17 +31,14 @@ import org.isoron.uhabits.core.models.Reminder
|
|||||||
import org.isoron.uhabits.core.models.WeekdayList
|
import org.isoron.uhabits.core.models.WeekdayList
|
||||||
import org.isoron.uhabits.core.models.sqlite.records.HabitRecord
|
import org.isoron.uhabits.core.models.sqlite.records.HabitRecord
|
||||||
import org.isoron.uhabits.core.test.HabitFixtures
|
import org.isoron.uhabits.core.test.HabitFixtures
|
||||||
import org.junit.Rule
|
import org.junit.Assert.assertThrows
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.rules.ExpectedException
|
|
||||||
import org.mockito.kotlin.mock
|
import org.mockito.kotlin.mock
|
||||||
import org.mockito.kotlin.verify
|
import org.mockito.kotlin.verify
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
|
|
||||||
class SQLiteHabitListTest : BaseUnitTest() {
|
class SQLiteHabitListTest : BaseUnitTest() {
|
||||||
@get:Rule
|
|
||||||
var exception = ExpectedException.none()!!
|
|
||||||
private lateinit var repository: Repository<HabitRecord>
|
private lateinit var repository: Repository<HabitRecord>
|
||||||
private var listener: ModelObservable.Listener = mock()
|
private var listener: ModelObservable.Listener = mock()
|
||||||
private lateinit var habitsArray: ArrayList<Habit>
|
private lateinit var habitsArray: ArrayList<Habit>
|
||||||
@@ -90,9 +87,10 @@ class SQLiteHabitListTest : BaseUnitTest() {
|
|||||||
val habit = modelFactory.buildHabit()
|
val habit = modelFactory.buildHabit()
|
||||||
habitList.add(habit)
|
habitList.add(habit)
|
||||||
verify(listener).onModelChange()
|
verify(listener).onModelChange()
|
||||||
exception.expect(IllegalArgumentException::class.java)
|
assertThrows(IllegalArgumentException::class.java) {
|
||||||
habitList.add(habit)
|
habitList.add(habit)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAdd_withId() {
|
fun testAdd_withId() {
|
||||||
|
|||||||
Reference in New Issue
Block a user