|
16 | 16 |
|
17 | 17 | package com.google.firebase.dataconnect.testutil |
18 | 18 |
|
19 | | -import com.google.common.truth.Truth.assertThat |
20 | 19 | import com.google.firebase.dataconnect.testutil.DataConnectBackend.Companion.fromInstrumentationArgument |
| 20 | +import io.kotest.assertions.assertSoftly |
| 21 | +import io.kotest.assertions.throwables.shouldThrow |
| 22 | +import io.kotest.matchers.nulls.shouldBeNull |
| 23 | +import io.kotest.matchers.shouldBe |
| 24 | +import io.kotest.matchers.types.shouldBeSameInstanceAs |
21 | 25 | import java.net.URI |
22 | 26 | import java.net.URL |
23 | 27 | import org.junit.Test |
24 | 28 |
|
25 | 29 | class DataConnectBackendUnitTest { |
26 | 30 |
|
27 | 31 | @Test |
28 | | - fun `fromInstrumentationArgument(null) should return Production`() { |
29 | | - assertThat(fromInstrumentationArgument(null)).isNull() |
| 32 | + fun `fromInstrumentationArgument(null) should return null`() { |
| 33 | + fromInstrumentationArgument(null).shouldBeNull() |
30 | 34 | } |
31 | 35 |
|
32 | 36 | @Test |
33 | 37 | fun `fromInstrumentationArgument('prod') should return Production`() { |
34 | | - assertThat(fromInstrumentationArgument("prod")).isSameInstanceAs(DataConnectBackend.Production) |
| 38 | + fromInstrumentationArgument("prod") shouldBeSameInstanceAs DataConnectBackend.Production |
35 | 39 | } |
36 | 40 |
|
37 | 41 | @Test |
38 | 42 | fun `fromInstrumentationArgument('staging') should return Staging`() { |
39 | | - assertThat(fromInstrumentationArgument("staging")).isSameInstanceAs(DataConnectBackend.Staging) |
| 43 | + fromInstrumentationArgument("staging") shouldBeSameInstanceAs DataConnectBackend.Staging |
40 | 44 | } |
41 | 45 |
|
42 | 46 | @Test |
43 | 47 | fun `fromInstrumentationArgument('autopush') should return Autopush`() { |
44 | | - assertThat(fromInstrumentationArgument("autopush")) |
45 | | - .isSameInstanceAs(DataConnectBackend.Autopush) |
| 48 | + fromInstrumentationArgument("autopush") shouldBeSameInstanceAs DataConnectBackend.Autopush |
46 | 49 | } |
47 | 50 |
|
48 | 51 | @Test |
49 | 52 | fun `fromInstrumentationArgument('emulator') should return Emulator()`() { |
50 | | - assertThat(fromInstrumentationArgument("emulator")).isEqualTo(DataConnectBackend.Emulator()) |
| 53 | + fromInstrumentationArgument("emulator") shouldBe DataConnectBackend.Emulator() |
51 | 54 | } |
52 | 55 |
|
53 | 56 | @Test |
54 | 57 | fun `fromInstrumentationArgument(emulator with host) should return Emulator() with the host`() { |
55 | | - assertThat(fromInstrumentationArgument("emulator:a.b.c")) |
56 | | - .isEqualTo(DataConnectBackend.Emulator(host = "a.b.c")) |
| 58 | + fromInstrumentationArgument("emulator:a.b.c") shouldBe |
| 59 | + DataConnectBackend.Emulator(host = "a.b.c") |
57 | 60 | } |
58 | 61 |
|
59 | 62 | @Test |
60 | 63 | fun `fromInstrumentationArgument(emulator with port) should return Emulator() with the port`() { |
61 | | - assertThat(fromInstrumentationArgument("emulator::9987")) |
62 | | - .isEqualTo(DataConnectBackend.Emulator(port = 9987)) |
| 64 | + fromInstrumentationArgument("emulator::9987") shouldBe DataConnectBackend.Emulator(port = 9987) |
63 | 65 | } |
64 | 66 |
|
65 | 67 | @Test |
66 | 68 | fun `fromInstrumentationArgument(emulator with host and port) should return Emulator() with the host and port`() { |
67 | | - assertThat(fromInstrumentationArgument("emulator:a.b.c:9987")) |
68 | | - .isEqualTo(DataConnectBackend.Emulator(host = "a.b.c", port = 9987)) |
| 69 | + fromInstrumentationArgument("emulator:a.b.c:9987") shouldBe |
| 70 | + DataConnectBackend.Emulator(host = "a.b.c", port = 9987) |
69 | 71 | } |
70 | 72 |
|
71 | 73 | @Test |
72 | 74 | fun `fromInstrumentationArgument(http url with host) should return Custom()`() { |
73 | | - assertThat(fromInstrumentationArgument("http://a.b.c")) |
74 | | - .isEqualTo(DataConnectBackend.Custom("a.b.c", false)) |
| 75 | + fromInstrumentationArgument("http://a.b.c") shouldBe DataConnectBackend.Custom("a.b.c", false) |
75 | 76 | } |
76 | 77 |
|
77 | 78 | @Test |
78 | 79 | fun `fromInstrumentationArgument(http url with host and port) should return Custom()`() { |
79 | | - assertThat(fromInstrumentationArgument("http://a.b.c:9987")) |
80 | | - .isEqualTo(DataConnectBackend.Custom("a.b.c:9987", false)) |
| 80 | + fromInstrumentationArgument("http://a.b.c:9987") shouldBe |
| 81 | + DataConnectBackend.Custom("a.b.c:9987", false) |
81 | 82 | } |
82 | 83 |
|
83 | 84 | @Test |
84 | 85 | fun `fromInstrumentationArgument(https url with host) should return Custom()`() { |
85 | | - assertThat(fromInstrumentationArgument("https://a.b.c")) |
86 | | - .isEqualTo(DataConnectBackend.Custom("a.b.c", true)) |
| 86 | + fromInstrumentationArgument("https://a.b.c") shouldBe DataConnectBackend.Custom("a.b.c", true) |
87 | 87 | } |
88 | 88 |
|
89 | 89 | @Test |
90 | 90 | fun `fromInstrumentationArgument(https url with host and port) should return Custom()`() { |
91 | | - assertThat(fromInstrumentationArgument("https://a.b.c:9987")) |
92 | | - .isEqualTo(DataConnectBackend.Custom("a.b.c:9987", true)) |
| 91 | + fromInstrumentationArgument("https://a.b.c:9987") shouldBe |
| 92 | + DataConnectBackend.Custom("a.b.c:9987", true) |
93 | 93 | } |
94 | 94 |
|
95 | 95 | @Test |
96 | 96 | fun `fromInstrumentationArgument('foo') should throw an exception`() { |
97 | 97 | val exception = |
98 | | - assertThrows(InvalidInstrumentationArgumentException::class) { |
99 | | - fromInstrumentationArgument("foo") |
100 | | - } |
| 98 | + shouldThrow<InvalidInstrumentationArgumentException> { fromInstrumentationArgument("foo") } |
| 99 | + |
101 | 100 | val urlParseErrorMessage = runCatching { URL("foo") }.exceptionOrNull()!!.message!! |
102 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText("foo") |
103 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText("invalid", ignoreCase = true) |
104 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText("DATA_CONNECT_BACKEND") |
105 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText(urlParseErrorMessage) |
| 101 | + assertSoftly { |
| 102 | + exception.message shouldContainWithNonAbuttingText "foo" |
| 103 | + exception.message shouldContainWithNonAbuttingTextIgnoringCase "invalid" |
| 104 | + exception.message shouldContainWithNonAbuttingText "DATA_CONNECT_BACKEND" |
| 105 | + exception.message shouldContainWithNonAbuttingText urlParseErrorMessage |
| 106 | + } |
106 | 107 | } |
107 | 108 |
|
108 | 109 | @Test |
109 | 110 | fun `fromInstrumentationArgument(invalid URI) should throw an exception`() { |
110 | 111 | val exception = |
111 | | - assertThrows(InvalidInstrumentationArgumentException::class) { |
112 | | - fromInstrumentationArgument("..:") |
113 | | - } |
| 112 | + shouldThrow<InvalidInstrumentationArgumentException> { fromInstrumentationArgument("..:") } |
| 113 | + |
114 | 114 | val uriParseErrorMessage = runCatching { URI("..:") }.exceptionOrNull()!!.message!! |
115 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText("..:") |
116 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText("invalid", ignoreCase = true) |
117 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText("DATA_CONNECT_BACKEND") |
118 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText(uriParseErrorMessage) |
| 115 | + assertSoftly { |
| 116 | + exception.message shouldContainWithNonAbuttingText "..:" |
| 117 | + exception.message shouldContainWithNonAbuttingTextIgnoringCase "invalid" |
| 118 | + exception.message shouldContainWithNonAbuttingText "DATA_CONNECT_BACKEND" |
| 119 | + exception.message shouldContainWithNonAbuttingText uriParseErrorMessage |
| 120 | + } |
119 | 121 | } |
120 | 122 |
|
121 | 123 | @Test |
122 | 124 | fun `fromInstrumentationArgument(invalid emulator URI) should throw an exception`() { |
123 | 125 | val exception = |
124 | | - assertThrows(InvalidInstrumentationArgumentException::class) { |
| 126 | + shouldThrow<InvalidInstrumentationArgumentException> { |
125 | 127 | fromInstrumentationArgument("emulator:::::") |
126 | 128 | } |
| 129 | + |
127 | 130 | val urlParseErrorMessage = runCatching { URL("https://::::") }.exceptionOrNull()!!.message!! |
128 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText("emulator:::::") |
129 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText("invalid", ignoreCase = true) |
130 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText("DATA_CONNECT_BACKEND") |
131 | | - assertThat(exception).hasMessageThat().containsWithNonAdjacentText(urlParseErrorMessage) |
| 131 | + assertSoftly { |
| 132 | + exception.message shouldContainWithNonAbuttingText "emulator:::::" |
| 133 | + exception.message shouldContainWithNonAbuttingTextIgnoringCase "invalid" |
| 134 | + exception.message shouldContainWithNonAbuttingText "DATA_CONNECT_BACKEND" |
| 135 | + exception.message shouldContainWithNonAbuttingText urlParseErrorMessage |
| 136 | + } |
132 | 137 | } |
133 | 138 | } |
0 commit comments