How to use notNull method of org.mockito.kotlin.Matchers class

Best Mockito-kotlin code snippet using org.mockito.kotlin.Matchers.notNull

ConversionExpressions.kt

Source:ConversionExpressions.kt Github

copy

Full Screen

1package org.jesperancinha.plugins.unit2/**3 * Created by jofisaes on 25/12/20214 */5class ConversionExpressions {6 companion object {7 private const val GENERIC_SEARCH_CHARACTERS2 = "0-9a-zA-Z_\\-\":,/\\.\\!\\[\\]\\+<>{}#\\?\\\\\\$"8 private const val GENERIC_SEARCH_CHARACTERS = "0-9a-zA-Z(_\\-\":,/\\.)\\!\\[\\]\\+<>{}#\\?\\\\\\$"9 private const val GENERIC_SEARCH_CHARACTERS_AND_SPACE = "$GENERIC_SEARCH_CHARACTERS "10 private const val GENERIC_GROUP_ALL = "([$GENERIC_SEARCH_CHARACTERS_AND_SPACE]*)"11 private const val GENERIC_GROUP = "([$GENERIC_SEARCH_CHARACTERS_AND_SPACE]*[$GENERIC_SEARCH_CHARACTERS]+)"12 private const val GENERIC_GROUP_ESCAPE_CHARS = "([$GENERIC_SEARCH_CHARACTERS_AND_SPACE`]*)"13 private const val GENERIC_GROUP_WITH_NEWLINE = "([$GENERIC_SEARCH_CHARACTERS_AND_SPACE\\n]*)"14 private const val GENERIC_GROUP_WITH_NEWLINE2 = "([$GENERIC_SEARCH_CHARACTERS2\\n (]*)"15 private const val GENERIC_GROUP_WITH_NEWLINE_STAR = "([$GENERIC_SEARCH_CHARACTERS_AND_SPACE\\n\\*]*)"16 private const val GENERIC_GROUP_WITH_NEWLINE_EQUALS = "([$GENERIC_SEARCH_CHARACTERS_AND_SPACE\\n\\=]*)"17 private const val GENERIC_GROUP_WITH_STAR = "([$GENERIC_SEARCH_CHARACTERS_AND_SPACE\\*]*)"18 private const val CONSTANT_GROUP = "(\"[$GENERIC_SEARCH_CHARACTERS_AND_SPACE]*\"|[0-9]*|[A-Z_]*)"19 private const val CONSTANT_GROUP1 = "(([A-Z]+[a-z]*(\\.)?)*)"20 private const val CONSTANT_GROUP2 = "([a-zA-Z]*)"21 private const val VARIABLE_GROUP = "([a-zA-Z_]*)"22 private val FAIL_FROM_JUNIT_TO_EXCEPTION_REGEX =23 Regex("Assert\\.fail\\($GENERIC_GROUP\\)")24 private const val FAIL_FROM_JUNIT_TO_EXCEPTION_REPLACEMENT = "throw RuntimeException(\$1)"25 private val MOCK_FROM_MOCKITO_TO_MOCKK_REGEX =26 Regex("Mockito\\.mock\\((\n)?(\\s)*$GENERIC_GROUP::class\\.java\\)")27 private const val MOCK_FROM_MOCKITO_TO_MOCKK_REPLACEMENT = "mockk<\$3>()"28 private val DISABLE_FROM_JUNIT_TO_KOTEST_REGEX =29 Regex("@Ignore\\(\"$GENERIC_GROUP_ALL\"\\)")30 private const val DISABLE_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "@Disabled(\"\$1\")"31 private val ASSERT_ARRAY_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX =32 Regex("Assert\\.assertArrayEquals\\($GENERIC_GROUP, $GENERIC_GROUP\\)")33 private const val ASSERT_ARRAY_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$2.shouldContainExactly(\$1)"34 private val ASSERT_FALSE_FROM_JUNIT_TO_KOTEST_REGEX =35 Regex("Assert\\.assertFalse\\($GENERIC_GROUP_WITH_STAR\\)")36 private const val ASSERT_FALSE_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$1.shouldBeFalse()"37 private val ASSERT_GREATER_THAN_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REGEX =38 Regex("Assert\\.assertTrue\\($GENERIC_GROUP_WITH_STAR, $GENERIC_GROUP_WITH_STAR > $CONSTANT_GROUP\\)")39 private const val ASSERT_GREATER_THAN_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REPLACEMENT =40 "\$2 shouldBeGreaterThan \$3"41 private val ASSERT_EQUAL_TO_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REGEX =42 Regex("Assert\\.assertTrue\\($GENERIC_GROUP_WITH_STAR, $GENERIC_GROUP_WITH_STAR == $CONSTANT_GROUP\\)")43 private const val ASSERT_EQUAL_TO_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$2 shouldBe \$3"44 private val ASSERT_TRUE_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REGEX =45 Regex("Assert\\.assertTrue\\($CONSTANT_GROUP, $GENERIC_GROUP_WITH_STAR\\)")46 private const val ASSERT_TRUE_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$2.shouldBeTrue()"47 private val ASSERT_TRUE_FROM_JUNIT_TO_KOTEST_REGEX =48 Regex("Assert\\.assertTrue\\($GENERIC_GROUP_WITH_STAR\\)")49 private const val ASSERT_TRUE_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$1.shouldBeTrue()"50 /**51 * Same52 */53 private val ASSERT_FALSE_BUT_NOTSAME_FROM_JUNIT_TO_KOTEST_REGEX0 =54 Regex("Assert\\.assertFalse\\($CONSTANT_GROUP\\s*(===?|\\.equals)\\s*$GENERIC_GROUP\\)")55 private const val ASSERT_FALSE_BUT_NOTSAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 =56 "\$3 shouldNotBeSameInstanceAs \$1"57 private val ASSERT_FALSE_BUT_NOTSAME_FROM_JUNIT_TO_KOTEST_REGEX =58 Regex("Assert\\.assertFalse\\($GENERIC_GROUP\\s*(===?|\\.equals)\\s*$GENERIC_GROUP\\)")59 private const val ASSERT_FALSE_BUT_NOTSAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT =60 "\$1 shouldNotBeSameInstanceAs \$3"61 private val ASSERT_FALSE_BUT_SAME_FROM_JUNIT_TO_KOTEST_REGEX0 =62 Regex("Assert\\.assertTrue\\($CONSTANT_GROUP\\s*(===?|\\.equals)\\s*$GENERIC_GROUP\\)")63 private const val ASSERT_FALSE_BUT_SAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 = "\$3 shouldBeSameInstanceAs \$1"64 private val ASSERT_FALSE_BUT_SAME_FROM_JUNIT_TO_KOTEST_REGEX =65 Regex("Assert\\.assertTrue\\($GENERIC_GROUP\\s*(===?|\\.equals)\\s*$GENERIC_GROUP\\)")66 private const val ASSERT_FALSE_BUT_SAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$1 shouldBeSameInstanceAs \$3"67 /**68 * Equals69 */70 private val ASSERT_FALSE_BUT_NOTEQUALS_FROM_JUNIT_TO_KOTEST_REGEX0 =71 Regex("Assert\\.assertFalse\\($CONSTANT_GROUP\\s*(==?|\\.equals)\\s*$GENERIC_GROUP\\)")72 private const val ASSERT_FALSE_BUT_NOTEQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 = "\$3 shouldNotBe \$1"73 private val ASSERT_FALSE_BUT_NOTEQUALS_FROM_JUNIT_TO_KOTEST_REGEX =74 Regex("Assert\\.assertFalse\\($GENERIC_GROUP\\s*(==?|\\.equals)\\s*$GENERIC_GROUP\\)")75 private const val ASSERT_FALSE_BUT_NOTEQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$1 shouldNotBe \$3"76 private val ASSERT_FALSE_BUT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX0 =77 Regex("Assert\\.assertTrue\\($CONSTANT_GROUP\\s*(==?|\\.equals)\\s*$GENERIC_GROUP\\)")78 private const val ASSERT_FALSE_BUT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 = "\$3 shouldBe \$1"79 private val ASSERT_FALSE_BUT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX =80 Regex("Assert\\.assertTrue\\($GENERIC_GROUP\\s*(==?|\\.equals)\\s*$GENERIC_GROUP\\)")81 private const val ASSERT_FALSE_BUT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$1 shouldBe \$3"82 /**83 *84 */85 private val ASSERT_EMPTY_FROM_HAMCREST_TO_KOTEST_REGEX =86 Regex("Assert\\.assertThat\\($GENERIC_GROUP, Matchers.`is`\\(Matchers\\.empty\\(\\)\\)\\)")87 private const val ASSERT_EMPTY_FROM_HAMCREST_TO_KOTEST_REPLACEMENT = "\$1.shouldBeEmpty()"88 private val ASSERT_IS_FROM_HAMCREST_TO_KOTEST_REGEX =89 Regex("Assert\\.assertThat\\($GENERIC_GROUP, Matchers.`is`\\($GENERIC_GROUP\\)\\)")90 private const val ASSERT_IS_FROM_HAMCREST_TO_KOTEST_REPLACEMENT = "\$1 shouldBe \$2"91 private val ASSERT_HAS_SIZE_FROM_HAMCREST_TO_KOTEST_REGEX =92 Regex("Assert\\.assertThat\\($GENERIC_GROUP, Matchers.hasSize\\($GENERIC_GROUP\\)\\)")93 private const val ASSERT_HAS_SIZE_FROM_HAMCREST_TO_KOTEST_REPLACEMENT = "\$1.shouldHaveSize(\$2)"94 private val ASSERT_NULL_VALUE_IS_IS_FROM_HAMCREST_TO_KOTEST_REGEX =95 Regex("MatcherAssert\\.assertThat\\($GENERIC_GROUP, Is.`is`\\(IsNull\\.nullValue\\(\\)\\)\\)")96 private const val ASSERT_NULL_VALUE_IS_IS_FROM_HAMCREST_TO_KOTEST_REPLACEMENT = "\$1.shouldBeNull()"97 private val ASSERT_NULL_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REGEX =98 Regex("Assert\\.assertNull\\($GENERIC_GROUP, $GENERIC_GROUP\\)")99 private const val ASSERT_NULL_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$2.shouldBeNull()"100 private val ASSERT_NULL_FROM_JUNIT_TO_KOTEST_REGEX = Regex("Assert\\.assertNull\\($GENERIC_GROUP\\)")101 private const val ASSERT_NULL_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$1.shouldBeNull()"102 private val ASSERT_NOTNULL_FROM_JUNIT_TO_KOTEST_REGEX = Regex("Assert\\.assertNotNull\\($GENERIC_GROUP\\)")103 private const val ASSERT_NOTNULL_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$1.shouldNotBeNull()"104 private val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX0 =105 Regex("Assert\\.assertEquals\\($CONSTANT_GROUP,(\n*)(\\s*)$GENERIC_GROUP\\)")106 private const val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 = "\$4 shouldBe \$1"107 private val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX5 =108 Regex("Assert\\.assertEquals\\($GENERIC_GROUP, $CONSTANT_GROUP2::class\\.java\\)")109 private const val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT5 = "\$1 shouldBe \$2::class.java"110 private val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX4 =111 Regex("Assert\\.assertEquals\\($CONSTANT_GROUP1, $GENERIC_GROUP_ALL\\)")112 private const val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT4 = "\$4 shouldBe \$1"113 private val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX =114 Regex("Assert\\.assertEquals\\($GENERIC_GROUP, $GENERIC_GROUP\\)")115 private const val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$1 shouldBe \$2"116 private val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX6 =117 Regex("Assert\\.assertEquals\\($GENERIC_GROUP, $GENERIC_GROUP_ESCAPE_CHARS\\)")118 private const val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT6 = "\$2 shouldBe \$1"119 private val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX1 =120 Regex("assertEquals\\($GENERIC_GROUP, $GENERIC_GROUP\\)")121 private const val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT1 = "\$1 shouldBe \$2"122 private val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX2 =123 Regex("Assert\\.assertEquals\\($GENERIC_GROUP, $GENERIC_GROUP_WITH_NEWLINE\\)")124 private const val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT2 = "\$2 shouldBe \$1"125 private val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX3 =126 Regex("Assert\\.assertEquals\\($GENERIC_GROUP, $GENERIC_GROUP_WITH_STAR\\)")127 private const val ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT3 = "\$2 shouldBe \$1"128 private val ASSERT_SAME_FROM_JUNIT_TO_KOTEST_REGEX0 =129 Regex("Assert\\.assertSame\\($VARIABLE_GROUP, $GENERIC_GROUP\\)")130 private const val ASSERT_SAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 = "\$1 shouldBeSameInstanceAs \$2"131 private val ASSERT_SAME_FROM_JUNIT_TO_KOTEST_REGEX =132 Regex("Assert\\.assertSame\\($GENERIC_GROUP, $GENERIC_GROUP\\)")133 private const val ASSERT_SAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$1 shouldBeSameInstanceAs \$2"134 private val ASSERT_CONTAINS_STRING_FROM_JUNIT_TO_KOTEST_REGEX =135 Regex("Assert\\.assertThat\\($GENERIC_GROUP, Matchers.containsString\\($GENERIC_GROUP\\)\\)")136 private const val ASSERT_CONTAINS_STRING_FROM_JUNIT_TO_KOTEST_REPLACEMENT = "\$1 shouldContain \$2"137 private val EVERY_THEN_FROM_MOCKITO_TO_MOCKK_REGEX =138 Regex("Mockito\\.`when`\\($GENERIC_GROUP\\)(\n)?(\\s*)?\\.then\\($GENERIC_GROUP\\)")139 private const val EVERY_THEN_FROM_MOCKITO_TO_MOCKK_REPLACEMENT = "every { \$1 } answers { \$4 }"140 private val EVERY_TRUE_FROM_MOCKITO_TO_MOCKK_REGEX =141 Regex("Mockito\\.`when`\\($GENERIC_GROUP\\)(\n)?(\\s*)?\\.thenReturn\\($GENERIC_GROUP\\)")142 private const val EVERY_TRUE_FROM_MOCKITO_TO_MOCKK_REPLACEMENT = "every { \$1 } returns \$4"143 private val EVERY_TRUE_FROM_MOCKITO_TO_MOCKK_REGEX1 =144 Regex("Mockito\\.`when`\\($GENERIC_GROUP\\)(\n)?(\\s*)?\\.thenReturn\\($GENERIC_GROUP_WITH_NEWLINE2\\)")145 private const val EVERY_TRUE_FROM_MOCKITO_TO_MOCKK_REPLACEMENT1 = "every { \$1 } returns \$4"146 private val EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REGEX0 =147 Regex("Mockito\\.`when`\\($GENERIC_GROUP\\)(\n)?(\\s*)?\\.thenThrow\\((\n)?(\\s*)?$GENERIC_GROUP::class\\.java\\)")148 private const val EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REPLACEMENT0 = "every { \$1 } throws mockk<\$6>()"149 private val EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REGEX =150 Regex("Mockito\\.`when`\\($GENERIC_GROUP\\)(\n)?(\\s*)?\\.thenThrow\\($GENERIC_GROUP\\)")151 private const val EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REPLACEMENT = "every { \$1 } throws \$4"152 private val EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REGEX1 =153 Regex("(\\s*)try \\{\n" +154 "(\\s*)${GENERIC_GROUP_WITH_NEWLINE}\n" +155 "(\\s*)Assert\\.fail\\($GENERIC_GROUP\\)\n" +156 "(\\s*)} catch \\($GENERIC_GROUP\\)(\\s*)\\{\n" +157 "(\\s*)Assert\\.assertEquals\\($GENERIC_GROUP, $GENERIC_GROUP::class\\.java\\)\n" +158 "(\\s*)}")159 private const val EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REPLACEMENT1 = "\$1shouldThrow<\$11> { \$3 }"160 private val EVERY_THEN_WITH_INVOCATION_ARGS_FROM_MOCKITO_TO_MOCKK_REGEX =161 Regex("Mockito.`when`\\($GENERIC_GROUP\\)\\.then(\\s*)\\{(\\s*)$VARIABLE_GROUP(\\s*)->\n" +162 "(\\s*)(val|var) $VARIABLE_GROUP = $VARIABLE_GROUP\\.arguments\\[$CONSTANT_GROUP]\\.toString\\(\\)\n" +163 GENERIC_GROUP_WITH_NEWLINE_EQUALS)164 private const val EVERY_THEN_WITH_INVOCATION_ARGS_FROM_MOCKITO_TO_MOCKK_REPLACEMENT =165 "every { \$1 } answers {\n" +166 "\$6\$7 \$8 = it.invocation.args[\$10].toString()\n" +167 "\$11"168 private val VERIFY_ATLEAST_FROM_MOCKITO_TO_MOCKK_REGEX =169 Regex("Mockito.verify\\($GENERIC_GROUP, Mockito\\.atLeast\\($GENERIC_GROUP\\)\\)(\n)?(\\s)*\\.$GENERIC_GROUP_ALL")170 private const val VERIFY_ATLEAST_FROM_MOCKITO_TO_MOCKK_REPLACEMENT = "verify(atLeast = \$2) { \$1.\$5 }"171 private val VERIFY_TIMES_FROM_MOCKITO_TO_MOCKK_REGEX =172 Regex("Mockito\\.verify\\($GENERIC_GROUP, (Mockito\\.)?times\\($CONSTANT_GROUP\\)\\)\\.$GENERIC_GROUP")173 private const val VERIFY_TIMES_FROM_MOCKITO_TO_MOCKK_REPLACEMENT = "verify\\(exactly = \$3\\) { \$1.\$4 }"174 private val VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REGEX0 =175 Regex("Mockito\\.verify\\($GENERIC_GROUP\\)\\.$GENERIC_GROUP")176 private const val VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REPLACEMENT0 = "verify { \$1.\$2 }"177 private val VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REGEX =178 Regex("Mockito\\.verify\\($GENERIC_GROUP_WITH_NEWLINE\\)(\n)?(\\s*)?\\.$GENERIC_GROUP_WITH_NEWLINE\"\\)\n")179 private const val VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REPLACEMENT = "verify { \$1.\$4\"\\) }\n"180 private val VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REGEX1 =181 Regex("Mockito\\.verify\\($GENERIC_GROUP_WITH_NEWLINE\\)(\n)?(\\s*)?\\.$GENERIC_GROUP_WITH_NEWLINE_STAR\"\\)\n")182 private val FIND_EXCEPTION_ANNOTATION_REGEX = Regex("@Test\\(expected")183 private val FIND_FUN_REGEX = Regex("fun $VARIABLE_GROUP")184 private val REPLACE_EXCEPTION_ANNOTATION_REGEX = Regex("@Test\\(expected = $GENERIC_GROUP::class\\)")185 private val SLOT_EXPRESSION = Regex("val $GENERIC_GROUP = slot<$VARIABLE_GROUP>\\(\\)")186 private val ANY_TYPE_REGEX =187 Regex("(ArgumentMatchers|Mockito)\\.any\\((\n)?(\\s*)?$GENERIC_GROUP::class\\.java\\)")188 private const val ANY_TYPE_REPLACEMENT = "any<\$4>()"189 private val ANY_STRING_REGEX =190 Regex("ArgumentMatchers.anyString\\(\\)")191 private const val ANY_STRING_REPLACEMENT = "any<String>()"192 private val ANY_SAME_REGEX =193 Regex("ArgumentMatchers\\.same\\($GENERIC_GROUP\\)")194 private const val ANY_SAME_REPLACEMENT = "$1"195 private val SLOT_REGEX =196 Regex("ArgumentCaptor.forClass\\((\n)?(\\s)*$GENERIC_GROUP::class\\.java\\)")197 private const val SLOT_REPLACEMENT = "slot<\$3>()"198 private val RULE_TEMP_FOLDER_FROM_JUNIT_REGEX =199 Regex("var $GENERIC_GROUP = TemporaryFolder\\(\\)")200 private const val RULE_TEMP_FOLDER_FROM_JUNIT_REPLACEMENT = "val \$1 = createTempDirectory()"201 private val RULE_TEMP_FILE_FROM_JUNIT_REGEX =202 Regex("$GENERIC_GROUP = $GENERIC_GROUP\\.newFile\\(\\)")203 private const val RULE_TEMP_FILE_FROM_JUNIT_REPLACEMENT = "\$1 = createTempFile(\$2).toFile()"204 private val RULE_TEMP_FILE_FROM_JUNIT_REGEX1 =205 Regex("$GENERIC_GROUP = $GENERIC_GROUP\\.newFile\\((\"$GENERIC_GROUP\"|$VARIABLE_GROUP)\\)")206 private const val RULE_TEMP_FILE_FROM_JUNIT_REPLACEMENT1 = "\$1 = Path(\$2.absolutePathString(), \$3).toFile()"207 private val KOTLIN_INJECTION_TEST_REGEX =208 Regex("(private )?(val|var) $GENERIC_GROUP: $GENERIC_GROUP\\? = null")209 private const val KOTLIN_INJECTION_TEST_REPLACE = "\$1lateinit var \$3: \$4"210 private val ANSWER_IMPLEMENTATION_FROM_MOCKITO_TO_MOCKK_TEST_REGEX =211 Regex("(\\s)*(protected )?(private )?fun $GENERIC_GROUP\\($GENERIC_GROUP\\): Answer<$GENERIC_GROUP> \\{\n*" +212 "(\\s)*return Answer \\{ $GENERIC_GROUP: InvocationOnMock\\? ->\n*" +213 "(\\s)*$GENERIC_GROUP\\(\n*" +214 "(\\s)*$GENERIC_GROUP\\)\n*" +215 "(\\s)*}\n*" +216 "(\\s)*}")217 private const val ANSWER_IMPLEMENTATION_FROM_MOCKITO_TO_MOCKK_TEST_REPLACEMENT =218 "\$1\$2\$3fun \$4(\$5): \$6 = $6(\$12)"219 private val WIREMOCK_DECLARATION_FROM_RULE_TO_INSTANCE_REGEX =220 Regex("(private )?(protected )?(var|val) $GENERIC_GROUP = WireMockRule\\($CONSTANT_GROUP\\)")221 private const val WIREMOCK_DECLARATION_FROM_RULE_TO_INSTANCE_REPLACEMENT =222 "\$1\$2\$3 \$4 = WireMockServer(options().port(\$5))"223 private val CORRECTION1_REGEX =224 Regex("$GENERIC_GROUP shouldNotBe \\($GENERIC_GROUP\\)")225 private const val CORRECTION1_REPLACEMENT = "\$1 shouldNotBe \$2"226 private val CORRECTION2_REGEX =227 Regex("$GENERIC_GROUP shouldBe \\($GENERIC_GROUP\\)")228 private const val CORRECTION2_REPLACEMENT = "\$1 shouldBe \$2"229 private val CORRECTION3_REGEX =230 Regex("$CONSTANT_GROUP2\\.capture\\(\\)")231 private const val CORRECTION3_REPLACEMENT = "capture\\(\$1\\)"232 private val CORRECTION4_REGEX =233 Regex("$GENERIC_GROUP\\.$GENERIC_GROUP\\.absolutePath\n")234 private const val CORRECTION4_REPLACEMENT = "\$1.\$2.absolutePathString()\n"235 private val CORRECTION5_REGEX =236 Regex("$GENERIC_GROUP\\.$GENERIC_GROUP\\.absolutePath\\)")237 private const val CORRECTION5_REPLACEMENT = "\$1.\$2.absolutePathString()\\)"238 private val CORRECTION60_REGEX =239 Regex("$VARIABLE_GROUP\\.newFolder\\(\\)")240 private const val CORRECTION60_REPLACEMENT = "createTempDirectory(\$1).toFile()"241 private val CORRECTION61_REGEX =242 Regex("$VARIABLE_GROUP\\.newFolder\\($CONSTANT_GROUP, $CONSTANT_GROUP, $CONSTANT_GROUP\\)")243 private const val CORRECTION61_REPLACEMENT =244 "createDirectory(\$1.resolve(\$2).createDirectory().resolve(\$3).createDirectory().resolve(\$4)).toFile()"245 private val CORRECTION62_REGEX =246 Regex("$VARIABLE_GROUP\\.newFolder\\($CONSTANT_GROUP, $CONSTANT_GROUP\\)")247 private const val CORRECTION62_REPLACEMENT =248 "createDirectory(\$1.resolve(\$2).createDirectory().resolve(\$3)).toFile()"249 private val CORRECTION6_REGEX =250 Regex("$VARIABLE_GROUP\\.newFolder\\($CONSTANT_GROUP\\)")251 private const val CORRECTION6_REPLACEMENT = "createDirectory(\$1.resolve(\$2)).toFile()"252 private val CORRECTION7_REGEX =253 Regex("$VARIABLE_GROUP\\.newFile\\($CONSTANT_GROUP\\)")254 private const val CORRECTION7_REPLACEMENT = "createFile(\$1.resolve(\$2)).toFile()"255 private val CORRECTION8_REGEX =256 Regex("$CONSTANT_GROUP2\\.root(?!\\.)")257 private const val CORRECTION8_REPLACEMENT = "\$1.toFile()"258 private val CORRECTION9_REGEX =259 Regex("root\\.toURI\\(\\).toURL\\(\\)")260 private const val CORRECTION9_REPLACEMENT = "toUri().toURL()"261 private val ASSERT_REPLACE_IMPORT_JUNIT_TO_JUPITER = mutableListOf(262 FAIL_FROM_JUNIT_TO_EXCEPTION_REGEX to (FAIL_FROM_JUNIT_TO_EXCEPTION_REPLACEMENT to arrayOf("import io.kotest.assertions.any")),263 ANY_STRING_REGEX to (ANY_STRING_REPLACEMENT to arrayOf("import io.kotest.assertions.any")),264 ANY_TYPE_REGEX to (ANY_TYPE_REPLACEMENT to arrayOf("import io.kotest.assertions.any")),265 ANY_SAME_REGEX to (ANY_SAME_REPLACEMENT to emptyArray()),266 SLOT_REGEX to (SLOT_REPLACEMENT to arrayOf("import io.mockk.slot")),267 MOCK_FROM_MOCKITO_TO_MOCKK_REGEX to (MOCK_FROM_MOCKITO_TO_MOCKK_REPLACEMENT to arrayOf("import io.mockk.mockk")),268 ASSERT_EQUAL_TO_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_EQUAL_TO_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf(269 "import io.kotest.matchers.shouldBe")),270 ASSERT_GREATER_THAN_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_GREATER_THAN_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf(271 "import io.kotest.matchers.ints.shouldBeGreaterThan")),272 ASSERT_TRUE_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_TRUE_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf(273 "import io.kotest.matchers.booleans.shouldBeTrue")),274 ASSERT_ARRAY_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_ARRAY_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf(275 "import io.kotest.matchers.collections.shouldContainExactly")),276 ASSERT_SAME_FROM_JUNIT_TO_KOTEST_REGEX0 to (ASSERT_SAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 to arrayOf("import io.kotest.matchers.types.shouldBeSameInstanceAs")),277 ASSERT_SAME_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_SAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf("import io.kotest.matchers.types.shouldBeSameInstanceAs")),278 DISABLE_FROM_JUNIT_TO_KOTEST_REGEX to (DISABLE_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf("import org.junit.jupiter.api.Disabled")),279 ASSERT_FALSE_BUT_NOTEQUALS_FROM_JUNIT_TO_KOTEST_REGEX0 to (ASSERT_FALSE_BUT_NOTEQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 to arrayOf(280 "import io.kotest.matchers.shouldNotBe")),281 ASSERT_FALSE_BUT_NOTEQUALS_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_FALSE_BUT_NOTEQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf(282 "import io.kotest.matchers.shouldNotBe")),283 ASSERT_FALSE_BUT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX0 to (ASSERT_FALSE_BUT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 to arrayOf(284 "import io.kotest.matchers.shouldBe")),285 ASSERT_FALSE_BUT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_FALSE_BUT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf(286 "import io.kotest.matchers.shouldBe")),287 ASSERT_FALSE_BUT_NOTSAME_FROM_JUNIT_TO_KOTEST_REGEX0 to (ASSERT_FALSE_BUT_NOTSAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 to arrayOf(288 "import io.kotest.matchers.types.shouldNotBeSameInstanceAs")),289 ASSERT_FALSE_BUT_NOTSAME_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_FALSE_BUT_NOTSAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf(290 "import io.kotest.matchers.types.shouldNotBeSameInstanceAs")),291 ASSERT_FALSE_BUT_SAME_FROM_JUNIT_TO_KOTEST_REGEX0 to (ASSERT_FALSE_BUT_SAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 to arrayOf(292 "import io.kotest.matchers.types.shouldBeSameInstanceAs")),293 ASSERT_FALSE_BUT_SAME_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_FALSE_BUT_SAME_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf(294 "import io.kotest.matchers.types.shouldBeSameInstanceAs")),295 EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REGEX1 to (EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REPLACEMENT1 to arrayOf("import io.kotest.assertions.throwables.shouldThrow")),296 ASSERT_EMPTY_FROM_HAMCREST_TO_KOTEST_REGEX to (ASSERT_EMPTY_FROM_HAMCREST_TO_KOTEST_REPLACEMENT to arrayOf("import io.kotest.matchers.collections.shouldBeEmpty")),297 ASSERT_IS_FROM_HAMCREST_TO_KOTEST_REGEX to (ASSERT_IS_FROM_HAMCREST_TO_KOTEST_REPLACEMENT to arrayOf("import io.kotest.matchers.shouldBe")),298 ASSERT_HAS_SIZE_FROM_HAMCREST_TO_KOTEST_REGEX to (ASSERT_HAS_SIZE_FROM_HAMCREST_TO_KOTEST_REPLACEMENT to arrayOf(299 "import io.kotest.matchers.collections.shouldHaveSize")),300 ASSERT_NULL_VALUE_IS_IS_FROM_HAMCREST_TO_KOTEST_REGEX to (ASSERT_NULL_VALUE_IS_IS_FROM_HAMCREST_TO_KOTEST_REPLACEMENT to arrayOf(301 "import io.kotest.matchers.nulls.shouldBeNull")),302 ASSERT_NULL_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_NULL_WITH_MESSAGE_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf(303 "import io.kotest.matchers.nulls.shouldBeNull")),304 ASSERT_NULL_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_NULL_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf("import io.kotest.matchers.nulls.shouldBeNull")),305 ASSERT_NOTNULL_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_NOTNULL_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf("import io.kotest.matchers.nulls.shouldNotBeNull")),306 ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX5 to (ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT5 to arrayOf("import io.kotest.matchers.shouldBe")),307 ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX4 to (ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT4 to arrayOf("import io.kotest.matchers.shouldBe")),308 ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX3 to (ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT3 to arrayOf("import io.kotest.matchers.shouldBe")),309 ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX0 to (ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT0 to arrayOf("import io.kotest.matchers.shouldBe")),310 ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf("import io.kotest.matchers.shouldBe")),311 ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX2 to (ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT2 to arrayOf("import io.kotest.matchers.shouldBe")),312 ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX1 to (ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT1 to arrayOf("import io.kotest.matchers.shouldBe")),313 ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REGEX6 to (ASSERT_EQUALS_FROM_JUNIT_TO_KOTEST_REPLACEMENT6 to arrayOf("import io.kotest.matchers.shouldBe")),314 ASSERT_CONTAINS_STRING_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_CONTAINS_STRING_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf(315 "import io.kotest.matchers.string.shouldContain")),316 EVERY_THEN_FROM_MOCKITO_TO_MOCKK_REGEX to (EVERY_THEN_FROM_MOCKITO_TO_MOCKK_REPLACEMENT to arrayOf("import io.mockk.every")),317 EVERY_TRUE_FROM_MOCKITO_TO_MOCKK_REGEX to (EVERY_TRUE_FROM_MOCKITO_TO_MOCKK_REPLACEMENT to arrayOf("import io.mockk.every")),318 EVERY_TRUE_FROM_MOCKITO_TO_MOCKK_REGEX1 to (EVERY_TRUE_FROM_MOCKITO_TO_MOCKK_REPLACEMENT1 to arrayOf("import io.mockk.every")),319 EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REGEX0 to (EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REPLACEMENT0 to arrayOf("import io.mockk.every",320 "import io.mockk.mockk")),321 EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REGEX to (EVERY_THROWS_FROM_MOCKITO_TO_MOCKK_REPLACEMENT to arrayOf("import io.mockk.every")),322 VERIFY_ATLEAST_FROM_MOCKITO_TO_MOCKK_REGEX to (VERIFY_ATLEAST_FROM_MOCKITO_TO_MOCKK_REPLACEMENT to arrayOf("import io.mockk.verify")),323 VERIFY_TIMES_FROM_MOCKITO_TO_MOCKK_REGEX to (VERIFY_TIMES_FROM_MOCKITO_TO_MOCKK_REPLACEMENT to arrayOf("import io.mockk.verify")),324 VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REGEX0 to (VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REPLACEMENT0 to arrayOf("import io.mockk.verify")),325 VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REGEX to (VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REPLACEMENT to arrayOf("import io.mockk.verify")),326 VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REGEX1 to (VERIFY_SIMPLE_FROM_MOCKITO_TO_MOCKK_REPLACEMENT to arrayOf("import io.mockk.verify")),327 RULE_TEMP_FOLDER_FROM_JUNIT_REGEX to (RULE_TEMP_FOLDER_FROM_JUNIT_REPLACEMENT to arrayOf("import kotlin.io.path.createTempDirectory")),328 RULE_TEMP_FILE_FROM_JUNIT_REGEX to (RULE_TEMP_FILE_FROM_JUNIT_REPLACEMENT to arrayOf("import kotlin.io.path.createTempFile")),329 RULE_TEMP_FILE_FROM_JUNIT_REGEX1 to (RULE_TEMP_FILE_FROM_JUNIT_REPLACEMENT1 to emptyArray()),330 KOTLIN_INJECTION_TEST_REGEX to (KOTLIN_INJECTION_TEST_REPLACE to emptyArray()),331 ASSERT_FALSE_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_FALSE_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf("import io.kotest.matchers.booleans.shouldBeFalse")),332 ASSERT_TRUE_FROM_JUNIT_TO_KOTEST_REGEX to (ASSERT_TRUE_FROM_JUNIT_TO_KOTEST_REPLACEMENT to arrayOf("import io.kotest.matchers.booleans.shouldBeTrue")),333 ANSWER_IMPLEMENTATION_FROM_MOCKITO_TO_MOCKK_TEST_REGEX to (ANSWER_IMPLEMENTATION_FROM_MOCKITO_TO_MOCKK_TEST_REPLACEMENT to emptyArray()),334 EVERY_THEN_WITH_INVOCATION_ARGS_FROM_MOCKITO_TO_MOCKK_REGEX to (EVERY_THEN_WITH_INVOCATION_ARGS_FROM_MOCKITO_TO_MOCKK_REPLACEMENT to arrayOf(335 "import io.mockk.every")),336 WIREMOCK_DECLARATION_FROM_RULE_TO_INSTANCE_REGEX to (WIREMOCK_DECLARATION_FROM_RULE_TO_INSTANCE_REPLACEMENT to arrayOf(337 "import com.github.tomakehurst.wiremock.WireMockServer",338 "import com.github.tomakehurst.wiremock.core.WireMockConfiguration.options")),339 CORRECTION1_REGEX to (CORRECTION1_REPLACEMENT to emptyArray()),340 CORRECTION2_REGEX to (CORRECTION2_REPLACEMENT to emptyArray()),341 CORRECTION3_REGEX to (CORRECTION3_REPLACEMENT to emptyArray()),342 CORRECTION4_REGEX to (CORRECTION4_REPLACEMENT to arrayOf("import kotlin.io.path.absolutePathString")),343 CORRECTION5_REGEX to (CORRECTION5_REPLACEMENT to arrayOf("import kotlin.io.path.absolutePathString")),344 CORRECTION60_REGEX to (CORRECTION60_REPLACEMENT to arrayOf("import kotlin.io.path.createTempDirectory")),345 CORRECTION61_REGEX to (CORRECTION61_REPLACEMENT to arrayOf("import java.nio.file.Files.createDirectory",346 "import java.nio.file.Files.createDirectory",347 "import kotlin.io.path.createDirectory")),348 CORRECTION62_REGEX to (CORRECTION62_REPLACEMENT to arrayOf("import java.nio.file.Files.createDirectory",349 "import java.nio.file.Files.createDirectory","import kotlin.io.path.createDirectory")),350 CORRECTION6_REGEX to (CORRECTION6_REPLACEMENT to arrayOf("import kotlin.io.path.Path",351 "import kotlin.io.path.absolutePathString", "import java.nio.file.Files.createDirectory")),352 CORRECTION7_REGEX to (CORRECTION7_REPLACEMENT to arrayOf("import kotlin.io.path.Path",353 "import kotlin.io.path.absolutePathString", "import java.nio.file.Files.createFile")),354 CORRECTION8_REGEX to (CORRECTION8_REPLACEMENT to emptyArray()),355 CORRECTION9_REGEX to (CORRECTION9_REPLACEMENT to emptyArray()),356 )357 private val IMPORT_REPLACEMENT_JUNIT_TO_JUPITER = mapOf(358 Regex("import org.junit.Before") to "import org.junit.jupiter.api.BeforeEach",359 Regex("import org.junit.Test") to "import org.junit.jupiter.api.Test",360 Regex("import org.junit.runner.RunWith") to "import org.junit.jupiter.api.extension.ExtendWith",361 Regex("import org.mockito.junit.MockitoJUnitRunner") to "import io.mockk.junit5.MockKExtension",362 Regex("import org.mockito.Mock\n") to "import io.mockk.impl.annotations.MockK\n",363 Regex("import org.junit.Assert(;)?\n") to "",364 Regex("import org.junit.runner.RunWith(;)?\n") to "",365 Regex("import org.hamcrest.Matchers(;)?\n") to "",366 Regex("import org.hamcrest.core.IsNull(;)?\n") to "",367 Regex("import org.hamcrest.MatcherAssert(;)?\n") to "",368 Regex("import org.hamcrest.core.Is(;)?\n") to "",369 Regex("import org.mockito.Mockito(;)?\n") to "",370 Regex("import org.junit.Ignore(;)?\n") to "",371 Regex("import org.mockito.ArgumentCaptor(;)?\n") to "",372 Regex("import org.junit.Rule(;)?\n") to "",373 Regex("import org.junit.rules.TemporaryFolder(;)?\n") to "",374 Regex("import com.github.tomakehurst.wiremock.junit.WireMockRule(;)?\n") to "",375 Regex("(\\s*)Mockito.verifyNoMoreInteractions\\($GENERIC_GROUP\\)(;)?\n") to "",376 )377 private val ANNOTATIONS_REPLACEMENT_JUNIT_TO_JUPITER = mapOf(378 Regex("@Before\n") to "@BeforeEach\n",379 Regex("@Mock\n") to "@MockK(relaxed = true)\n",380 Regex("@RunWith\\(MockitoJUnitRunner::class\\)") to "@ExtendWith(MockKExtension::class)",381 Regex("@Test\\(expected = $GENERIC_GROUP::class\\)") to "@Test",382 Regex("\n(\\s)*@Rule\n") to "\n"383 )384 val OPERATIONS = listOf(385 { text: String -> processImports(text) },386 { text: String -> processExceptionExpectingTestMethods(text) },387 { text: String -> processAssertionsFindReplaceImport(text) },388 { text: String -> procesAnnotations(text) },389 { text: String -> processCapturedSlotValues(text) },390 { text: String -> processDistinctImports(text) },391 )392 private fun processDistinctImports(originalText: String): String {393 val stringList = originalText.split("\n").toMutableList()394 val indexOfFirst = stringList.indexOfFirst { it.startsWith("import") }395 val indexOfLast = stringList.indexOfLast { it.startsWith("import") }396 val allImports = mutableListOf<String>()397 if (indexOfFirst > -1) {398 for (i in indexOfFirst..indexOfLast) {399 allImports.add(stringList.removeAt(indexOfFirst))400 }401 stringList.addAll(indexOfFirst, allImports.sorted().distinct())402 }403 return stringList.joinToString("\n")404 }405 private fun processCapturedSlotValues(originalText: String): String {406 var stringList = originalText.split("\n").toMutableList()407 var indexOfFunction = stringList.indexOfFirst { it.contains(FIND_FUN_REGEX) }408 var indexOfFirst = stringList.indexOfFirst(indexOfFunction) { it.contains(SLOT_EXPRESSION) }409 while (indexOfFunction > -1) {410 val allSlots = mutableListOf<String>()411 val indexOfNextClosure = stringList.indexOfNextClosure(indexOfFirst)412 while (indexOfFirst > -1 && indexOfFirst <= indexOfNextClosure) {413 allSlots.add(stringList[indexOfFirst].replace(SLOT_EXPRESSION, "\$1").trim())414 indexOfFirst = stringList.indexOfFirst(indexOfFirst) { it.contains(SLOT_EXPRESSION) }415 }416 allSlots.forEach {417 val forExpression =418 Regex("(\\s*)for(\\s*)\\($VARIABLE_GROUP(\\s*)in(\\s*)$it\\.allValues\\)(\\s*)\\{")419 indexOfFirst = stringList.indexOfFirst(indexOfFunction) { test -> test.contains(forExpression) }420 if (indexOfFirst > -1) {421 val indexOfNextClosureForBlock = stringList.indexOfNextClosure(indexOfFirst)422 val tab = stringList[indexOfFirst].replace(forExpression, "\$1")423 val subValue = stringList[indexOfFirst].replace(forExpression, "\$3")424 for (i in (indexOfFirst + 1) until indexOfNextClosureForBlock) {425 if (stringList[i].contains(Regex("(, |\\(|\\.)$subValue(\\))"))) {426 stringList[i] = "$tab${stringList[i].replace(subValue, "$it.captured").trim()}"427 } else {428 stringList[i] = "$tab${stringList[i].trim()}"429 }430 }431 stringList.removeAt(indexOfFirst)432 stringList.removeAt(stringList.indexOfNextClosure(indexOfFirst))433 }434 }435 indexOfFunction = stringList.indexOfFirst(indexOfFunction) { it.contains(FIND_FUN_REGEX) }436 }437 return stringList.joinToString("\n")438 }439 private fun processExceptionExpectingTestMethods(originalText: String): String {440 var stringList = originalText.split("\n").toMutableList()441 var indexOfFirst = stringList.indexOfFirst { it.contains(FIND_EXCEPTION_ANNOTATION_REGEX) }442 val firstIndex = indexOfFirst443 while (indexOfFirst > -1) {444 stringList = processExceptionTest(stringList, indexOfFirst)445 indexOfFirst = stringList.indexOfFirst(indexOfFirst) { it.contains(FIND_EXCEPTION_ANNOTATION_REGEX) }446 }447 if (firstIndex > -1) {448 stringList.add(2, "import io.kotest.assertions.throwables.shouldThrow")449 }450 return stringList.joinToString("\n")451 }452 private fun processExceptionTest(453 stringList: MutableList<String>,454 indexOfFirst: Int,455 ): MutableList<String> {456 var change = false457 var count: Int = 0458 val className =459 REPLACE_EXCEPTION_ANNOTATION_REGEX.find(stringList[indexOfFirst])?.destructured?.component1()460 for (i in indexOfFirst until stringList.size) {461 val currentLine = stringList[i]462 currentLine.forEach { c ->463 when (c) {464 '{' -> {465 if (count == 0) {466 change = true467 }468 count++469 }470 '}' -> count--471 }472 if (change && count == 0) {473 val j = getStartOfInstructionIndex(stringList, i - 1)474 val sb = StringBuilder()475 sb.append(stringList.removeAt(j))476 for (k in j until i - 1) {477 sb.append(stringList.removeAt(j).trim())478 }479 val toString = sb.toString()480 val trimmedOldText = toString.trim()481 stringList.add(j,482 toString.replace(trimmedOldText, "shouldThrow<$className> { $trimmedOldText }"))483 return stringList484 }485 }486 }487 return stringList488 }489 private fun getStartOfInstructionIndex(stringList: MutableList<String>, startingPoint: Int): Int {490 var parCount = 0491 var maybe = false492 var valCharCheck = ' '493 var i = startingPoint494 while (i in 0..startingPoint) {495 val substring = stringList[i]496 val subStringLength = substring.length - 1497 var j = subStringLength498 while (j in 0..subStringLength) {499 val currentChar = substring[j]500 if (currentChar == ')') {501 parCount++502 }503 if (currentChar == '(') {504 parCount--505 }506 if (maybe && currentChar != '.' && parCount == 0) {507 return i508 }509 maybe = parCount == 0 && (currentChar == ' ' || currentChar == '\n')510 if (valCharCheck == ' ' && currentChar == 'l') {511 valCharCheck = currentChar512 } else if (valCharCheck == 'l' && currentChar == 'a') {513 valCharCheck = currentChar514 } else if (valCharCheck == 'a' && currentChar == 'v') {515 valCharCheck = currentChar516 } else valCharCheck = currentChar517 if (valCharCheck == 'v') {518 return i519 }520 j--521 }522 i--523 }524 return startingPoint525 }526 private fun processImports(originalText: String): String =527 IMPORT_REPLACEMENT_JUNIT_TO_JUPITER528 .entries.fold(originalText) { acc, entry ->529 acc.replace(entry.key, entry.value)530 }531 private fun processAssertionsFindReplaceImport(originalText: String): String =532 ASSERT_REPLACE_IMPORT_JUNIT_TO_JUPITER533 .fold(originalText) { acc, instructions ->534 val find = instructions.first535 val (replace, imports) = instructions.second536 val contains = acc.contains(find)537 if (contains) {538 val replacedText =539 acc.replace(find,540 replace)541 val stringList = replacedText.split("\n").toMutableList()542 imports.forEach { import ->543 if (import !== "") {544 stringList.add(2, import)545 }546 }547 stringList.joinToString("\n")548 } else acc549 }550 private fun procesAnnotations(originalText: String) = ANNOTATIONS_REPLACEMENT_JUNIT_TO_JUPITER551 .entries.fold(originalText) { acc, entry ->552 acc.replace(entry.key, entry.value)553 }554 }555}556private fun MutableList<String>.indexOfNextClosure(indexOfFirst: Int): Int {557 var closureCount = 1558 forEachIndexed { index, it ->559 if (index >= indexOfFirst) {560 for (i: Int in it.indices) {561 if (it[i] == '{') {562 closureCount++563 } else if (it[i] == '}') {564 closureCount--565 }566 }567 if (closureCount == 0) {568 return index569 }570 }571 }572 return -1573}574private fun <E> MutableList<E>.indexOfFirst(from: Int, predicate: (E) -> Boolean): Int {575 forEachIndexed { index, it ->576 if (predicate(it) && index > from)577 return index578 }579 return -1580}581val String.processTests: String582 get() = ConversionExpressions.OPERATIONS.fold(this) { acc, operation -> operation(acc) }583val String.isSupported: Boolean584 get() = equals("kt") || equals("scala") || equals("java")...

