Skip to content

Commit

Permalink
Change generic assertFails to assertFailure with specific exception
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicDima authored and JakeWharton committed Jan 3, 2025
1 parent 707fa0b commit bae8753
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.jakewharton.mosaic

import assertk.Assert
import assertk.assertFailure as originalAssertFailure
import assertk.assertions.isInstanceOf

inline fun <reified T : Throwable> assertFailure(block: () -> Unit): Assert<T> {
return originalAssertFailure(block).isInstanceOf<T>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import assertk.assertions.isEqualTo
import com.jakewharton.mosaic.Container
import com.jakewharton.mosaic.NodeSnapshots
import com.jakewharton.mosaic.TestFiller
import com.jakewharton.mosaic.assertFailure
import com.jakewharton.mosaic.modifier.Modifier
import com.jakewharton.mosaic.runMosaicTest
import com.jakewharton.mosaic.size
Expand All @@ -13,18 +14,17 @@ import com.jakewharton.mosaic.ui.Layout
import com.jakewharton.mosaic.ui.unit.Constraints
import com.jakewharton.mosaic.ui.unit.IntSize
import kotlin.test.Test
import kotlin.test.assertFails
import kotlinx.coroutines.test.runTest

class AspectRatioTest {
@Test fun aspectRatioNegative() {
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.aspectRatio(-2.0f)
}
}

@Test fun aspectRatioZero() {
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.aspectRatio(0.0f)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import assertk.assertThat
import assertk.assertions.isEqualTo
import com.jakewharton.mosaic.TestChar
import com.jakewharton.mosaic.TestFiller
import com.jakewharton.mosaic.assertFailure
import com.jakewharton.mosaic.modifier.Modifier
import com.jakewharton.mosaic.runMosaicTest
import com.jakewharton.mosaic.s
import com.jakewharton.mosaic.ui.Box
import com.jakewharton.mosaic.ui.unit.IntOffset
import kotlin.test.Test
import kotlin.test.assertFails
import kotlinx.coroutines.test.runTest

class OffsetTest {
Expand Down Expand Up @@ -41,7 +41,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand All @@ -54,7 +55,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand Down Expand Up @@ -87,7 +89,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand All @@ -100,7 +103,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand Down Expand Up @@ -133,7 +137,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand All @@ -146,7 +151,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand Down Expand Up @@ -184,7 +190,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand All @@ -197,7 +204,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand Down Expand Up @@ -230,7 +238,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand All @@ -243,7 +252,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand Down Expand Up @@ -276,7 +286,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand All @@ -289,7 +300,8 @@ class OffsetTest {
TestFiller(modifier = Modifier.size(1))
}
}
assertFails {
// check when going beyond the border of the TextSurface#get
assertFailure<IllegalStateException> {
awaitSnapshot()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import assertk.assertions.isEqualTo
import com.jakewharton.mosaic.Container
import com.jakewharton.mosaic.TestChar
import com.jakewharton.mosaic.TestFiller
import com.jakewharton.mosaic.assertFailure
import com.jakewharton.mosaic.modifier.Modifier
import com.jakewharton.mosaic.runMosaicTest
import com.jakewharton.mosaic.s
import com.jakewharton.mosaic.testIntrinsics
import com.jakewharton.mosaic.ui.Layout
import com.jakewharton.mosaic.ui.unit.Constraints
import kotlin.test.Test
import kotlin.test.assertFails
import kotlinx.coroutines.test.runTest

class PaddingTest {
Expand All @@ -28,7 +28,7 @@ class PaddingTest {
}

@Test fun paddingLeftNegative() {
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.padding(left = -2)
}
}
Expand Down Expand Up @@ -65,7 +65,7 @@ class PaddingTest {
}

@Test fun paddingTopNegative() {
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.padding(top = -2)
}
}
Expand Down Expand Up @@ -104,7 +104,7 @@ class PaddingTest {
}

@Test fun paddingRightNegative() {
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.padding(right = -2)
}
}
Expand Down Expand Up @@ -141,7 +141,7 @@ class PaddingTest {
}

@Test fun paddingBottomNegative() {
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.padding(bottom = -2)
}
}
Expand Down Expand Up @@ -180,7 +180,7 @@ class PaddingTest {
}

@Test fun paddingLeftBottomNegative() {
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.padding(left = -1, bottom = -2)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.jakewharton.mosaic.ConstrainedBox
import com.jakewharton.mosaic.Container
import com.jakewharton.mosaic.Holder
import com.jakewharton.mosaic.NodeSnapshots
import com.jakewharton.mosaic.assertFailure
import com.jakewharton.mosaic.layout.aspectRatio
import com.jakewharton.mosaic.layout.fillMaxHeight
import com.jakewharton.mosaic.layout.fillMaxWidth
Expand All @@ -30,7 +31,6 @@ import com.jakewharton.mosaic.ui.unit.IntOffset
import com.jakewharton.mosaic.ui.unit.IntSize
import kotlin.math.min
import kotlin.test.Test
import kotlin.test.assertFails
import kotlinx.coroutines.test.runTest

class RowColumnTest {
Expand Down Expand Up @@ -182,13 +182,13 @@ class RowColumnTest {

@Test fun testRow_invalidWeight() {
with(RowScopeInstance) {
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.weight(-1.0f)
}
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.weight(Float.NaN)
}
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.weight(Float.NEGATIVE_INFINITY)
}
}
Expand Down Expand Up @@ -341,13 +341,13 @@ class RowColumnTest {

@Test fun testColumn_invalidWeight() {
with(ColumnScopeInstance) {
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.weight(-1.0f)
}
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.weight(Float.NaN)
}
assertFails {
assertFailure<IllegalArgumentException> {
Modifier.weight(Float.NEGATIVE_INFINITY)
}
}
Expand Down

0 comments on commit bae8753

Please sign in to comment.