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

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

NotificationControllerTest.kt

Source:NotificationControllerTest.kt Github

copy

Full Screen

...18import org.mockito.Mockito.anyInt19import org.mockito.Mockito.anyString20import org.mockito.Mockito.times21import org.mockito.Mockito.verify22import org.mockito.kotlin.anyOrNull23import org.mockito.kotlin.argumentCaptor24import org.mockito.kotlin.whenever25import org.springframework.boot.test.mock.mockito.MockBean26import org.springframework.test.web.servlet.request.MockMvcRequestBuilders27import org.springframework.test.web.servlet.result.MockMvcResultMatchers28import java.util.UUID29class NotificationControllerTest : AbstractControllerTest() {30 @MockBean31 lateinit var notificationService: NotificationService32 @Test33 fun `delete notification`() {34 // Given35 val notificationId = IdGenerator.randomString()36 // When37 val mvcActions = mockMvc.perform(38 MockMvcRequestBuilders.delete(String.format("/notification/%s", notificationId))39 .contentType("application/json")40 .header("Authorization", "Bearer " + generateRbkAdminJwt())41 .header("X-Request-ID", "testRequestId")42 )43 // Then44 argumentCaptor<String> {45 verify(notificationService, times(1)).softDeleteNotification(anyString(), capture())46 assertEquals(notificationId, firstValue)47 }48 }49 @Test50 fun `delete multiple notification`() {51 // Given52 val firstNotificationId = UUID.randomUUID()53 val secondNotificationId = UUID.randomUUID()54 val deleteNotification = DeleteNotification().apply {55 addNotificationIdsItem(firstNotificationId)56 addNotificationIdsItem(secondNotificationId)57 }58 // When59 val mvcActions = mockMvc.perform(60 MockMvcRequestBuilders.delete("/notification/remove")61 .contentType("application/json")62 .header("Authorization", "Bearer " + generateRbkAdminJwt())63 .header("X-Request-ID", "testRequestId")64 .content(ObjectMapper().writeValueAsString(deleteNotification))65 )66 // Then67 argumentCaptor<String> {68 verify(notificationService, times(1)).softDeleteNotification(anyString(), capture())69 assertTrue(allValues.contains(firstNotificationId.toString()))70 assertTrue(allValues.contains(secondNotificationId.toString()))71 }72 }73 @Test74 fun `get notification`() {75 // Given76 val notificationId = IdGenerator.randomString()77 val notificationEntity = EasyRandom().nextObject(NotificationEntity::class.java).apply {78 this.notificationId = notificationId.toString()79 }80 whenever(notificationService.getNotification(anyString())).then { notificationEntity }81 // When82 val mvcActions = mockMvc.perform(83 MockMvcRequestBuilders.get(String.format("/notification/%s", notificationId))84 .contentType("application/json")85 .header("Authorization", "Bearer " + generateRbkAdminJwt())86 .header("X-Request-ID", "testRequestId")87 )88 // Then89 mvcActions.andExpect(MockMvcResultMatchers.status().is2xxSuccessful)90 .andExpect(MockMvcResultMatchers.jsonPath("$.id", equalTo(notificationId)))91 .andExpect(MockMvcResultMatchers.jsonPath("$.createdAt").isNotEmpty)92 .andExpect(MockMvcResultMatchers.jsonPath("$.status", equalTo(notificationEntity.status.name)))93 .andExpect(94 MockMvcResultMatchers.jsonPath(95 "$.title",96 equalTo(notificationEntity.notificationTemplateEntity?.title)97 )98 )99 .andExpect(100 MockMvcResultMatchers.jsonPath(101 "$.content",102 equalTo(notificationEntity.notificationTemplateEntity?.content)103 )104 )105 }106 @Test107 fun `mark notification`() {108 // Given109 val notificationId = UUID.randomUUID()110 val requestBody = MarkNotifications().apply {111 status = MarkNotifications.StatusEnum.READ112 notificationIds = mutableListOf(notificationId)113 }114 // When115 val mvcActions = mockMvc.perform(116 MockMvcRequestBuilders.post("/notification/mark")117 .contentType("application/json")118 .header("Authorization", "Bearer " + generateRbkAdminJwt())119 .header("X-Request-ID", "testRequestId")120 .content(ObjectMapper().writeValueAsString(requestBody))121 )122 // Then123 mvcActions.andExpect(MockMvcResultMatchers.status().is2xxSuccessful)124 argumentCaptor<List<String>> {125 verify(notificationService, times(1)).notificationMark(anyString(), capture(), anyOrNull())126 assertEquals(notificationId.toString(), firstValue[0])127 }128 }129 @Test130 fun `mark multiple notification`() {131 // Given132 val notificationId = UUID.randomUUID()133 val requestBody = MarkAllNotifications().apply {134 status = MarkAllNotifications.StatusEnum.READ135 }136 // When137 val mvcActions = mockMvc.perform(138 MockMvcRequestBuilders.post("/notification/mark/all")139 .contentType("application/json")140 .header("Authorization", "Bearer " + generateRbkAdminJwt())141 .header("X-Request-ID", "testRequestId")142 .content(ObjectMapper().writeValueAsString(requestBody))143 )144 // Then145 mvcActions.andExpect(MockMvcResultMatchers.status().is2xxSuccessful)146 argumentCaptor<NotificationStatus> {147 verify(notificationService, times(1)).notificationMarkAll(anyString(), capture())148 assertEquals(NotificationStatus.read, firstValue)149 }150 }151 @Test152 fun `search notifications`() {153 // Given154 val titleFilter = "my title"155 val notificationEntity = EasyRandom().nextObject(NotificationEntity::class.java).apply {156 notificationId = IdGenerator.randomString()157 status = NotificationStatus.unread158 }159 // When160 whenever(notificationService.findNotifications(anyOrNull(), anyOrNull(), anyInt())).then {161 Page(listOf(notificationEntity), token = null, hasNext = false)162 }163 val mvcActions = mockMvc.perform(164 MockMvcRequestBuilders.get("/notification")165 .contentType("application/json")166 .header("Authorization", "Bearer " + generateRbkAdminJwt())167 .header("X-Request-ID", "testRequestId")168 .queryParam("title", titleFilter)169 )170 // Then171 mvcActions.andExpect(MockMvcResultMatchers.status().is2xxSuccessful)172 .andExpect(MockMvcResultMatchers.jsonPath("$.result").isNotEmpty)173 .andExpect(MockMvcResultMatchers.jsonPath("$.result[0].id", `is`(notificationEntity.notificationId)))174 .andExpect(MockMvcResultMatchers.jsonPath("$.result[0].status", `is`(notificationEntity.status.name)))175 .andExpect(176 MockMvcResultMatchers.jsonPath(177 "$.result[0].title",178 `is`(notificationEntity.notificationTemplateEntity?.title)179 )180 )181 .andExpect(182 MockMvcResultMatchers.jsonPath(183 "$.result[0].content",184 `is`(notificationEntity.notificationTemplateEntity?.content)185 )186 )187 argumentCaptor<NotificationFilter> {188 verify(notificationService, times(1)).findNotifications(capture(), anyOrNull(), anyInt())189 assertEquals(titleFilter, firstValue.title)190 }191 }192}...

Full Screen

Full Screen

MatchersTest.kt

Source:MatchersTest.kt Github

copy

Full Screen

...69 @Test70 fun anyNull_verifiesAnyOrNull() {71 mock<Methods>().apply {72 nullableString(null)73 verify(this).nullableString(anyOrNull())74 }75 }76 @Test77 fun anyNull_forPrimitiveBoolean() {78 mock<Methods>().apply {79 boolean(false)80 verify(this).boolean(anyOrNull())81 }82 }83 @Test84 fun anyNull_forPrimitiveByte() {85 mock<Methods>().apply {86 byte(3)87 verify(this).byte(anyOrNull())88 }89 }90 @Test91 fun anyNull_forPrimitiveChar() {92 mock<Methods>().apply {93 char('a')94 verify(this).char(anyOrNull())95 }96 }97 @Test98 fun anyNull_forPrimitiveShort() {99 mock<Methods>().apply {100 short(3)101 verify(this).short(anyOrNull())102 }103 }104 @Test105 fun anyNull_forPrimitiveInt() {106 mock<Methods>().apply {107 int(3)108 verify(this).int(anyOrNull())109 }110 }111 @Test112 fun anyNull_forPrimitiveLong() {113 mock<Methods>().apply {114 long(3)115 verify(this).long(anyOrNull())116 }117 }118 @Test119 fun anyNull_forPrimitiveFloat() {120 mock<Methods>().apply {121 float(3f)122 verify(this).float(anyOrNull())123 }124 }125 @Test126 fun anyNull_forPrimitiveDouble() {127 mock<Methods>().apply {128 double(3.0)129 verify(this).double(anyOrNull())130 }131 }132 /** https://github.com/nhaarman/mockito-kotlin/issues/27 */133 @Test134 fun anyThrowableWithSingleThrowableConstructor() {135 mock<Methods>().apply {136 throwableClass(ThrowableClass(IOException()))137 verify(this).throwableClass(any())138 }139 }140 @Test141 fun listArgThat() {142 mock<Methods>().apply {143 closedList(listOf(Closed(), Closed()))...

Full Screen

Full Screen

AddPresenterTests.kt

Source:AddPresenterTests.kt Github

copy

Full Screen

...19import org.mockito.Captor20import org.mockito.Mock21import org.mockito.Mockito22import org.mockito.junit.MockitoJUnitRunner23import org.mockito.kotlin.anyOrNull24import org.mockito.kotlin.times2526@RunWith(MockitoJUnitRunner::class)27class AddPresenterTests : BaseTest() {2829 @Rule30 @JvmField31 // An instance of this class overrides the Schedulers used.32 // Its use was not necessary, because the Schedulers were requested via the interface.33 var testSchedulerRule = RxSchedulerRule()3435 @Mock36 private lateinit var mockView: Add.View3738 @Mock39 private lateinit var mockDataSource: RemoteDataSource4041 @Captor42 private lateinit var noteArgCaptor: ArgumentCaptor<Note>4344 private lateinit var addPresenter: AddPresenter4546 private val fakeNote: Note47 get() = Note(title = "Nota A", body = "Seja bem vindo Nota A", date = "01/10/2021")4849 @Before50 fun setup() {51 addPresenter = AddPresenter(1, mockView, mockDataSource)52 }5354 @Test55 fun `test must display note`() {56 //Give57 Mockito.doReturn(Schedulers.trampoline()).`when`(mockView).getBackgroundScheduler()58 Mockito.doReturn(Schedulers.trampoline()).`when`(mockView).getForegroundScheduler()59 Mockito.doReturn(Single.just(fakeNote)).`when`(mockDataSource).getNote(1)6061 //When62 addPresenter.getNoteDetail()6364 //Then65 Mockito.verify(mockView, times(1)).getBackgroundScheduler()66 Mockito.verify(mockView, times(1)).getForegroundScheduler()67 Mockito.verify(mockView).displayNote(fakeNote.title!!, fakeNote.body!!)68 }6970 @Test71 fun `test must not add note with empty body`() {72 val exception = Exception("O título deve ser informado!")73 //Give74 Mockito.doReturn(Schedulers.trampoline()).`when`(mockView).getBackgroundScheduler()75 Mockito.doReturn(Schedulers.trampoline()).`when`(mockView).getForegroundScheduler()7677 //When78 addPresenter.createNote("", "")7980 //Then81 Mockito.verify(mockView, times(1)).getBackgroundScheduler()82 Mockito.verify(mockView, times(1)).getForegroundScheduler()83 Mockito.verify(mockView).displayError(exception.message!!)84 }8586 @Test87 fun `test must create a new note`() {88 //Give89 Mockito.doReturn(Schedulers.trampoline()).`when`(mockView).getBackgroundScheduler()90 Mockito.doReturn(Schedulers.trampoline()).`when`(mockView).getForegroundScheduler()91 Mockito.doReturn(Completable.complete()).`when`(mockDataSource).createNote(92 captureArg(93 noteArgCaptor94 )95 )9697 //When98 addPresenter.createNote(fakeNote.title!!, fakeNote.body!!)99100 //Then101 Mockito.verify(mockDataSource).createNote(captureArg(noteArgCaptor))102 //Additional103 MatcherAssert.assertThat(noteArgCaptor.value.title, CoreMatchers.equalTo(fakeNote.title))104 MatcherAssert.assertThat(noteArgCaptor.value.body, CoreMatchers.equalTo(fakeNote.body))105106 Mockito.verify(mockView, times(1)).getBackgroundScheduler()107 Mockito.verify(mockView, times(1)).getForegroundScheduler()108 Mockito.verify(mockView).returnToHome()109 }110111 @Test112 fun `test must show error messsage when creation failure`() {113 //Give114 Mockito.doReturn(Schedulers.trampoline()).`when`(mockView).getBackgroundScheduler()115 Mockito.doReturn(Schedulers.trampoline()).`when`(mockView).getForegroundScheduler()116 Mockito.doReturn(Completable.error(Exception("Erro ao criar a Nota!")))117 .`when`(mockDataSource)118 .createNote(anyOrNull())119120 //When121 addPresenter.createNote(fakeNote.title!!, fakeNote.body!!)122123 //Then124 Mockito.verify(mockDataSource).createNote(captureArg(noteArgCaptor))125 //Additional126 MatcherAssert.assertThat(noteArgCaptor.value.title, CoreMatchers.equalTo(fakeNote.title))127 MatcherAssert.assertThat(noteArgCaptor.value.body, CoreMatchers.equalTo(fakeNote.body))128129 Mockito.verify(mockView, times(1)).getBackgroundScheduler()130 Mockito.verify(mockView, times(1)).getForegroundScheduler()131 Mockito.verify(mockView).displayError("Erro ao criar a Nota!")132 } ...

Full Screen

Full Screen

SummaryRepositoryTest.kt

Source:SummaryRepositoryTest.kt Github

copy

Full Screen

...10import com.kondenko.pocketwaka.utils.date.DateRange11import com.kondenko.pocketwaka.utils.date.DateRangeString12import com.kondenko.pocketwaka.utils.extensions.assertInOrder13import com.kondenko.pocketwaka.utils.extensions.testWithLogging14import com.nhaarman.mockito_kotlin.anyOrNull15import com.nhaarman.mockito_kotlin.mock16import com.nhaarman.mockito_kotlin.whenever17import io.reactivex.Completable18import io.reactivex.Maybe19import io.reactivex.Observable20import io.reactivex.Single21import io.reactivex.rxkotlin.toObservable22import io.reactivex.schedulers.TestScheduler23import org.junit.Test24import org.mockito.ArgumentMatchers.anyInt25import org.mockito.ArgumentMatchers.anyString26import java.util.concurrent.TimeUnit27class SummaryRepositoryTest {28 private val scheduler = TestScheduler()29 private val service: SummaryService = mock()30 private val dao: SummaryDao = mock()31 private val repository = SummaryRepository(service, dao, testSchedulers.workerScheduler)32 { _, _, _ -> dbModel }33 private val uiModels = listOf(SummaryUiModel.TimeTracked("", 0))34 private val dbModel = SummaryDbModel(0, false, false, false, uiModels)35 private val dataFromServer = Summary(emptyList())36 private val dataFromCache = listOf(dbModel.copy(isEmpty = true, isFromCache = true), dbModel.copy(isFromCache = true))37 private val convertedDataFromServer = listOf(dbModel.copy(isAccountEmpty = true), dbModel)38 private val params = SummaryRepository.Params("", DateRange.SingleDay(mock()), DateRangeString("", ""), null, null)39 @Test40 fun `should only emit data from cache`() {41 val delay = 100L42 whenever(dao.getSummaries(anyInt()))43 .thenReturn(Maybe.just(dataFromCache))44 whenever(service.getSummaries(anyString(), anyString(), anyString(), anyOrNull(), anyOrNull()))45 .thenReturn(Single.error(TestException()))46 whenever(dao.cacheSummary(anyOrNull()))47 .thenReturn(Completable.error(TestException()))48 val repoObservable = repository.getData(params) {49 Observable.error(TestException())50 }51 with(repoObservable.testWithLogging()) {52 scheduler.advanceTimeBy(delay, TimeUnit.MILLISECONDS)53 assertInOrder {54 assert { it.isFromCache }55 assert { it.isFromCache }56 }57 assertNoErrors()58 assertComplete()59 }60 }61 @Test62 fun `should return data from server`() {63 val delay = 100L64 whenever(dao.getSummaries(anyInt()))65 .thenReturn(Maybe.just(dataFromCache))66 whenever(service.getSummaries(anyString(), anyString(), anyString(), anyOrNull(), anyOrNull()))67 .thenReturn(Single.just(dataFromServer).delay(delay, TimeUnit.MILLISECONDS, scheduler))68 whenever(dao.cacheSummary(anyOrNull()))69 .thenReturn(Completable.complete())70 val repoObservable = repository.getData(params) {71 convertedDataFromServer.toObservable()72 }73 with(repoObservable.testWithLogging()) {74 scheduler.advanceTimeBy(delay, TimeUnit.MILLISECONDS)75 assertInOrder {76 assert { !it.isFromCache }77 assert { !it.isFromCache }78 }79 assertNoErrors()80 assertComplete()81 }82 }83 @Test84 fun `should ignore caching error`() {85 val delay = 100L86 whenever(dao.getSummaries(anyInt()))87 .thenReturn(Maybe.just(dataFromCache))88 whenever(service.getSummaries(anyString(), anyString(), anyString(), anyOrNull(), anyOrNull()))89 .thenReturn(Single.just(dataFromServer).delay(delay, TimeUnit.MILLISECONDS, scheduler))90 whenever(dao.cacheSummary(anyOrNull()))91 .thenReturn(Completable.error(TestException()))92 val repoObservable = repository.getData(params) {93 convertedDataFromServer.toObservable()94 }95 with(repoObservable.testWithLogging()) {96 scheduler.advanceTimeBy(delay, TimeUnit.MILLISECONDS)97 assertNoErrors()98 assertComplete()99 }100 }101}...

Full Screen

Full Screen

AccessTokenRepositoryTest.kt

Source:AccessTokenRepositoryTest.kt Github

copy

Full Screen

...4import com.kondenko.pocketwaka.data.auth.service.AccessTokenService5import com.kondenko.pocketwaka.testutils.RxRule6import com.kondenko.pocketwaka.testutils.getAccessTokenMock7import com.kondenko.pocketwaka.utils.exceptions.UnauthorizedException8import com.nhaarman.mockito_kotlin.anyOrNull9import com.nhaarman.mockito_kotlin.doReturn10import com.nhaarman.mockito_kotlin.mock11import com.nhaarman.mockito_kotlin.whenever12import io.reactivex.Single13import org.junit.Rule14import org.junit.Test15import org.mockito.ArgumentMatchers.anyFloat16import org.mockito.ArgumentMatchers.anyString17class AccessTokenRepositoryTest {18 @get:Rule19 val rxRule = RxRule()20 private val accessTokenService: AccessTokenService = mock()21 private val sp: SharedPreferences = mock()22 private val accessTokenRepository = AccessTokenRepository(accessTokenService, sp)23 @Test24 fun `should acquire new token`() {25 val token: AccessToken = mock()26 whenever(accessTokenService.getAccessToken(anyString(), anyString(), anyString(), anyString(), anyString()))27 .doReturn(Single.just(token))28 val tokenSingle = accessTokenRepository.getNewAccessToken("string", "string", "string", "string", "string")29 with(tokenSingle.test()) {30 assertNoErrors()31 assertComplete()32 assertValue(token)33 }34 }35 @Test36 fun `should fail if not saved`() {37 whenever(sp.contains(anyString())).doReturn(false)38 val errorSingle = accessTokenRepository.getEncryptedToken()39 with(errorSingle.test()) {40 assertFailure(UnauthorizedException::class.java)41 assertNotComplete()42 assertTerminated()43 }44 }45 @Test46 fun `should return encrypted token`() {47 val tokenStringField = "foo"48 val token: AccessToken = getAccessTokenMock(tokenStringField)49 whenever(sp.contains(anyString())).doReturn(true)50 whenever(sp.getString(anyString(), anyOrNull())).doReturn(tokenStringField)51 whenever(sp.getFloat(anyString(), anyFloat())).doReturn(0f)52 val tokenSingle = accessTokenRepository.getEncryptedToken()53 with(tokenSingle.test()) {54 assertValue(token)55 assertNoErrors()56 assertComplete()57 }58 }59}...

Full Screen

Full Screen

MockTest.kt

Source:MockTest.kt Github

copy

Full Screen

1package com.robotsandpencils.kotlindaggerexperiement.tests2import com.nhaarman.mockito_kotlin.anyOrNull3import com.nhaarman.mockito_kotlin.eq4import com.nhaarman.mockito_kotlin.mock5import com.nhaarman.mockito_kotlin.whenever6import com.robotsandpencils.kotlindaggerexperiement.App7import com.robotsandpencils.kotlindaggerexperiement.TestHelper8import com.robotsandpencils.kotlindaggerexperiement.app.managers.PreferencesManager9import com.robotsandpencils.kotlindaggerexperiement.app.modules.AppModule10import com.robotsandpencils.kotlindaggerexperiement.base.BaseDaggerTestHarness11import com.robotsandpencils.kotlindaggerexperiement.base.BaseTest12import org.hamcrest.Matchers13import org.junit.Assert14import org.junit.Before15import org.junit.Test16import javax.inject.Inject17/**18 * Just a test to show how to write a test that mocks or uses19 * injection from a component. If you use the @InjectFromComponent ensure20 * there is a method that returns the type of object you want to use21 * in the AppComponent interface. Dagger will happily generate an accessor22 * for that value, but without it, you'll be forever wondering why your23 * object is null in your test.24 */25class MockTest : BaseTest() {26 @Inject27 lateinit var preferencesManager: PreferencesManager28 // Just need to override the preferences manager to make it a mock29 class TestAppModule(app: App) : AppModule(app) {30 override fun providePreferencesManager(): PreferencesManager = mock()31 }32 @Before33 override fun before() {34 super.before()35 val app = TestHelper.getApp()36 BaseDaggerTestHarness(app = app, appModule = TestAppModule(app))37 .userComponent.inject(this)38 }39 /**40 * This test is a little contrived, but just serves to show that indeed, the preferencesManager41 * is mocked and returning the appropriate value when called with appropriate parameters.42 * This also shows some of the convenient stuff in the mockito_kotlin library such as a nice43 * way to avoid back-ticks when using mockito when (use whenever instead) for example.44 */45 @Test46 fun mockPreferencesManagerTest() {47 whenever(preferencesManager.getString(eq("key"), anyOrNull()))48 .thenReturn("Testing")49 Assert.assertThat(preferencesManager.getString("key", null), Matchers.equalTo("Testing"))50 }51}...

Full Screen

Full Screen

FillingTest.kt

Source:FillingTest.kt Github

copy

Full Screen

...21 */22class FillingTest23{24 val loader: ResourceLoader = mock {25 on { loadResource(anyOrNull()) } .then { mock<InputStream>() }26 }27 val namingResolver: ResourceNamingResolver = mock {28 on { resolve(anyOrNull(), anyOrNull(), anyOrNull()) } .then { "resolve" }29 }30 val serializer: ResourceSerializer = mock {31 on { createEntity<DataClass>(anyOrNull(), anyOrNull()) } .then { DataClass() }32 }33 val options: Options = mock {34 on { loader }.doReturn(loader)35 on { namingResolver }.doReturn(namingResolver)36 on { serializer }.doReturn(serializer)37 }38 @Test39 fun `fill class`()40 {41 val filling = Filling(options)42 var fill = filling.fill(DataClass::class)43 var javaFill = filling.fill(DataClass::class.java)44 var reifiedFill: DataClass = filling.fill()45 verify(loader, times(3)).loadResource(anyOrNull())46 verify(namingResolver, times(3)).resolve(anyOrNull(), anyOrNull(), anyOrNull())47 verify(serializer, times(3)).createEntity<DataClass>(anyOrNull(), anyOrNull())48 }49}...

Full Screen

Full Screen

ExchangeCommandsTest.kt

Source:ExchangeCommandsTest.kt Github

copy

Full Screen

...22 private val from: Currency = Currency(name = "test", abbreviation = "test", symbol = "£")23 private val to: Currency = Currency(name = "asd", abbreviation = "asd", symbol = "$")24 @Test25 fun onExchange() {26 `when`(economyAPI.exchangeAmount(anyOrNull(), anyOrNull(), anyOrNull(), anyDouble())).thenReturn(false)27 exchangeCommands.onExchange(player, from, to, 20.0)28 verify(economyAPI, times(1)).exchangeAmount(anyOrNull(), anyOrNull(), anyOrNull(), anyDouble())29 verifyNoMoreInteractions(economyAPI)30 verify(localeMessenger, times(1)).sendMessage(anyOrNull(), anyString())31 verifyNoMoreInteractions(localeMessenger)32 }33}...

Full Screen

Full Screen

anyOrNull

Using AI Code Generation

copy

Full Screen

1val anyOrNullString: String? = anyOrNull()2val anyOrNullList: List<String>? = anyOrNull()3val anyOrNullMap: Map<String, Int>? = anyOrNull()4val anyOrNullStringArray: Array<String>? = anyOrNull()5val anyOrNullIntArray: IntArray? = anyOrNull()6val anyOrNullLongArray: LongArray? = anyOrNull()7val anyOrNullDoubleArray: DoubleArray? = anyOrNull()8val anyOrNullFloatArray: FloatArray? = anyOrNull()9val anyOrNullByteArray: ByteArray? = anyOrNull()10val anyOrNullShortArray: ShortArray? = anyOrNull()11val anyOrNullCharArray: CharArray? = anyOrNull()12val anyOrNullBooleanArray: BooleanArray? = anyOrNull()13val anyOrNullIntArray2D: Array<IntArray>? = anyOrNull()14val anyOrNullStringList: List<List<String>>? = anyOrNull()15val anyOrNullStringMap: Map<String, Map<String, String>>? = anyOrNull()16val anyOrNullStringListMap: Map<String, List<Map<String, List<String>>>>? = anyOrNull()17val anyOrNullStringListMapList: List<Map<String, List<Map<String, List<String>>>>>? = anyOrNull()18val anyOrNullStringListMapList2D: Array<List<Map<String, List<Map<String, List<String>>>>>>? = anyOrNull()19val anyOrNullStringListMapList2DArray: Array<Array<List<Map<String, List<Map<String, List<String>>>>>>>? = anyOrNull()20val anyOrNullStringListMapList2DArray3D: Array<Array<Array<List<Map<String, List<Map<String, List<String>>>>>>>>? = anyOrNull()21val anyOrNullStringListMapList2DArray3D4D: Array<Array<Array<Array<List<Map<String, List<Map<String, List<String>>>>>>>>>>? = anyOrNull()22val anyOrNullStringListMapList2DArray3D4D5D: Array<Array<Array<Array<Array<List<Map<String, List<Map<String, List<String>>>>>>>>>>>? = anyOrNull()23val anyOrNullStringListMapList2DArray3D4D5D6D: Array<Array<Array<Array<Array<Array<List<Map<String, List<Map<String, List<String>>>>>>>>>>>>? = anyOrNull()24val anyOrNullStringListMapList2DArray3D4D5D6D7D: Array<Array<Array<Array<Array<Array<Array<List<Map<String, List<Map<String, List<String>>>>>>>>>>>>>? = anyOrNull()

Full Screen

Full Screen

anyOrNull

Using AI Code Generation

copy

Full Screen

1val mockedList = mock < MutableList < String >> ()2whenever ( mockedList . anyOrNull ()) . thenReturn ( "foo" )3println ( mockedList . get ( 1 ))4verify ( mockedList ). add ( anyOrNull ())5verify ( mockedList ). add ( ArgumentMatchers . anyString ())6whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . thenReturn ( true )7whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . then { true }8whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . thenAnswer { true }9whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . thenThrow ( RuntimeException ())10whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . thenCallRealMethod ()11whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . doReturn ( true )12whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . doAnswer { true }13whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . doThrow ( RuntimeException ())14whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . doCallRealMethod ()15whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . doNothing ()16whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . doNothing ()17whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . doNothing ()18whenever ( mockedList . add ( ArgumentMatchers . anyString ())) . doNothing ()

Full Screen

Full Screen

anyOrNull

Using AI Code Generation

copy

Full Screen

1val mockedList = mock<MutableList<String>>()2whenever(mockedList[anyOrNull()]).thenReturn("element")3println(mockedList[0])4println(mockedList[1])5println(mockedList[2])6println(mockedList[3])7println(mockedList[4])8println(mockedList[5])9println(mockedList[6])10println(mockedList[7])11println(mockedList[8])12println(mockedList[9])13println(mockedList[10])14println(mockedList[11])15println(mockedList[12])16println(mockedList[13])17println(mockedList[14])18println(mockedList[15])19println(mockedList[16])20println(mockedList[17])21println(mockedList[18])22println(mockedList[19])23println(mockedList[20])24println(mockedList[21])25println(mockedList[22])26println(mock

Full Screen

Full Screen

anyOrNull

Using AI Code Generation

copy

Full Screen

1val mockedList: List<String> = mock()2whenever(mockedList.anyOrNull()).thenReturn("hello")3println(mockedList.anyOrNull())4println(mockedList.anyOrNull())5verify(mockedList).anyOrNull()6assertEquals("hello", mockedList.anyOrNull())7verify(mockedList, never()).anyOrNull()8verify(mockedList, times(1)).anyOrNull()9verify(mockedList, atLeastOnce()).anyOrNull()10verify(mockedList, atLeast(2)).anyOrNull()11verify(mockedList, atMost(5)).anyOrNull()12verify(mockedList).anyOrNull("hello")13verify(mockedList, never()).anyOrNull("world")14verify(mockedList).anyOrNull(argThat { it.startsWith("h") })15verify(mockedList).anyOrNull(argThat { it.startsWith("h") })

Full Screen

Full Screen

anyOrNull

Using AI Code Generation

copy

Full Screen

1val mockedList = mock<MutableList<String>>()2whenever(mockedList.anyOrNull()).thenReturn("hello")3val mockedList = mock<MutableList<String>>()4whenever(mockedList.anyOrNull()).thenReturn("hello")5val mockedList = mock<MutableList<String>>()6whenever(mockedList.anyOrNull()).thenReturn("hello")7val mockedList = mock<MutableList<String>>()8whenever(mockedList.anyOrNull()).thenReturn("hello")9val mockedList = mock<MutableList<String>>()10whenever(mockedList.anyOrNull()).thenReturn("hello")11val mockedList = mock<MutableList<String>>()12whenever(mockedList.anyOrNull()).thenReturn("hello")13val mockedList = mock<MutableList<String>>()14whenever(mockedList.anyOrNull()).thenReturn("hello")15val mockedList = mock<MutableList<String>>()16whenever(mockedList.anyOrNull()).thenReturn("hello")17val mockedList = mock<MutableList<String>>()18whenever(mockedList.anyOrNull()).thenReturn("hello")19val mockedList = mock<MutableList<String>>()20whenever(mockedList.anyOrNull()).thenReturn("hello")21val mockedList = mock<MutableList<String>>()22whenever(mockedList.anyOrNull()).thenReturn("hello")

Full Screen

Full Screen

anyOrNull

Using AI Code Generation

copy

Full Screen

1 val mockList = mock<List<String>>()2 whenever(mockList.anyOrNull() ?: "default").thenReturn("default")3 assertEquals("default", mockList.anyOrNull() ?: "default")4 val mockList = mock<List<String>>()5 whenever(mockList.anyOrNull() ?: "default").thenReturn("default")6 assertEquals("default", mockList.anyOrNull() ?: "default")7 val mockList = mock<List<String>>()8 whenever(mockList.any() ?: "default").thenReturn("default")9 assertEquals("default", mockList.any() ?: "default")10 val mockList = mock<List<String>>()11 whenever(mockList.any() ?: "default").thenReturn("default")12 assertEquals("default", mockList.any() ?: "default")13 val mockList = mock<List<String>>()14 whenever(mockList.any() ?: "default").thenReturn("default")15 assertEquals("default", mockList.any() ?: "default")16 val mockList = mock<List<String>>()17 whenever(mockList.any() ?: "default").thenReturn("default")18 assertEquals("default", mockList.any() ?: "default")

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