Full Screen

Full Screen

AConnectivityStateObservableToTest.kt

Source:AConnectivityStateObservableToTest.kt Github

copy

Full Screen

...34 * Created by MConstantin on 4/6/2017.35 *//*36abstract class AConnectivityStateObservableToTest(val childBody: DescribeBody.() -> Unit) :37 Spek({38 var mockContext: Context by Delegates.notNull<Context>()39 var mockNetworkInfo: NetworkInfo by Delegates.notNull<NetworkInfo>()40 var mockNetwork: Network by Delegates.notNull<Network>()41 var mockIntent: Intent by Delegates.notNull<Intent>()42 var receiver: BroadcastReceiver by Delegates.notNull<BroadcastReceiver>()43 var supplier: IConnectionSupplier by Delegates.notNull<IConnectionSupplier>()44 var mockConnectivityManager: ConnectivityManager by Delegates.notNull<ConnectivityManager>()45 val networkInfos = arrayOf<NetworkInfo>(mockNetworkInfo)46 val networks = arrayOf<Network>(mockNetwork)47 val byDefault: DescribeBody.() -> Unit = {48 on("no active network state") {49 beforeEach {50 given(mockConnectivityManager.allNetworkInfo).willReturn(networkInfos)51 given(mockConnectivityManager.allNetworks).willReturn(networks)52 }53 it("returns current state when subscribed") {54 // when55 val observable = ConnectivityStateObservable(supplier)56 val observer = observable.test()57 // then58 observer.assertNoErrors()...

Full Screen

Full Screen

AssertionsTest.kt

Source:AssertionsTest.kt Github

copy

Full Screen

...16import com.nhaarman.mockito_kotlin.doNothing17import com.nhaarman.mockito_kotlin.doThrow18import com.nhaarman.mockito_kotlin.mock19import com.nhaarman.mockito_kotlin.whenever20import org.hamcrest.Matchers.notNullValue21import org.junit.Assert.assertThat22import org.junit.Before23import org.junit.Test24import org.junit.runner.RunWith25import org.mockito.ArgumentMatchers26import org.mockito.Mockito.verifyZeroInteractions27import tech.sirwellington.alchemy.arguments.AlchemyAssertion28import tech.sirwellington.alchemy.arguments.FailedAssertionException29import tech.sirwellington.alchemy.arguments.failedAssertion30import tech.sirwellington.alchemy.generator.StringGenerators.Companion.strings31import tech.sirwellington.alchemy.generator.one32import tech.sirwellington.alchemy.test.junit.ThrowableAssertion.assertThrows33import tech.sirwellington.alchemy.test.junit.runners.*34/**35 * @author SirWellington36 */37@RunWith(AlchemyTestRunner::class)38@Repeat39class AssertionsTest40{41 @GenerateString42 private lateinit var string: String43 @GenerateInteger44 private var positiveInt: Int = 045 @GenerateLong46 private var positiveLong: Long = 047 @GenerateDouble48 private var positiveDouble: Double = 0.049 @Before50 fun setUp()51 {52 }53 @DontRepeat54 @Test55 @Throws(Exception::class)56 fun testNotNull()57 {58 val instance = notNull<Any>()59 assertThat(instance, notNullValue())60 Tests.checkForNullCase(instance)61 val mock = mock<Any>()62 instance.check(mock)63 verifyZeroInteractions(mock)64 }65 @DontRepeat66 @Test67 fun testNonNullReference()68 {69 val instance = nonNullReference<Any>()70 assertThat(instance, notNullValue())71 Tests.checkForNullCase(instance)72 val mock = mock<Any>()73 instance.check(mock)74 verifyZeroInteractions(mock)75 assertThrows { instance.check(null) }.failedAssertion()76 }77 @DontRepeat78 @Test79 fun testNullObject()80 {81 val instance = nullObject<Any>()82 assertThat(instance, notNullValue())83 instance.check(null)84 assertThrows { instance.check(string) }.failedAssertion()85 }86 @Test87 fun testSameInstanceAs()88 {89 val instanceOne = sameInstanceAs<Any?>(null)90 //null is the same instance as null91 assertThat(instanceOne, notNullValue())92 instanceOne.check(null)93 //null is not the same instance as any other non-null object94 assertThrows { instanceOne.check("") }.failedAssertion()95 val someObject = Any()96 val instanceTwo = sameInstanceAs(someObject)97 instanceTwo.check(someObject)98 val differentObject = Any()99 assertThrows { instanceTwo.check(differentObject) }.failedAssertion()100 }101 @Test102 fun testInstanceOf()103 {104 val instance = instanceOf<Any>(Number::class.java)105 instance.check(positiveInt)...

Full Screen

Full Screen

Matchers.kt

Source:Matchers.kt Github

copy

Full Screen

...108}109/**110 * Not `null` argument.111 */112fun <T : Any> notNull(): T? {113 return ArgumentMatchers.notNull()114}115/**116 * Object argument that is reflection-equal to the given value with support for excluding117 * selected fields from a class.118 */119inline fun <reified T : Any> refEq(value: T, vararg excludeFields: String): T {120 return ArgumentMatchers.refEq<T>(value, *excludeFields) ?: createInstance()121}...

Full Screen

Full Screen

HotelBreakdownTest.kt

Source:HotelBreakdownTest.kt Github

copy

Full Screen

...17import kotlin.test.assertTrue18public class HotelBreakdownTest {19 public var mockHotelServiceTestRule: MockHotelServiceTestRule = MockHotelServiceTestRule()20 @Rule get21 private var vm: HotelBreakDownViewModel by Delegates.notNull()22 private var hotelCheckoutSummaryViewModel: HotelCheckoutSummaryViewModel by Delegates.notNull()23 private var createTripResponse: HotelCreateTripResponse by Delegates.notNull()24 @Before25 fun before() {26 val context = Mockito.mock(Context::class.java)27 val resources = Mockito.mock(Resources::class.java)28 Mockito.`when`(context.resources).thenReturn(resources)29 Mockito.`when`(resources.getQuantityString(Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt())).thenReturn("")30 Mockito.`when`(context.getString(Matchers.anyInt())).thenReturn("")31 hotelCheckoutSummaryViewModel = HotelCheckoutSummaryViewModel(context)32 vm = HotelBreakDownViewModel(context, hotelCheckoutSummaryViewModel)33 }34 @Test35 fun verifyBreakdown() {36 givenHappyCreateTripResponse()37 val latch = CountDownLatch(1)...

Full Screen

Full Screen

MatchersExtensions.kt

Source:MatchersExtensions.kt Github

copy

Full Screen

...42inline fun <reified T : Any> same(value: T): T =43 ArgumentMatchers.same(value).toNotNull()44inline fun <reified T : Any> isNull(): T =45 ArgumentMatchers.isNull<T>().toNotNull()46inline fun <reified T : Any> notNull(): T =47 ArgumentMatchers.notNull<T>().toNotNull()48fun contains(substring: String): String =49 ArgumentMatchers.contains(substring).toNotNull()50fun matches(regex: String): String =51 ArgumentMatchers.matches(regex).toNotNull()52fun endsWith(suffix: String): String =53 ArgumentMatchers.endsWith(suffix).toNotNull()54fun startsWith(prefix: String): String =55 ArgumentMatchers.startsWith(prefix).toNotNull()56inline fun <reified T : Any> argThat(matcher: ArgumentMatcher<T>): T =57 ArgumentMatchers.argThat(matcher).toNotNull()...

Full Screen

Full Screen

AbstractRetryKotlinTest.kt

Source:AbstractRetryKotlinTest.kt Github

copy

Full Screen

...20import org.mockito.BDDMockito.anyLong21import org.mockito.BDDMockito.given22import org.mockito.Matchers23import org.mockito.Matchers.eq24import org.mockito.Matchers.notNull25import java.util.concurrent.*26/**27 * AbstractRetryKotlinTest28 * @author debop sunghyouk.bae@gmail.com29 */30abstract class AbstractRetryKotlinTest : AbstractCoreKotlinTest() {31 val DON_T_PANIC = "Don't panic!"32 val schedulerMock = mock<ScheduledExecutorService>()33 val serviceMock = mock<FaultyService>()34 @Before open fun setup(): Unit {35 setupMocks()36 }37 private fun setupMocks() {38 given(schedulerMock.schedule(notNullRunnable(), anyLong(), eq(TimeUnit.MILLISECONDS)))39 .willAnswer { invocation ->40 (invocation.arguments[0] as Runnable).run()41 return@willAnswer uninitialized()42 }43 }44 open protected fun notNullRunnable(): Runnable? = notNull() as Runnable?45 open protected fun notNullRetryContext(): RetryContext? = notNull() as RetryContext?46 open protected fun millis(): TimeUnit? = Matchers.eq(TimeUnit.MILLISECONDS)47 open protected fun anyRetry(): RetryContext = retry(1)48 open protected fun retry(times: Int): RetryContext49 = AsyncRetryContext(RetryPolicy.DEFAULT, times, Exception())50}...

Full Screen

Full Screen

TransformationsNotNullTest.kt

Source:TransformationsNotNullTest.kt Github

copy

Full Screen

...12class TransformationsNotNullTest : BaseLiveDataTest() {13 @Test14 fun verifyLiveDataNotNull() {15 val source = MutableLiveData<String?>(null)16 val result = source.notNull()17 result.observeForever(observer)18 source.value = null19 verify(observer, never()).onChanged(any())20 source.value = "a"21 assertEquals("a", result.value)22 source.value = null23 assertEquals("a", result.value)24 source.value = "b"25 source.value = "b"26 argumentCaptor<String> {27 verify(observer, times(3)).onChanged(capture())28 assertThat(allValues, contains("a", "b", "b"))29 }30 }...

Full Screen

Full Screen

notNull

Using AI Code Generation

copy

Full Screen

1val mock: Person = mock()2verify(mock).setName(notNull())3val mock: Person = mock()4verify(mock).setName(any())5val mock: Person = mock()6verify(mock).setName(anyOrNull())7val mock: Person = mock()8verify(mock).setName(anyVararg())9val mock: Person = mock()10verify(mock).setName(eq("John"))11val mock: Person = mock()12verify(mock).setName(check { it.length > 5 })13val mock: Person = mock()14verify(mock).setName(isNull())15val mock: Person = mock()16verify(mock).setName(argThat { it.length > 5 })17val mock: Person = mock()18verify(mock).setName(argWhere { it.length > 5 })19val mock: Person = mock()20verify(mock).setName(captor.capture())21val mock: Person = mock()22verify(mock).setName(slot.capture())23val mock: Person = mock()24verify(mock).setName(lambda { it.length > 5 })25val mock: Person = mock()26verify(mock).setName(lambdaOrNull { it.length > 5 })27val mock: Person = mock()28verify(mock).setName(lambdaWhere { it.length > 5 })29val mock: Person = mock()30verify(mock).setName(lambdaVararg { it.length > 5 })31val mock: Person = mock()32verify(mock).setName(lambdaCheck { it.length > 5 })

Full Screen

Full Screen

notNull

Using AI Code Generation

copy

Full Screen

1 fun `notNull() method of Matchers class`() {2 val mock = mock<Mockable>()3 `when`(mock.doSomething(notNull())).thenReturn("Hello World")4 assertEquals("Hello World", mock.doSomething("Hello World"))5 }6 fun `anyOrNull() method of Matchers class`() {7 val mock = mock<Mockable>()8 `when`(mock.doSomething(anyOrNull())).thenReturn("Hello World")9 assertEquals("Hello World", mock.doSomething(null))10 }11 fun `anyVararg() method of Matchers class`() {12 val mock = mock<Mockable>()13 `when`(mock.doSomething(anyVararg())).thenReturn("Hello World")14 assertEquals("Hello World", mock.doSomething("Hello", "World"))15 }16 fun `eq() method of Matchers class`() {17 val mock = mock<Mockable>()18 `when`(mock.doSomething(eq("Hello World"))).thenReturn("Hello World")19 assertEquals("Hello World", mock.doSomething("Hello World"))20 }21 fun `argThat() method of Matchers class`() {22 val mock = mock<Mockable>()23 `when`(mock.doSomething(argThat { it.startsWith("Hello") })).thenReturn("Hello World")24 assertEquals("Hello World", mock.doSomething("Hello World"))25 }26 fun `check() method of Matchers class`() {27 val mock = mock<Mockable>()28 `when`(mock.doSomething(check { it.startsWith("Hello") })).thenReturn("Hello World")29 assertEquals("Hello World", mock.doSomething("Hello World"))30 }31 fun `isNull() method of Matchers class`() {32 val mock = mock<Mockable>()33 `when`(mock.doSomething(isNull())).thenReturn("Hello World")34 assertEquals("Hello World", mock.doSomething(null))35 }

Full Screen

Full Screen

notNull

Using AI Code Generation

copy

Full Screen

1val mock = mock<MockedClass>()2val mock = mock<MockedClass>()3val mock = mock<MockedClass>()4whenever(mock.getValues()).thenReturn(listOf("value1", "value2"))5 when(mock.getValues(anyInt(), anyString())).thenReturn("foo");6at com.nhaarman.mockitokotlin2.KStubbing.getAnswer(KStubbing.kt:27)7at com.nhaarman.mockitokotlin2.KStubbing.thenReturn(KStubbing.kt:42)8at com.nhaarman.mockitokotlin2.KStubbing.thenReturn$default(KStubbing.kt:41)9at com.nhaarman.mockitokotlin2.KStubbing.thenReturn(KStubbing.kt:40)10val mock = mock<MockedClass>()11whenever(mock.getValues()).thenReturn(listOf("value1", "value2"))

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mockito-kotlin automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful