How to use test class

Best Atoum code snippet using test

ControlsControllerImplTest.kt

Source:ControlsControllerImplTest.kt Github

copy

Full Screen

...24import android.os.UserHandle25import android.service.controls.Control26import android.service.controls.DeviceTypes27import android.service.controls.actions.ControlAction28import android.testing.AndroidTestingRunner29import androidx.test.filters.SmallTest30import com.android.systemui.SysuiTestCase31import com.android.systemui.backup.BackupHelper32import com.android.systemui.broadcast.BroadcastDispatcher33import com.android.systemui.controls.ControlStatus34import com.android.systemui.controls.ControlsServiceInfo35import com.android.systemui.controls.management.ControlsListingController36import com.android.systemui.controls.ui.ControlsUiController37import com.android.systemui.dump.DumpManager38import com.android.systemui.settings.UserTracker39import com.android.systemui.util.concurrency.FakeExecutor40import com.android.systemui.util.time.FakeSystemClock41import org.junit.After42import org.junit.Assert.assertEquals43import org.junit.Assert.assertFalse44import org.junit.Assert.assertNotEquals45import org.junit.Assert.assertTrue46import org.junit.Before47import org.junit.Test48import org.junit.runner.RunWith49import org.mockito.ArgumentCaptor50import org.mockito.ArgumentMatchers51import org.mockito.Captor52import org.mockito.Mock53import org.mockito.Mockito54import org.mockito.Mockito.`when`55import org.mockito.Mockito.inOrder56import org.mockito.Mockito.mock57import org.mockito.Mockito.never58import org.mockito.Mockito.reset59import org.mockito.Mockito.verify60import org.mockito.Mockito.verifyNoMoreInteractions61import org.mockito.MockitoAnnotations62import java.util.Optional63import java.util.function.Consumer64@SmallTest65@RunWith(AndroidTestingRunner::class)66class ControlsControllerImplTest : SysuiTestCase() {67 @Mock68 private lateinit var uiController: ControlsUiController69 @Mock70 private lateinit var bindingController: ControlsBindingController71 @Mock72 private lateinit var pendingIntent: PendingIntent73 @Mock74 private lateinit var persistenceWrapper: ControlsFavoritePersistenceWrapper75 @Mock76 private lateinit var auxiliaryPersistenceWrapper: AuxiliaryPersistenceWrapper77 @Mock78 private lateinit var broadcastDispatcher: BroadcastDispatcher79 @Mock80 private lateinit var listingController: ControlsListingController81 @Mock(stubOnly = true)82 private lateinit var userTracker: UserTracker83 @Captor84 private lateinit var structureInfoCaptor: ArgumentCaptor<StructureInfo>85 @Captor86 private lateinit var controlLoadCallbackCaptor:87 ArgumentCaptor<ControlsBindingController.LoadCallback>88 @Captor89 private lateinit var controlLoadCallbackCaptor2:90 ArgumentCaptor<ControlsBindingController.LoadCallback>91 @Captor92 private lateinit var broadcastReceiverCaptor: ArgumentCaptor<BroadcastReceiver>93 @Captor94 private lateinit var listingCallbackCaptor:95 ArgumentCaptor<ControlsListingController.ControlsListingCallback>96 private lateinit var delayableExecutor: FakeExecutor97 private lateinit var controller: ControlsControllerImpl98 private lateinit var canceller: DidRunRunnable99 companion object {100 fun <T> capture(argumentCaptor: ArgumentCaptor<T>): T = argumentCaptor.capture()101 fun <T> eq(value: T): T = Mockito.eq(value) ?: value102 fun <T> any(): T = Mockito.any<T>()103 private val TEST_COMPONENT = ComponentName("test.pkg", "test.class")104 private const val TEST_CONTROL_ID = "control1"105 private const val TEST_CONTROL_TITLE = "Test"106 private const val TEST_CONTROL_SUBTITLE = "TestSub"107 private const val TEST_DEVICE_TYPE = DeviceTypes.TYPE_AC_HEATER108 private const val TEST_STRUCTURE = ""109 private val TEST_CONTROL_INFO = ControlInfo(TEST_CONTROL_ID,110 TEST_CONTROL_TITLE, TEST_CONTROL_SUBTITLE, TEST_DEVICE_TYPE)111 private val TEST_STRUCTURE_INFO = StructureInfo(TEST_COMPONENT,112 TEST_STRUCTURE, listOf(TEST_CONTROL_INFO))113 private val TEST_COMPONENT_2 = ComponentName("test.pkg", "test.class.2")114 private const val TEST_CONTROL_ID_2 = "control2"115 private const val TEST_CONTROL_TITLE_2 = "Test 2"116 private const val TEST_CONTROL_SUBTITLE_2 = "TestSub 2"117 private const val TEST_DEVICE_TYPE_2 = DeviceTypes.TYPE_CAMERA118 private const val TEST_STRUCTURE_2 = "My House"119 private val TEST_CONTROL_INFO_2 = ControlInfo(TEST_CONTROL_ID_2,120 TEST_CONTROL_TITLE_2, TEST_CONTROL_SUBTITLE_2, TEST_DEVICE_TYPE_2)121 private val TEST_STRUCTURE_INFO_2 = StructureInfo(TEST_COMPONENT_2,122 TEST_STRUCTURE_2, listOf(TEST_CONTROL_INFO_2))123 }124 private val user = mContext.userId125 private val otherUser = user + 1126 @Before127 fun setUp() {128 MockitoAnnotations.initMocks(this)129 `when`(userTracker.userHandle).thenReturn(UserHandle.of(user))130 delayableExecutor = FakeExecutor(FakeSystemClock())131 val wrapper = object : ContextWrapper(mContext) {132 override fun createContextAsUser(user: UserHandle, flags: Int): Context {133 return baseContext134 }135 }136 canceller = DidRunRunnable()137 `when`(bindingController.bindAndLoad(any(), any())).thenReturn(canceller)138 controller = ControlsControllerImpl(139 wrapper,140 delayableExecutor,141 uiController,142 bindingController,143 listingController,144 broadcastDispatcher,145 Optional.of(persistenceWrapper),146 mock(DumpManager::class.java),147 userTracker148 )149 controller.auxiliaryPersistenceWrapper = auxiliaryPersistenceWrapper150 verify(broadcastDispatcher).registerReceiver(151 capture(broadcastReceiverCaptor), any(), any(), eq(UserHandle.ALL))152 verify(listingController).addCallback(capture(listingCallbackCaptor))153 }154 @After155 fun tearDown() {156 controller.destroy()157 }158 private fun statelessBuilderFromInfo(159 controlInfo: ControlInfo,160 structure: CharSequence = ""161 ): Control.StatelessBuilder {162 return Control.StatelessBuilder(controlInfo.controlId, pendingIntent)163 .setDeviceType(controlInfo.deviceType).setTitle(controlInfo.controlTitle)164 .setSubtitle(controlInfo.controlSubtitle).setStructure(structure)165 }166 private fun statefulBuilderFromInfo(167 controlInfo: ControlInfo,168 structure: CharSequence = ""169 ): Control.StatefulBuilder {170 return Control.StatefulBuilder(controlInfo.controlId, pendingIntent)171 .setDeviceType(controlInfo.deviceType).setTitle(controlInfo.controlTitle)172 .setSubtitle(controlInfo.controlSubtitle).setStructure(structure)173 }174 @Test175 fun testStartOnUser() {176 assertEquals(user, controller.currentUserId)177 }178 @Test179 fun testStartWithoutFavorites() {180 assertTrue(controller.getFavorites().isEmpty())181 }182 @Test183 fun testStartWithSavedFavorites() {184 `when`(persistenceWrapper.readFavorites()).thenReturn(listOf(TEST_STRUCTURE_INFO))185 val controller_other = ControlsControllerImpl(186 mContext,187 delayableExecutor,188 uiController,189 bindingController,190 listingController,191 broadcastDispatcher,192 Optional.of(persistenceWrapper),193 mock(DumpManager::class.java),194 userTracker195 )196 assertEquals(listOf(TEST_STRUCTURE_INFO), controller_other.getFavorites())197 }198 @Test199 fun testOnActionResponse() {200 controller.onActionResponse(TEST_COMPONENT, TEST_CONTROL_ID, ControlAction.RESPONSE_OK)201 verify(uiController).onActionResponse(TEST_COMPONENT, TEST_CONTROL_ID,202 ControlAction.RESPONSE_OK)203 }204 @Test205 fun testRefreshStatus() {206 val control = Control.StatefulBuilder(TEST_CONTROL_ID, pendingIntent).build()207 val list = listOf(control)208 controller.refreshStatus(TEST_COMPONENT, control)209 verify(uiController).onRefreshState(TEST_COMPONENT, list)210 }211 @Test212 fun testUnsubscribe() {213 controller.unsubscribe()214 verify(bindingController).unsubscribe()215 }216 @Test217 fun testSubscribeFavorites() {218 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)219 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO_2)220 delayableExecutor.runAllReady()221 controller.subscribeToFavorites(TEST_STRUCTURE_INFO)222 verify(bindingController).subscribe(capture(structureInfoCaptor))223 assertTrue(TEST_CONTROL_INFO in structureInfoCaptor.value.controls)224 assertFalse(TEST_CONTROL_INFO_2 in structureInfoCaptor.value.controls)225 }226 @Test227 fun testLoadForComponent_noFavorites() {228 var loaded = false229 val control = statelessBuilderFromInfo(TEST_CONTROL_INFO).build()230 controller.loadForComponent(TEST_COMPONENT, Consumer { data ->231 val controls = data.allControls232 val favorites = data.favoritesIds233 loaded = true234 assertEquals(1, controls.size)235 val controlStatus = controls[0]236 assertEquals(ControlStatus(control, TEST_COMPONENT, false), controlStatus)237 assertTrue(favorites.isEmpty())238 assertFalse(data.errorOnLoad)239 }, Consumer {})240 verify(bindingController).bindAndLoad(eq(TEST_COMPONENT),241 capture(controlLoadCallbackCaptor))242 controlLoadCallbackCaptor.value.accept(listOf(control))243 delayableExecutor.runAllReady()244 assertTrue(loaded)245 }246 @Test247 fun testLoadForComponent_favorites() {248 var loaded = false249 val control = statelessBuilderFromInfo(TEST_CONTROL_INFO).build()250 val control2 = statelessBuilderFromInfo(TEST_CONTROL_INFO_2).build()251 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)252 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO_2)253 delayableExecutor.runAllReady()254 controller.loadForComponent(TEST_COMPONENT, Consumer { data ->255 val controls = data.allControls256 val favorites = data.favoritesIds257 loaded = true258 assertEquals(2, controls.size)259 val controlStatus = controls.first { it.control.controlId == TEST_CONTROL_ID }260 assertEquals(ControlStatus(control, TEST_COMPONENT, true), controlStatus)261 val controlStatus2 = controls.first { it.control.controlId == TEST_CONTROL_ID_2 }262 assertEquals(ControlStatus(control2, TEST_COMPONENT, false), controlStatus2)263 assertEquals(1, favorites.size)264 assertEquals(TEST_CONTROL_ID, favorites[0])265 assertFalse(data.errorOnLoad)266 }, Consumer {})267 verify(bindingController).bindAndLoad(eq(TEST_COMPONENT),268 capture(controlLoadCallbackCaptor))269 controlLoadCallbackCaptor.value.accept(listOf(control, control2))270 delayableExecutor.runAllReady()271 assertTrue(loaded)272 }273 @Test274 fun testLoadForComponent_removed() {275 var loaded = false276 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)277 delayableExecutor.runAllReady()278 controller.loadForComponent(TEST_COMPONENT, Consumer { data ->279 val controls = data.allControls280 val favorites = data.favoritesIds281 loaded = true282 assertEquals(1, controls.size)283 val controlStatus = controls[0]284 assertEquals(TEST_CONTROL_ID, controlStatus.control.controlId)285 assertEquals(TEST_STRUCTURE_INFO.structure, controlStatus.control.structure)286 assertTrue(controlStatus.favorite)287 assertTrue(controlStatus.removed)288 assertEquals(1, favorites.size)289 assertEquals(TEST_CONTROL_ID, favorites[0])290 assertFalse(data.errorOnLoad)291 }, Consumer {})292 verify(bindingController).bindAndLoad(eq(TEST_COMPONENT),293 capture(controlLoadCallbackCaptor))294 controlLoadCallbackCaptor.value.accept(emptyList())295 delayableExecutor.runAllReady()296 assertTrue(loaded)297 }298 @Test299 fun testErrorOnLoad_notRemoved() {300 var loaded = false301 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)302 delayableExecutor.runAllReady()303 controller.loadForComponent(TEST_COMPONENT, Consumer { data ->304 val controls = data.allControls305 val favorites = data.favoritesIds306 loaded = true307 assertEquals(1, controls.size)308 val controlStatus = controls[0]309 assertEquals(TEST_CONTROL_ID, controlStatus.control.controlId)310 assertEquals(TEST_STRUCTURE_INFO.structure, controlStatus.control.structure)311 assertTrue(controlStatus.favorite)312 assertFalse(controlStatus.removed)313 assertEquals(1, favorites.size)314 assertEquals(TEST_CONTROL_ID, favorites[0])315 assertTrue(data.errorOnLoad)316 }, Consumer {})317 verify(bindingController).bindAndLoad(eq(TEST_COMPONENT),318 capture(controlLoadCallbackCaptor))319 controlLoadCallbackCaptor.value.error("")320 delayableExecutor.runAllReady()321 assertTrue(loaded)322 }323 @Test324 fun testCancelLoad() {325 var loaded = false326 var cancelRunnable: Runnable? = null327 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)328 delayableExecutor.runAllReady()329 controller.loadForComponent(TEST_COMPONENT, Consumer {330 loaded = true331 }, Consumer { runnable -> cancelRunnable = runnable })332 cancelRunnable?.run()333 delayableExecutor.runAllReady()334 assertFalse(loaded)335 assertTrue(canceller.ran)336 }337 @Test338 fun testCancelLoad_afterSuccessfulLoad() {339 var loaded = false340 var cancelRunnable: Runnable? = null341 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)342 delayableExecutor.runAllReady()343 controller.loadForComponent(TEST_COMPONENT, Consumer {344 loaded = true345 }, Consumer { runnable -> cancelRunnable = runnable })346 verify(bindingController).bindAndLoad(eq(TEST_COMPONENT),347 capture(controlLoadCallbackCaptor))348 controlLoadCallbackCaptor.value.accept(emptyList())349 cancelRunnable?.run()350 delayableExecutor.runAllReady()351 assertTrue(loaded)352 assertTrue(canceller.ran)353 }354 @Test355 fun testCancelLoad_afterErrorLoad() {356 var loaded = false357 var cancelRunnable: Runnable? = null358 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)359 delayableExecutor.runAllReady()360 controller.loadForComponent(TEST_COMPONENT, Consumer {361 loaded = true362 }, Consumer { runnable -> cancelRunnable = runnable })363 verify(bindingController).bindAndLoad(eq(TEST_COMPONENT),364 capture(controlLoadCallbackCaptor))365 controlLoadCallbackCaptor.value.error("")366 cancelRunnable?.run()367 delayableExecutor.runAllReady()368 assertTrue(loaded)369 assertTrue(canceller.ran)370 }371 @Test372 fun testFavoriteInformationModifiedOnLoad() {373 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)374 delayableExecutor.runAllReady()375 val newControlInfo = TEST_CONTROL_INFO.copy(controlTitle = TEST_CONTROL_TITLE_2)376 val control = statelessBuilderFromInfo(newControlInfo).build()377 controller.loadForComponent(TEST_COMPONENT, Consumer {}, Consumer {})378 verify(bindingController).bindAndLoad(eq(TEST_COMPONENT),379 capture(controlLoadCallbackCaptor))380 controlLoadCallbackCaptor.value.accept(listOf(control))381 delayableExecutor.runAllReady()382 val favorites = controller.getFavorites().flatMap { it.controls }383 assertEquals(1, favorites.size)384 assertEquals(newControlInfo, favorites[0])385 }386 @Test387 fun testFavoriteInformationModifiedOnRefreshWithOkStatus() {388 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)389 val newControlInfo = TEST_CONTROL_INFO.copy(controlTitle = TEST_CONTROL_TITLE_2)390 val control = statefulBuilderFromInfo(newControlInfo).setStatus(Control.STATUS_OK).build()391 controller.refreshStatus(TEST_COMPONENT, control)392 delayableExecutor.runAllReady()393 val favorites = controller.getFavorites().flatMap { it.controls }394 assertEquals(1, favorites.size)395 assertEquals(newControlInfo, favorites[0])396 }397 @Test398 fun testFavoriteInformationNotModifiedOnRefreshWithNonOkStatus() {399 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)400 val newControlInfo = TEST_CONTROL_INFO.copy(controlTitle = TEST_CONTROL_TITLE_2)401 val control = statefulBuilderFromInfo(newControlInfo).setStatus(Control.STATUS_ERROR)402 .build()403 controller.refreshStatus(TEST_COMPONENT, control)404 delayableExecutor.runAllReady()405 val favorites = controller.getFavorites().flatMap { it.controls }406 assertEquals(1, favorites.size)407 assertEquals(TEST_CONTROL_INFO, favorites[0])408 }409 @Test410 fun testSwitchUsers() {411 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)412 delayableExecutor.runAllReady()413 reset(persistenceWrapper)414 val intent = Intent(Intent.ACTION_USER_SWITCHED).apply {415 putExtra(Intent.EXTRA_USER_HANDLE, otherUser)416 }417 val pendingResult = mock(BroadcastReceiver.PendingResult::class.java)418 `when`(pendingResult.sendingUserId).thenReturn(otherUser)419 broadcastReceiverCaptor.value.pendingResult = pendingResult420 broadcastReceiverCaptor.value.onReceive(mContext, intent)421 verify(persistenceWrapper).changeFileAndBackupManager(any(), any())422 verify(persistenceWrapper).readFavorites()423 verify(auxiliaryPersistenceWrapper).changeFile(any())424 verify(bindingController).changeUser(UserHandle.of(otherUser))425 verify(listingController).changeUser(UserHandle.of(otherUser))426 assertTrue(controller.getFavorites().isEmpty())427 assertEquals(otherUser, controller.currentUserId)428 }429 @Test430 fun testCountFavoritesForComponent_singleComponent() {431 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)432 delayableExecutor.runAllReady()433 assertEquals(1, controller.countFavoritesForComponent(TEST_COMPONENT))434 assertEquals(0, controller.countFavoritesForComponent(TEST_COMPONENT_2))435 }436 @Test437 fun testCountFavoritesForComponent_multipleComponents() {438 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)439 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO_2)440 delayableExecutor.runAllReady()441 assertEquals(1, controller.countFavoritesForComponent(TEST_COMPONENT))442 assertEquals(1, controller.countFavoritesForComponent(TEST_COMPONENT_2))443 }444 @Test445 fun testGetFavoritesForComponent() {446 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)447 delayableExecutor.runAllReady()448 assertEquals(listOf(TEST_STRUCTURE_INFO),449 controller.getFavoritesForComponent(TEST_COMPONENT))450 }451 @Test452 fun testGetFavoritesForComponent_otherComponent() {453 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO_2)454 delayableExecutor.runAllReady()455 assertTrue(controller.getFavoritesForComponent(TEST_COMPONENT).isEmpty())456 }457 @Test458 fun testGetFavoritesForComponent_multipleInOrder() {459 val controlInfo = ControlInfo("id", "title", "subtitle", 0)460 controller.replaceFavoritesForStructure(461 StructureInfo(462 TEST_COMPONENT,463 "Home",464 listOf(TEST_CONTROL_INFO, controlInfo)465 ))466 delayableExecutor.runAllReady()467 assertEquals(listOf(TEST_CONTROL_INFO, controlInfo),468 controller.getFavoritesForComponent(TEST_COMPONENT).flatMap { it.controls })469 controller.replaceFavoritesForStructure(470 StructureInfo(471 TEST_COMPONENT,472 "Home",473 listOf(controlInfo, TEST_CONTROL_INFO)474 ))475 delayableExecutor.runAllReady()476 assertEquals(listOf(controlInfo, TEST_CONTROL_INFO),477 controller.getFavoritesForComponent(TEST_COMPONENT).flatMap { it.controls })478 }479 @Test480 fun testReplaceFavoritesForStructure_noExistingFavorites() {481 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)482 delayableExecutor.runAllReady()483 assertEquals(1, controller.countFavoritesForComponent(TEST_COMPONENT))484 assertEquals(listOf(TEST_STRUCTURE_INFO),485 controller.getFavoritesForComponent(TEST_COMPONENT))486 }487 @Test488 fun testReplaceFavoritesForStructure_doNotStoreEmptyStructure() {489 controller.replaceFavoritesForStructure(490 StructureInfo(TEST_COMPONENT, "Home", emptyList<ControlInfo>()))491 delayableExecutor.runAllReady()492 assertEquals(0, controller.countFavoritesForComponent(TEST_COMPONENT))493 assertEquals(emptyList<ControlInfo>(), controller.getFavoritesForComponent(TEST_COMPONENT))494 }495 @Test496 fun testReplaceFavoritesForStructure_differentComponentsAreFilteredOut() {497 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)498 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO_2)499 delayableExecutor.runAllReady()500 assertEquals(1, controller.countFavoritesForComponent(TEST_COMPONENT))501 assertEquals(listOf(TEST_CONTROL_INFO),502 controller.getFavoritesForComponent(TEST_COMPONENT).flatMap { it.controls })503 }504 @Test505 fun testReplaceFavoritesForStructure_oldFavoritesRemoved() {506 val controlInfo = ControlInfo("id", "title", "subtitle", 0)507 assertNotEquals(TEST_CONTROL_INFO, controlInfo)508 val newComponent = ComponentName("test.pkg", "test.class.3")509 controller.replaceFavoritesForStructure(510 StructureInfo(511 newComponent,512 "Home",513 listOf(controlInfo)514 ))515 controller.replaceFavoritesForStructure(516 StructureInfo(517 newComponent,518 "Home",519 listOf(TEST_CONTROL_INFO)520 ))521 delayableExecutor.runAllReady()522 assertEquals(1, controller.countFavoritesForComponent(newComponent))523 assertEquals(listOf(TEST_CONTROL_INFO), controller524 .getFavoritesForComponent(newComponent).flatMap { it.controls })525 }526 @Test527 fun testReplaceFavoritesForStructure_favoritesInOrder() {528 val controlInfo = ControlInfo("id", "title", "subtitle", 0)529 val listOrder1 = listOf(TEST_CONTROL_INFO, controlInfo)530 val structure1 = StructureInfo(TEST_COMPONENT, "Home", listOrder1)531 controller.replaceFavoritesForStructure(structure1)532 delayableExecutor.runAllReady()533 assertEquals(2, controller.countFavoritesForComponent(TEST_COMPONENT))534 assertEquals(listOrder1, controller.getFavoritesForComponent(TEST_COMPONENT)535 .flatMap { it.controls })536 val listOrder2 = listOf(controlInfo, TEST_CONTROL_INFO)537 val structure2 = StructureInfo(TEST_COMPONENT, "Home", listOrder2)538 controller.replaceFavoritesForStructure(structure2)539 delayableExecutor.runAllReady()540 assertEquals(2, controller.countFavoritesForComponent(TEST_COMPONENT))541 assertEquals(listOrder2, controller.getFavoritesForComponent(TEST_COMPONENT)542 .flatMap { it.controls })543 }544 @Test545 fun testPackageRemoved_noFavorites_noRemovals() {546 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)547 delayableExecutor.runAllReady()548 val serviceInfo = mock(ServiceInfo::class.java)549 `when`(serviceInfo.componentName).thenReturn(TEST_COMPONENT)550 val info = ControlsServiceInfo(mContext, serviceInfo)551 // Don't want to check what happens before this call552 reset(persistenceWrapper)553 listingCallbackCaptor.value.onServicesUpdated(listOf(info))554 delayableExecutor.runAllReady()555 verify(bindingController, never()).onComponentRemoved(any())556 assertEquals(1, controller.getFavorites().size)557 assertEquals(TEST_STRUCTURE_INFO, controller.getFavorites()[0])558 verify(persistenceWrapper, never()).storeFavorites(ArgumentMatchers.anyList())559 }560 @Test561 fun testPackageRemoved_hasFavorites() {562 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)563 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO_2)564 delayableExecutor.runAllReady()565 val serviceInfo = mock(ServiceInfo::class.java)566 `when`(serviceInfo.componentName).thenReturn(TEST_COMPONENT)567 val info = ControlsServiceInfo(mContext, serviceInfo)568 // Don't want to check what happens before this call569 reset(persistenceWrapper)570 listingCallbackCaptor.value.onServicesUpdated(listOf(info))571 delayableExecutor.runAllReady()572 verify(bindingController).onComponentRemoved(TEST_COMPONENT_2)573 assertEquals(1, controller.getFavorites().size)574 assertEquals(TEST_STRUCTURE_INFO, controller.getFavorites()[0])575 verify(persistenceWrapper).storeFavorites(ArgumentMatchers.anyList())576 }577 @Test578 fun testExistingPackage_removedFromCache() {579 `when`(auxiliaryPersistenceWrapper.favorites).thenReturn(580 listOf(TEST_STRUCTURE_INFO, TEST_STRUCTURE_INFO_2))581 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)582 delayableExecutor.runAllReady()583 val serviceInfo = mock(ServiceInfo::class.java)584 `when`(serviceInfo.componentName).thenReturn(TEST_COMPONENT)585 val info = ControlsServiceInfo(mContext, serviceInfo)586 listingCallbackCaptor.value.onServicesUpdated(listOf(info))587 delayableExecutor.runAllReady()588 verify(auxiliaryPersistenceWrapper).getCachedFavoritesAndRemoveFor(TEST_COMPONENT)589 }590 @Test591 fun testAddedPackage_requestedFromCache() {592 `when`(auxiliaryPersistenceWrapper.favorites).thenReturn(593 listOf(TEST_STRUCTURE_INFO, TEST_STRUCTURE_INFO_2))594 val serviceInfo = mock(ServiceInfo::class.java)595 `when`(serviceInfo.componentName).thenReturn(TEST_COMPONENT)596 val info = ControlsServiceInfo(mContext, serviceInfo)597 listingCallbackCaptor.value.onServicesUpdated(listOf(info))598 delayableExecutor.runAllReady()599 verify(auxiliaryPersistenceWrapper).getCachedFavoritesAndRemoveFor(TEST_COMPONENT)600 verify(auxiliaryPersistenceWrapper, never())601 .getCachedFavoritesAndRemoveFor(TEST_COMPONENT_2)602 }603 @Test604 fun testSeedFavoritesForComponentsWithLimit() {605 var responses = mutableListOf<SeedResponse>()606 val controls1 = mutableListOf<Control>()607 for (i in 1..10) {608 controls1.add(statelessBuilderFromInfo(ControlInfo("id1:$i", TEST_CONTROL_TITLE,609 TEST_CONTROL_SUBTITLE, TEST_DEVICE_TYPE), "testStructure").build())610 }611 val controls2 = mutableListOf<Control>()612 for (i in 1..3) {613 controls2.add(statelessBuilderFromInfo(ControlInfo("id2:$i", TEST_CONTROL_TITLE,614 TEST_CONTROL_SUBTITLE, TEST_DEVICE_TYPE), "testStructure2").build())615 }616 controller.seedFavoritesForComponents(listOf(TEST_COMPONENT, TEST_COMPONENT_2), Consumer {617 resp -> responses.add(resp)618 })619 verify(bindingController).bindAndLoadSuggested(eq(TEST_COMPONENT),620 capture(controlLoadCallbackCaptor))621 controlLoadCallbackCaptor.value.accept(controls1)622 delayableExecutor.runAllReady()623 verify(bindingController).bindAndLoadSuggested(eq(TEST_COMPONENT_2),624 capture(controlLoadCallbackCaptor2))625 controlLoadCallbackCaptor2.value.accept(controls2)626 delayableExecutor.runAllReady()627 // COMPONENT 1628 val structureInfo = controller.getFavoritesForComponent(TEST_COMPONENT)[0]629 assertEquals(structureInfo.controls.size,630 ControlsControllerImpl.SUGGESTED_CONTROLS_PER_STRUCTURE)631 var i = 1632 structureInfo.controls.forEach {633 assertEquals(it.controlId, "id1:$i")634 i++635 }636 assertEquals(SeedResponse(TEST_COMPONENT.packageName, true), responses[0])637 // COMPONENT 2638 val structureInfo2 = controller.getFavoritesForComponent(TEST_COMPONENT_2)[0]639 assertEquals(structureInfo2.controls.size, 3)640 i = 1641 structureInfo2.controls.forEach {642 assertEquals(it.controlId, "id2:$i")643 i++644 }645 assertEquals(SeedResponse(TEST_COMPONENT.packageName, true), responses[1])646 }647 @Test648 fun testSeedFavoritesForComponents_error() {649 var response: SeedResponse? = null650 controller.seedFavoritesForComponents(listOf(TEST_COMPONENT), Consumer { resp ->651 response = resp652 })653 verify(bindingController).bindAndLoadSuggested(eq(TEST_COMPONENT),654 capture(controlLoadCallbackCaptor))655 controlLoadCallbackCaptor.value.error("Error loading")656 delayableExecutor.runAllReady()657 assertEquals(listOf<StructureInfo>(), controller.getFavoritesForComponent(TEST_COMPONENT))658 assertEquals(SeedResponse(TEST_COMPONENT.packageName, false), response)659 }660 @Test661 fun testSeedFavoritesForComponents_inProgressCallback() {662 var response: SeedResponse? = null663 var seeded = false664 val control = statelessBuilderFromInfo(TEST_CONTROL_INFO, TEST_STRUCTURE_INFO.structure)665 .build()666 controller.seedFavoritesForComponents(listOf(TEST_COMPONENT), Consumer { resp ->667 response = resp668 })669 verify(bindingController).bindAndLoadSuggested(eq(TEST_COMPONENT),670 capture(controlLoadCallbackCaptor))671 controller.addSeedingFavoritesCallback(Consumer { accepted ->672 seeded = accepted673 })674 controlLoadCallbackCaptor.value.accept(listOf(control))675 delayableExecutor.runAllReady()676 assertEquals(listOf(TEST_STRUCTURE_INFO),677 controller.getFavoritesForComponent(TEST_COMPONENT))678 assertEquals(SeedResponse(TEST_COMPONENT.packageName, true), response)679 assertTrue(seeded)680 }681 @Test682 fun testRestoreReceiver_loadsAuxiliaryData() {683 val receiver = controller.restoreFinishedReceiver684 val structure1 = mock(StructureInfo::class.java)685 val structure2 = mock(StructureInfo::class.java)686 val listOfStructureInfo = listOf(structure1, structure2)687 `when`(auxiliaryPersistenceWrapper.favorites).thenReturn(listOfStructureInfo)688 val intent = Intent(BackupHelper.ACTION_RESTORE_FINISHED)689 intent.putExtra(Intent.EXTRA_USER_ID, context.userId)690 receiver.onReceive(context, intent)691 delayableExecutor.runAllReady()692 val inOrder = inOrder(auxiliaryPersistenceWrapper, persistenceWrapper)693 inOrder.verify(auxiliaryPersistenceWrapper).initialize()694 inOrder.verify(auxiliaryPersistenceWrapper).favorites695 inOrder.verify(persistenceWrapper).storeFavorites(listOfStructureInfo)696 inOrder.verify(persistenceWrapper).readFavorites()697 }698 @Test699 fun testRestoreReceiver_noActionOnWrongUser() {700 val receiver = controller.restoreFinishedReceiver701 reset(persistenceWrapper)702 reset(auxiliaryPersistenceWrapper)703 val intent = Intent(BackupHelper.ACTION_RESTORE_FINISHED)704 intent.putExtra(Intent.EXTRA_USER_ID, context.userId + 1)705 receiver.onReceive(context, intent)706 delayableExecutor.runAllReady()707 verifyNoMoreInteractions(persistenceWrapper)708 verifyNoMoreInteractions(auxiliaryPersistenceWrapper)709 }710 @Test711 fun testGetFavoritesForStructure() {712 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)713 controller.replaceFavoritesForStructure(714 TEST_STRUCTURE_INFO_2.copy(componentName = TEST_COMPONENT))715 delayableExecutor.runAllReady()716 assertEquals(TEST_STRUCTURE_INFO.controls,717 controller.getFavoritesForStructure(TEST_COMPONENT, TEST_STRUCTURE))718 assertEquals(TEST_STRUCTURE_INFO_2.controls,719 controller.getFavoritesForStructure(TEST_COMPONENT, TEST_STRUCTURE_2))720 }721 @Test722 fun testGetFavoritesForStructure_wrongStructure() {723 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)724 delayableExecutor.runAllReady()725 assertTrue(controller.getFavoritesForStructure(TEST_COMPONENT, TEST_STRUCTURE_2).isEmpty())726 }727 @Test728 fun testGetFavoritesForStructure_wrongComponent() {729 controller.replaceFavoritesForStructure(TEST_STRUCTURE_INFO)730 delayableExecutor.runAllReady()731 assertTrue(controller.getFavoritesForStructure(TEST_COMPONENT_2, TEST_STRUCTURE).isEmpty())732 }733}734private class DidRunRunnable() : Runnable {735 var ran = false736 override fun run() {737 ran = true738 }739}...

Full Screen

Full Screen

CommandOptionsTest.kt

Source:CommandOptionsTest.kt Github

copy

Full Screen

...35 private const val TEST_SRC_JAR = "out/soong/.temp/sbox175955373/" +36 "services.core.wm.protolog.srcjar"37 private const val TEST_VIEWER_JSON = "out/soong/.temp/sbox175955373/" +38 "services.core.wm.protolog.json"39 private const val TEST_LOG = "./test_log.pb"40 }41 @Test(expected = InvalidCommandException::class)42 fun noCommand() {43 CommandOptions(arrayOf())44 }45 @Test(expected = InvalidCommandException::class)46 fun invalidCommand() {47 val testLine = "invalid"48 CommandOptions(testLine.split(' ').toTypedArray())49 }50 @Test51 fun transformClasses() {52 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +53 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +54 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +55 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +56 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +57 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"58 val cmd = CommandOptions(testLine.split(' ').toTypedArray())59 assertEquals(CommandOptions.TRANSFORM_CALLS_CMD, cmd.command)60 assertEquals(TEST_PROTOLOG_CLASS, cmd.protoLogClassNameArg)61 assertEquals(TEST_PROTOLOGIMPL_CLASS, cmd.protoLogImplClassNameArg)62 assertEquals(TEST_PROTOLOGGROUP_CLASS, cmd.protoLogGroupsClassNameArg)63 assertEquals(TEST_PROTOLOGGROUP_JAR, cmd.protoLogGroupsJarArg)64 assertEquals(TEST_SRC_JAR, cmd.outputSourceJarArg)65 assertEquals(TEST_JAVA_SRC, cmd.javaSourceArgs)66 }67 @Test(expected = InvalidCommandException::class)68 fun transformClasses_noProtoLogClass() {69 val testLine = "transform-protolog-calls " +70 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +71 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +72 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +73 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +74 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"75 CommandOptions(testLine.split(' ').toTypedArray())76 }77 @Test(expected = InvalidCommandException::class)78 fun transformClasses_noProtoLogImplClass() {79 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +80 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +81 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +82 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +83 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"84 CommandOptions(testLine.split(' ').toTypedArray())85 }86 @Test(expected = InvalidCommandException::class)87 fun transformClasses_noProtoLogCacheClass() {88 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +89 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +90 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +91 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +92 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"93 CommandOptions(testLine.split(' ').toTypedArray())94 }95 @Test(expected = InvalidCommandException::class)96 fun transformClasses_noProtoLogGroupClass() {97 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +98 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +99 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +100 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +101 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"102 CommandOptions(testLine.split(' ').toTypedArray())103 }104 @Test(expected = InvalidCommandException::class)105 fun transformClasses_noProtoLogGroupJar() {106 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +107 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +108 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +109 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +110 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"111 CommandOptions(testLine.split(' ').toTypedArray())112 }113 @Test(expected = InvalidCommandException::class)114 fun transformClasses_noOutJar() {115 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +116 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +117 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +118 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +119 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +120 TEST_JAVA_SRC.joinToString(" ")121 CommandOptions(testLine.split(' ').toTypedArray())122 }123 @Test(expected = InvalidCommandException::class)124 fun transformClasses_noJavaInput() {125 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +126 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +127 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +128 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +129 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +130 "--output-srcjar $TEST_SRC_JAR"131 CommandOptions(testLine.split(' ').toTypedArray())132 }133 @Test(expected = InvalidCommandException::class)134 fun transformClasses_invalidProtoLogClass() {135 val testLine = "transform-protolog-calls --protolog-class invalid " +136 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +137 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +138 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +139 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +140 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"141 CommandOptions(testLine.split(' ').toTypedArray())142 }143 @Test(expected = InvalidCommandException::class)144 fun transformClasses_invalidProtoLogImplClass() {145 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +146 "--protolog-impl-class invalid " +147 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +148 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +149 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +150 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"151 CommandOptions(testLine.split(' ').toTypedArray())152 }153 @Test(expected = InvalidCommandException::class)154 fun transformClasses_invalidProtoLogCacheClass() {155 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +156 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +157 "--protolog-cache-class invalid " +158 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +159 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +160 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"161 CommandOptions(testLine.split(' ').toTypedArray())162 }163 @Test(expected = InvalidCommandException::class)164 fun transformClasses_invalidProtoLogGroupClass() {165 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +166 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +167 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +168 "--loggroups-class invalid " +169 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +170 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"171 CommandOptions(testLine.split(' ').toTypedArray())172 }173 @Test(expected = InvalidCommandException::class)174 fun transformClasses_invalidProtoLogGroupJar() {175 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +176 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +177 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +178 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +179 "--loggroups-jar invalid.txt " +180 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"181 CommandOptions(testLine.split(' ').toTypedArray())182 }183 @Test(expected = InvalidCommandException::class)184 fun transformClasses_invalidOutJar() {185 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +186 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +187 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +188 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +189 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +190 "--output-srcjar invalid.db ${TEST_JAVA_SRC.joinToString(" ")}"191 CommandOptions(testLine.split(' ').toTypedArray())192 }193 @Test(expected = InvalidCommandException::class)194 fun transformClasses_invalidJavaInput() {195 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +196 "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +197 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +198 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +199 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +200 "--output-srcjar $TEST_SRC_JAR invalid.py"201 CommandOptions(testLine.split(' ').toTypedArray())202 }203 @Test(expected = InvalidCommandException::class)204 fun transformClasses_unknownParam() {205 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +206 "--unknown test --protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +207 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +208 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +209 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +210 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"211 CommandOptions(testLine.split(' ').toTypedArray())212 }213 @Test(expected = InvalidCommandException::class)214 fun transformClasses_noValue() {215 val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +216 "--protolog-impl-class " +217 "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +218 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +219 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +220 "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"221 CommandOptions(testLine.split(' ').toTypedArray())222 }223 @Test224 fun generateConfig() {225 val testLine = "generate-viewer-config --protolog-class $TEST_PROTOLOG_CLASS " +226 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +227 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +228 "--viewer-conf $TEST_VIEWER_JSON ${TEST_JAVA_SRC.joinToString(" ")}"229 val cmd = CommandOptions(testLine.split(' ').toTypedArray())230 assertEquals(CommandOptions.GENERATE_CONFIG_CMD, cmd.command)231 assertEquals(TEST_PROTOLOG_CLASS, cmd.protoLogClassNameArg)232 assertEquals(TEST_PROTOLOGGROUP_CLASS, cmd.protoLogGroupsClassNameArg)233 assertEquals(TEST_PROTOLOGGROUP_JAR, cmd.protoLogGroupsJarArg)234 assertEquals(TEST_VIEWER_JSON, cmd.viewerConfigJsonArg)235 assertEquals(TEST_JAVA_SRC, cmd.javaSourceArgs)236 }237 @Test(expected = InvalidCommandException::class)238 fun generateConfig_noViewerConfig() {239 val testLine = "generate-viewer-config --protolog-class $TEST_PROTOLOG_CLASS " +240 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +241 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +242 TEST_JAVA_SRC.joinToString(" ")243 CommandOptions(testLine.split(' ').toTypedArray())244 }245 @Test(expected = InvalidCommandException::class)246 fun generateConfig_invalidViewerConfig() {247 val testLine = "generate-viewer-config --protolog-class $TEST_PROTOLOG_CLASS " +248 "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +249 "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +250 "--viewer-conf invalid.yaml ${TEST_JAVA_SRC.joinToString(" ")}"251 CommandOptions(testLine.split(' ').toTypedArray())252 }253 @Test254 fun readLog() {255 val testLine = "read-log --viewer-conf $TEST_VIEWER_JSON $TEST_LOG"256 val cmd = CommandOptions(testLine.split(' ').toTypedArray())257 assertEquals(CommandOptions.READ_LOG_CMD, cmd.command)258 assertEquals(TEST_VIEWER_JSON, cmd.viewerConfigJsonArg)259 assertEquals(TEST_LOG, cmd.logProtofileArg)260 }261}...

Full Screen

Full Screen

UnhideApisTest.kt

Source:UnhideApisTest.kt Github

copy

Full Screen

...30 ARG_ERROR,31 "ReferencesHidden"32 ),33 expectedIssues = """34 src/test/pkg/Foo.java:3: error: Class test.pkg.Hidden1 is not public but was referenced (as field type) from public field test.pkg.Foo.hidden1 [ReferencesHidden]35 src/test/pkg/Foo.java:4: error: Class test.pkg.Hidden2 is hidden but was referenced (as field type) from public field test.pkg.Foo.hidden2 [ReferencesHidden]36 src/test/pkg/Foo.java:5: error: Class test.pkg.Hidden1 is not public but was referenced (as parameter type) from public parameter hidden1 in test.pkg.Foo.method(test.pkg.Hidden1 hidden1, test.pkg.Hidden2 hidden2) [ReferencesHidden]37 src/test/pkg/Foo.java:5: error: Class test.pkg.Hidden2 is hidden but was referenced (as parameter type) from public parameter hidden2 in test.pkg.Foo.method(test.pkg.Hidden1 hidden1, test.pkg.Hidden2 hidden2) [ReferencesHidden]38 src/test/pkg/Foo.java:5: error: Class test.pkg.Hidden3 is hidden but was referenced (as exception) from public method test.pkg.Foo.method(test.pkg.Hidden1,test.pkg.Hidden2) [ReferencesHidden]39 src/test/pkg/Foo.java:7: error: Class test.pkg.Hidden1 is not public but was referenced (as type parameter) from public method test.pkg.Foo.get(T) [ReferencesHidden]40 src/test/pkg/Foo.java:7: error: Class test.pkg.Hidden2 is hidden but was referenced (as type parameter) from public method test.pkg.Foo.get(T) [ReferencesHidden]41 src/test/pkg/Foo.java:8: error: Class test.pkg.Hidden1 is not public but was referenced (as return type) from public method test.pkg.Foo.getHidden1() [ReferencesHidden]42 src/test/pkg/Foo.java:9: error: Class test.pkg.Hidden2 is hidden but was referenced (as return type) from public method test.pkg.Foo.getHidden2() [ReferencesHidden]43 """,44 sourceFiles = arrayOf(45 java(46 """47 package test.pkg;48 public class Foo extends Hidden2 {49 public Hidden1 hidden1;50 public Hidden2 hidden2;51 public void method(Hidden1 hidden1, Hidden2 hidden2) throws Hidden3 {52 }53 public <S extends Hidden1, T extends Hidden2> S get(T t) { return null; }54 public Hidden1 getHidden1() { return null; }55 public Hidden2 getHidden2() { return null; }56 }57 """58 ),59 java(60 """61 package test.pkg;62 // Implicitly not part of the API by being package private63 class Hidden1 {64 }65 """66 ),67 java(68 """69 package test.pkg;70 /** @hide */71 public class Hidden2 {72 }73 """74 ),75 java(76 """77 package test.pkg;78 /** @hide */79 public class Hidden3 extends IOException {80 }81 """82 )83 ),84 api = """85 package test.pkg {86 public class Foo {87 ctor public Foo();88 method public <S extends test.pkg.Hidden1, T extends test.pkg.Hidden2> S get(T);89 method public test.pkg.Hidden1 getHidden1();90 method public test.pkg.Hidden2 getHidden2();91 method public void method(test.pkg.Hidden1, test.pkg.Hidden2) throws test.pkg.Hidden3;92 field public test.pkg.Hidden1 hidden1;93 field public test.pkg.Hidden2 hidden2;94 }95 }96 """97 )98 }99 @Test100 fun `Do not warn about package private access when generating package private stubs`() {101 // Like above test, but with --package and therefore fewer warnings102 check(103 extraArguments = arrayOf(104 ARG_PACKAGE,105 ARG_HIDE,106 "HiddenSuperclass",107 ARG_HIDE,108 "UnavailableSymbol",109 ARG_HIDE,110 "HiddenTypeParameter",111 ARG_ERROR,112 "ReferencesHidden"113 ),114 expectedIssues = """115 src/test/pkg/Foo.java:4: error: Class test.pkg.Hidden2 is hidden but was referenced (as field type) from public field test.pkg.Foo.hidden2 [ReferencesHidden]116 src/test/pkg/Foo.java:5: error: Class test.pkg.Hidden2 is hidden but was referenced (as parameter type) from public parameter hidden2 in test.pkg.Foo.method(test.pkg.Hidden1 hidden1, test.pkg.Hidden2 hidden2) [ReferencesHidden]117 src/test/pkg/Foo.java:5: error: Class test.pkg.Hidden3 is hidden but was referenced (as exception) from public method test.pkg.Foo.method(test.pkg.Hidden1,test.pkg.Hidden2) [ReferencesHidden]118 src/test/pkg/Foo.java:7: error: Class test.pkg.Hidden2 is hidden but was referenced (as type parameter) from public method test.pkg.Foo.get(T) [ReferencesHidden]119 src/test/pkg/Foo.java:9: error: Class test.pkg.Hidden2 is hidden but was referenced (as return type) from public method test.pkg.Foo.getHidden2() [ReferencesHidden]120 """,121 sourceFiles = arrayOf(122 java(123 """124 package test.pkg;125 public class Foo extends Hidden2 {126 public Hidden1 hidden1;127 public Hidden2 hidden2;128 public void method(Hidden1 hidden1, Hidden2 hidden2) throws Hidden3 {129 }130 public <S extends Hidden1, T extends Hidden2> S get(T t) { return null; }131 public Hidden1 getHidden1() { return null; }132 public Hidden2 getHidden2() { return null; }133 }134 """135 ),136 java(137 """138 package test.pkg;139 // Implicitly not part of the API by being package private140 class Hidden1 {141 }142 """143 ),144 java(145 """146 package test.pkg;147 /** @hide */148 public class Hidden2 {149 }150 """151 ),152 java(153 """154 package test.pkg;155 /** @hide */156 public class Hidden3 extends IOException {157 }158 """159 )160 ),161 api = """162 package test.pkg {163 public class Foo {164 ctor public Foo();165 method public <S extends test.pkg.Hidden1, T extends test.pkg.Hidden2> S get(T);166 method public test.pkg.Hidden1 getHidden1();167 method public test.pkg.Hidden2 getHidden2();168 method public void method(test.pkg.Hidden1, test.pkg.Hidden2) throws test.pkg.Hidden3;169 field public test.pkg.Hidden1 hidden1;170 field public test.pkg.Hidden2 hidden2;171 }172 }173 """174 )175 }176 @Test177 fun `Including private interfaces from types`() {178 check(179 extraArguments = arrayOf(ARG_ERROR, "ReferencesHidden"),180 sourceFiles = arrayOf(181 java("""package test.pkg1; interface Interface1 { }"""),182 java("""package test.pkg1; abstract class Class1 { }"""),183 java("""package test.pkg1; abstract class Class2 { }"""),184 java("""package test.pkg1; abstract class Class3 { }"""),185 java("""package test.pkg1; abstract class Class4 { }"""),186 java("""package test.pkg1; abstract class Class5 { }"""),187 java("""package test.pkg1; abstract class Class6 { }"""),188 java("""package test.pkg1; abstract class Class7 { }"""),189 java("""package test.pkg1; abstract class Class8 { }"""),190 java("""package test.pkg1; abstract class Class9 { }"""),191 java(192 """193 package test.pkg1;194 import java.util.List;195 import java.util.Map;196 public abstract class Usage implements List<Class1> {197 <T extends java.lang.Comparable<? super T>> void sort(java.util.List<T> list) {}198 public Class3 myClass1 = null;199 public List<? extends Class4> myClass2 = null;200 public Map<String, ? extends Class5> myClass3 = null;201 public <T extends Class6> void mySort(List<Class7> list, T element) {}202 public void ellipsisType(Class8... myargs);203 public void arrayType(Class9[] myargs);204 }205 """206 )207 ),208 // TODO: Test annotations! (values, annotation classes, etc.)209 expectedIssues = """210 src/test/pkg1/Usage.java:7: error: Class test.pkg1.Class3 is not public but was referenced (as field type) from public field test.pkg1.Usage.myClass1 [ReferencesHidden]211 src/test/pkg1/Usage.java:8: error: Class test.pkg1.Class4 is not public but was referenced (as field type argument class) from public field test.pkg1.Usage.myClass2 [ReferencesHidden]212 src/test/pkg1/Usage.java:9: error: Class test.pkg1.Class5 is not public but was referenced (as field type argument class) from public field test.pkg1.Usage.myClass3 [ReferencesHidden]213 src/test/pkg1/Usage.java:10: error: Class test.pkg1.Class6 is not public but was referenced (as type parameter) from public method test.pkg1.Usage.mySort(java.util.List<test.pkg1.Class7>,T) [ReferencesHidden]214 src/test/pkg1/Usage.java:10: error: Class test.pkg1.Class7 is not public but was referenced (as type parameter) from public parameter list in test.pkg1.Usage.mySort(java.util.List<test.pkg1.Class7> list, T element) [ReferencesHidden]215 src/test/pkg1/Usage.java:10: error: Class test.pkg1.Class7 is not public but was referenced (as parameter type) from public parameter list in test.pkg1.Usage.mySort(java.util.List<test.pkg1.Class7> list, T element) [ReferencesHidden]216 src/test/pkg1/Usage.java:11: error: Class test.pkg1.Class8 is not public but was referenced (as parameter type) from public parameter myargs in test.pkg1.Usage.ellipsisType(test.pkg1.Class8... myargs) [ReferencesHidden]217 src/test/pkg1/Usage.java:12: error: Class test.pkg1.Class9 is not public but was referenced (as parameter type) from public parameter myargs in test.pkg1.Usage.arrayType(test.pkg1.Class9[] myargs) [ReferencesHidden]218 src/test/pkg1/Usage.java:12: warning: Parameter myargs references hidden type test.pkg1.Class9[]. [HiddenTypeParameter]219 src/test/pkg1/Usage.java:11: warning: Parameter myargs references hidden type test.pkg1.Class8.... [HiddenTypeParameter]220 src/test/pkg1/Usage.java:10: warning: Parameter list references hidden type class test.pkg1.Class7. [HiddenTypeParameter]221 src/test/pkg1/Usage.java:7: warning: Field Usage.myClass1 references hidden type test.pkg1.Class3. [HiddenTypeParameter]222 src/test/pkg1/Usage.java:8: warning: Field Usage.myClass2 references hidden type class test.pkg1.Class4. [HiddenTypeParameter]223 src/test/pkg1/Usage.java:9: warning: Field Usage.myClass3 references hidden type class test.pkg1.Class5. [HiddenTypeParameter]224 """,225 api = """226 package test.pkg1 {227 public abstract class Usage implements java.util.List {228 ctor public Usage();229 method public void arrayType(test.pkg1.Class9[]);230 method public void ellipsisType(test.pkg1.Class8...);231 method public <T extends test.pkg1.Class6> void mySort(java.util.List<test.pkg1.Class7>, T);232 field public test.pkg1.Class3 myClass1;233 field public java.util.List<? extends test.pkg1.Class4> myClass2;234 field public java.util.Map<java.lang.String, ? extends test.pkg1.Class5> myClass3;235 }236 }237 """238 )239 }240}

Full Screen

Full Screen

KeepFileTest.kt

Source:KeepFileTest.kt Github

copy

Full Screen

...21 check(22 sourceFiles = arrayOf(23 java(24 """25 package test.pkg;26 @SuppressWarnings("ALL")27 public interface MyInterface<T extends Object>28 extends MyBaseInterface {29 }30 """31 ), java(32 """33 package a.b.c;34 @SuppressWarnings("ALL")35 public interface MyStream<T, S extends MyStream<T, S>> extends java.lang.AutoCloseable {36 }37 """38 ), java(39 """40 package test.pkg;41 @SuppressWarnings("ALL")42 public interface MyInterface2<T extends Number>43 extends MyBaseInterface {44 class TtsSpan<C extends MyInterface<?>> { }45 abstract class Range<T extends Comparable<? super T>> {46 protected String myString;47 }48 }49 """50 ),51 java(52 """53 package test.pkg;54 public interface MyBaseInterface {55 void fun(int a, String b);56 }57 """58 )59 ),60 proguard = """61 -keep class a.b.c.MyStream {62 }63 -keep class test.pkg.MyBaseInterface {64 public abstract void fun(int, java.lang.String);65 }66 -keep class test.pkg.MyInterface {67 }68 -keep class test.pkg.MyInterface2 {69 }70 -keep class test.pkg.MyInterface2${"$"}Range {71 <init>();72 protected java.lang.String myString;73 }74 -keep class test.pkg.MyInterface2${"$"}TtsSpan {75 <init>();76 }77 """,78 extraArguments = arrayOf(ARG_HIDE, "KotlinKeyword")79 )80 }81 @Test82 fun `Primitive types`() {83 check(84 sourceFiles = arrayOf(85 java(86 """87 package test.pkg;88 public class MyClass {89 public int testMethodA(int a) {}90 public boolean testMethodB(boolean a) {}91 public float testMethodC(float a) {}92 public double testMethodD(double a) {}93 public byte testMethodE(byte a) {}94 }95 """96 )97 ),98 proguard = """99 -keep class test.pkg.MyClass {100 <init>();101 public int testMethodA(int);102 public boolean testMethodB(boolean);103 public float testMethodC(float);104 public double testMethodD(double);105 public byte testMethodE(byte);106 }107 """,108 extraArguments = arrayOf(ARG_HIDE, "KotlinKeyword")109 )110 }111 @Test112 fun `Primitive array types`() {113 check(114 sourceFiles = arrayOf(115 java(116 """117 package test.pkg;118 public class MyClass {119 public int[] testMethodA(int[] a) {}120 public float[][] testMethodB(float[][] a) {}121 public double[][][] testMethodC(double[][][] a) {}122 public byte testMethodD(byte... a) {}123 }124 """125 )126 ),127 proguard = """128 -keep class test.pkg.MyClass {129 <init>();130 public int[] testMethodA(int[]);131 public float[][] testMethodB(float[][]);132 public double[][][] testMethodC(double[][][]);133 public byte testMethodD(byte[]);134 }135 """,136 extraArguments = arrayOf(ARG_HIDE, "KotlinKeyword")137 )138 }139 @Test140 fun `Object Array parameters`() {141 check(142 sourceFiles = arrayOf(143 java(144 """145 package test.pkg;146 public class MyClass {147 public void testMethodA(String a) {}148 public void testMethodB(Boolean[] a) {}149 public void testMethodC(Integer... a) {}150 }151 """152 )153 ),154 proguard = """155 -keep class test.pkg.MyClass {156 <init>();157 public void testMethodA(java.lang.String);158 public void testMethodB(java.lang.Boolean[]);159 public void testMethodC(java.lang.Integer[]);160 }161 """,162 extraArguments = arrayOf(ARG_HIDE, "KotlinKeyword")163 )164 }165 @Test166 fun `Arrays with Inner class`() {167 check(168 sourceFiles = arrayOf(169 java(170 """171 package test.pkg;172 public class MyClass {173 public void testMethodA(InnerClass a) {}174 public void testMethodB(InnerClass[] a) {}175 public void testMethodC(InnerClass... a) {}176 public class InnerClass {}177 }178 """179 )180 ),181 proguard = """182 -keep class test.pkg.MyClass {183 <init>();184 public void testMethodA(test.pkg.MyClass${"$"}InnerClass);185 public void testMethodB(test.pkg.MyClass${"$"}InnerClass[]);186 public void testMethodC(test.pkg.MyClass${"$"}InnerClass[]);187 }188 -keep class test.pkg.MyClass${"$"}InnerClass {189 <init>();190 }191 """,192 extraArguments = arrayOf(ARG_HIDE, "KotlinKeyword")193 )194 }195 @Test196 fun `Conflicting Class Names in parameters`() {197 check(198 sourceFiles = arrayOf(199 java(200 """201 package test.pkg;202 public class String {}203 """204 ),205 java(206 """207 package test.pkg;208 public class MyClass {209 public void testMethodA(String a, String b) {}210 public void testMethodB(String a, test.pkg.String b) {}211 public void testMethodC(String a, java.lang.String b) {}212 public void testMethodD(java.lang.String a, test.pkg.String b) {}213 }214 """215 ),216 java(217 """218 package test.pkg;219 public class MyClassArrays {220 public void testMethodA(String[] a, String[] b) {}221 public void testMethodB(String[] a, test.pkg.String[] b) {}222 public void testMethodC(String[] a, java.lang.String[] b) {}223 public void testMethodD(java.lang.String... a, test.pkg.String... b) {}224 }225 """226 )227 ),228 proguard = """229 -keep class test.pkg.MyClass {230 <init>();231 public void testMethodA(test.pkg.String, test.pkg.String);232 public void testMethodB(test.pkg.String, test.pkg.String);233 public void testMethodC(test.pkg.String, java.lang.String);234 public void testMethodD(java.lang.String, test.pkg.String);235 }236 -keep class test.pkg.MyClassArrays {237 <init>();238 public void testMethodA(test.pkg.String[], test.pkg.String[]);239 public void testMethodB(test.pkg.String[], test.pkg.String[]);240 public void testMethodC(test.pkg.String[], java.lang.String[]);241 public void testMethodD(java.lang.String[], test.pkg.String[]);242 }243 -keep class test.pkg.String {244 <init>();245 }246 """,247 extraArguments = arrayOf(ARG_HIDE, "KotlinKeyword")248 )249 }250 @Test251 fun `Multi dimensional arrays`() {252 check(253 sourceFiles = arrayOf(254 java(255 """256 package test.pkg;257 public class String {}258 """259 ),260 java(261 """262 package test.pkg;263 public class MyClassArrays {264 public void testMethodA(String[][] a, String[][] b) {}265 public void testMethodB(String[][][] a, test.pkg.String[][][] b) {}266 public void testMethodC(String[][] a, java.lang.String[][] b) {}267 public class InnerClass {}268 public void testMethodD(InnerClass[][] a) {}269 }270 """271 )272 ),273 proguard = """274 -keep class test.pkg.MyClassArrays {275 <init>();276 public void testMethodA(test.pkg.String[][], test.pkg.String[][]);277 public void testMethodB(test.pkg.String[][][], test.pkg.String[][][]);278 public void testMethodC(test.pkg.String[][], java.lang.String[][]);279 public void testMethodD(test.pkg.MyClassArrays${"$"}InnerClass[][]);280 }281 -keep class test.pkg.MyClassArrays${"$"}InnerClass {282 <init>();283 }284 -keep class test.pkg.String {285 <init>();286 }287 """,288 extraArguments = arrayOf(ARG_HIDE, "KotlinKeyword")289 )290 }291 @Test292 fun `Methods with arrays as the return type`() {293 check(294 sourceFiles = arrayOf(295 java(296 """297 package test.pkg;298 public class MyClass {299 public String[] testMethodA() {}300 public String[][] testMethodB() {}301 public String[][][] testMethodC() {}302 }303 """304 ),305 java(306 """307 package test.pkg;308 public class MyOtherClass {309 public java.lang.String[] testMethodA() {}310 public String[][] testMethodB() {}311 public test.pkg.String[][][] testMethodC() {}312 }313 """314 ),315 java(316 """317 package test.pkg;318 public class String {}319 """320 )321 ),322 proguard = """323 -keep class test.pkg.MyClass {324 <init>();325 public test.pkg.String[] testMethodA();326 public test.pkg.String[][] testMethodB();327 public test.pkg.String[][][] testMethodC();328 }329 -keep class test.pkg.MyOtherClass {330 <init>();331 public java.lang.String[] testMethodA();332 public test.pkg.String[][] testMethodB();333 public test.pkg.String[][][] testMethodC();334 }335 -keep class test.pkg.String {336 <init>();337 }338 """,339 extraArguments = arrayOf(ARG_HIDE, "KotlinKeyword")340 )341 }342}...

Full Screen

Full Screen

ClassSpecTest_MethodSelectorWithReturnType.kt

Source:ClassSpecTest_MethodSelectorWithReturnType.kt Github

copy

Full Screen

...21 .forGivenPrefixes(22 "support/"23 )24 .forGivenTypesMap(25 "support/Activity" to "test/Activity",26 "support/Fragment" to "test/Fragment"27 )28 .testThatGivenProGuard(29 "-keep public class * { \n" +30 " void get*(); \n" +31 " void get*(...); \n" +32 " void get*(*); \n" +33 " void get*(support.Activity); \n" +34 " void get?(support.Activity); \n" +35 " void get(support.Activity); \n" +36 " void *(support.Activity, support.Fragment, keep.Please); \n" +37 "}"38 )39 .rewritesTo(40 "-keep public class * { \n" +41 " void get*(); \n" +42 " void get*(...); \n" +43 " void get*(*); \n" +44 " void get*(test.Activity); \n" +45 " void get?(test.Activity); \n" +46 " void get(test.Activity); \n" +47 " void *(test.Activity, test.Fragment, keep.Please); \n" +48 "}"49 )50 }51 @Test fun proGuard_methodReturnTypeSelector_voidResult() {52 ProGuardTester()53 .forGivenPrefixes(54 "support/"55 )56 .forGivenTypesMap(57 "support/Activity" to "test/Activity",58 "support/Fragment" to "test/Fragment"59 )60 .testThatGivenProGuard(61 "-keep public class * { \n" +62 " void get(); \n" +63 " void get(...); \n" +64 " void get(*); \n" +65 " void get(support.Activity); \n" +66 " void get(support.Activity, support.Fragment, keep.Please); \n" +67 "}"68 )69 .rewritesTo(70 "-keep public class * { \n" +71 " void get(); \n" +72 " void get(...); \n" +73 " void get(*); \n" +74 " void get(test.Activity); \n" +75 " void get(test.Activity, test.Fragment, keep.Please); \n" +76 "}"77 )78 }79 @Test fun proGuard_methodReturnTypeSelector_starResult() {80 ProGuardTester()81 .forGivenPrefixes(82 "support/"83 )84 .forGivenTypesMap(85 "support/Activity" to "test/Activity",86 "support/Fragment" to "test/Fragment"87 )88 .testThatGivenProGuard(89 "-keep public class * { \n" +90 " * get(); \n" +91 " * get(...); \n" +92 " * get(*); \n" +93 " * get(support.Activity); \n" +94 " * get(support.Activity, support.Fragment, keep.Please); \n" +95 "}"96 )97 .rewritesTo(98 "-keep public class * { \n" +99 " * get(); \n" +100 " * get(...); \n" +101 " * get(*); \n" +102 " * get(test.Activity); \n" +103 " * get(test.Activity, test.Fragment, keep.Please); \n" +104 "}"105 )106 }107 @Test fun proGuard_methodReturnTypeSelector_typeResult() {108 ProGuardTester()109 .forGivenPrefixes(110 "support/"111 )112 .forGivenTypesMap(113 "support/Activity" to "test/Activity",114 "support/Fragment" to "test/Fragment"115 )116 .testThatGivenProGuard(117 "-keep public class * { \n" +118 " support.Fragment get(); \n" +119 " support.Fragment get(...); \n" +120 " support.Fragment get(*); \n" +121 " support.Fragment get(support.Activity); \n" +122 " support.Fragment get(support.Activity, support.Fragment, keep.Please); \n" +123 "}"124 )125 .rewritesTo(126 "-keep public class * { \n" +127 " test.Fragment get(); \n" +128 " test.Fragment get(...); \n" +129 " test.Fragment get(*); \n" +130 " test.Fragment get(test.Activity); \n" +131 " test.Fragment get(test.Activity, test.Fragment, keep.Please); \n" +132 "}"133 )134 }135 @Test fun proGuard_methodReturnTypeSelector_typeResult_wildcards() {136 ProGuardTester()137 .forGivenPrefixes(138 "support/"139 )140 .forGivenTypesMap(141 "support/Activity" to "test/Activity",142 "support/Fragment" to "test/Fragment"143 )144 .testThatGivenProGuard(145 "-keep public class * { \n" +146 " support.Fragment get*(); \n" +147 " support.Fragment get?(...); \n" +148 " support.Fragment *(*); \n" +149 " support.Fragment *(support.Activity); \n" +150 " support.Fragment *(support.Activity, support.Fragment, keep.Please); \n" +151 "}"152 )153 .rewritesTo(154 "-keep public class * { \n" +155 " test.Fragment get*(); \n" +156 " test.Fragment get?(...); \n" +157 " test.Fragment *(*); \n" +158 " test.Fragment *(test.Activity); \n" +159 " test.Fragment *(test.Activity, test.Fragment, keep.Please); \n" +160 "}"161 )162 }163 @Test fun proGuard_methodReturnTypeSelector_typeResult_modifiers() {164 ProGuardTester()165 .forGivenPrefixes(166 "support/"167 )168 .forGivenTypesMap(169 "support/Activity" to "test/Activity",170 "support/Fragment" to "test/Fragment"171 )172 .testThatGivenProGuard(173 "-keep public class * { \n" +174 " public support.Fragment get(); \n" +175 " public static support.Fragment get(...); \n" +176 " !public !static support.Fragment get(*); \n" +177 " private support.Fragment get(support.Activity); \n" +178 " public abstract support.Fragment get(support.Activity, support.Fragment, " +179 "keep.Please); \n" +180 "}"181 )182 .rewritesTo(183 "-keep public class * { \n" +184 " public test.Fragment get(); \n" +185 " public static test.Fragment get(...); \n" +186 " !public !static test.Fragment get(*); \n" +187 " private test.Fragment get(test.Activity); \n" +188 " public abstract test.Fragment get(test.Activity, test.Fragment, keep.Please); " +189 "\n" +190 "}"191 )192 }193 @Test fun proGuard_methodReturnTypeSelector_typeResult_annotation() {194 ProGuardTester()195 .forGivenPrefixes(196 "support/"197 )198 .forGivenTypesMap(199 "support/Activity" to "test/Activity",200 "support/Fragment" to "test/Fragment",201 "support/Annotation" to "test/Annotation"202 )203 .testThatGivenProGuard(204 "-keep public class * { \n" +205 " @support.Annotation support.Fragment get(); \n" +206 " @support.Annotation support.Fragment get(...); \n" +207 " @support.Annotation support.Fragment get(*); \n" +208 " @keep.Me support.Fragment get(support.Activity); \n" +209 " @support.Annotation support.Fragment get(support.Activity, support.Fragment, " +210 "keep.Please); \n" +211 "}"212 )213 .rewritesTo(214 "-keep public class * { \n" +215 " @test.Annotation test.Fragment get(); \n" +216 " @test.Annotation test.Fragment get(...); \n" +217 " @test.Annotation test.Fragment get(*); \n" +218 " @keep.Me test.Fragment get(test.Activity); \n" +219 " @test.Annotation test.Fragment get(test.Activity, test.Fragment, keep.Please" +220 "); \n" +221 "}"222 )223 }224 @Test fun proGuard_methodReturnTypeSelector_typeResult_modifiers_annotation() {225 ProGuardTester()226 .forGivenPrefixes(227 "support/"228 )229 .forGivenTypesMap(230 "support/Activity" to "test/Activity",231 "support/Fragment" to "test/Fragment",232 "support/Annotation" to "test/Annotation"233 )234 .testThatGivenProGuard(235 "-keep public class * { \n" +236 " @support.Annotation public support.Fragment get(); \n" +237 " @support.Annotation public static support.Fragment get(...); \n" +238 " @support.Annotation !public !static support.Fragment get(*); \n" +239 " @support.Annotation private support.Fragment get(support.Activity); \n" +240 " @support.Annotation public abstract support.Fragment get(support.Activity, " +241 "support.Fragment, keep.Please); \n" +242 "}"243 )244 .rewritesTo(245 "-keep public class * { \n" +246 " @test.Annotation public test.Fragment get(); \n" +247 " @test.Annotation public static test.Fragment get(...); \n" +248 " @test.Annotation !public !static test.Fragment get(*); \n" +249 " @test.Annotation private test.Fragment get(test.Activity); \n" +250 " @test.Annotation public abstract test.Fragment get(test.Activity, " +251 "test.Fragment, keep.Please); \n" +252 "}"253 )254 }255 @Test fun proGuard_methodReturnTypeSelector_typeResult_modifiers_annotation_spaces() {256 ProGuardTester()257 .forGivenPrefixes(258 "support/"259 )260 .forGivenTypesMap(261 "support/Activity" to "test/Activity",262 "support/Fragment" to "test/Fragment",263 "support/Annotation" to "test/Annotation"264 )265 .testThatGivenProGuard(266 "-keep public class * { \n" +267 " @support.Annotation support.Fragment \t get(support.Activity , " +268 "support.Fragment , keep.Please) ; \n" +269 "}"270 )271 .rewritesTo(272 "-keep public class * { \n" +273 " @test.Annotation test.Fragment \t get(test.Activity, test.Fragment, " +274 "keep.Please) ; \n" +275 "}"276 )277 }278 @Test fun proGuard_methodReturnTypeSelector_multiple() {279 ProGuardTester()280 .forGivenPrefixes(281 "support/"282 )283 .forGivenProGuardMapSet("support.**" to setOf("support.**", "androidx.**"))284 .testThatGivenProGuard(285 "-keep public class * { \n" +286 " support.** get(support.**); \n" +287 "}"288 )289 .rewritesTo(290 "-keep public class * { \n" +291 " support.** get(support.**); \n" +292 "}\n" +293 "-keep public class * { \n" +294 " androidx.** get(support.**); \n" +295 "}\n" +296 "-keep public class * { \n" +297 " support.** get(androidx.**); \n" +298 "}\n" +...

Full Screen

Full Screen

ProGuardTypesMapperTest.kt

Source:ProGuardTypesMapperTest.kt Github

copy

Full Screen

...17import org.junit.Test18class ProGuardTypesMapperTest {19 @Test fun proGuard_typeMapper_wildcard_simple() {20 ProGuardTester()21 .testThatGivenType("*")22 .getsRewrittenTo("*")23 }24 @Test fun proGuard_typeMapper_wildcard_double() {25 ProGuardTester()26 .testThatGivenType("**")27 .getsRewrittenTo("**")28 }29 @Test fun proGuard_typeMapper_wildcard_composed() {30 ProGuardTester()31 .testThatGivenType("**/*")32 .getsRewrittenTo("**/*")33 }34 @Test fun proGuard_typeMapper_wildcard_viaMap() {35 ProGuardTester()36 .forGivenPrefixes(37 "support/"38 )39 .forGivenProGuardMap(40 "support/v7/*" to "test/v7/*"41 )42 .testThatGivenType("support.v7.*")43 .getsRewrittenTo("test.v7.*")44 }45 @Test fun proGuard_typeMapper_wildcard_viaMap2() {46 ProGuardTester()47 .forGivenPrefixes(48 "support/"49 )50 .forGivenProGuardMap(51 "support/v7/**" to "test/v7/**"52 )53 .testThatGivenType("support.v7.**")54 .getsRewrittenTo("test.v7.**")55 }56 @Test fun proGuard_typeMapper_wildcard_viaTypesMap() {57 ProGuardTester()58 .forGivenPrefixes(59 "support/"60 )61 .forGivenTypesMap(62 "support/v7/Activity" to "test/v7/Activity"63 )64 .testThatGivenType("support.v7.Activity")65 .getsRewrittenTo("test.v7.Activity")66 }67 @Test fun proGuard_typeMapper_wildcard_notFoundInMap() {68 ProGuardTester()69 .forGivenPrefixes(70 "support/"71 )72 .forGivenProGuardMap(73 "support/**" to "test/**"74 )75 .testThatGivenType("keep.me.**")76 .getsRewrittenTo("keep.me.**")77 }78 @Test fun proGuard_typeMapper_differentPrefix_stillRewritten() {79 ProGuardTester()80 .forGivenPrefixes(81 "support/"82 )83 .forGivenTypesMap(84 "hello/Activity" to "test/Activity"85 )86 .testThatGivenType("hello.Activity")87 .getsRewrittenTo("test.Activity")88 }89 @Test fun proGuard_typeMapper_differentPrefix_wildcard_getsRewritten() {90 ProGuardTester()91 .forGivenPrefixes(92 "support/"93 )94 .forGivenProGuardMap(95 "hello/**" to "test/**"96 )97 .testThatGivenType("hello.**")98 .getsRewrittenTo("test.**")99 }100 @Test fun proGuard_typeMapper_innerClass() {101 ProGuardTester()102 .forGivenPrefixes(103 "support/"104 )105 .forGivenTypesMap(106 "support/Activity" to "test/Activity"107 )108 .testThatGivenType("support.Activity\$InnerClass")109 .getsRewrittenTo("test.Activity\$InnerClass")110 }111 @Test fun proGuard_typeMapper_innerWithStar() {112 ProGuardTester()113 .forGivenPrefixes(114 "support/"115 )116 .forGivenTypesMap(117 "support/Activity" to "test/Activity"118 )119 .testThatGivenType("support.Activity\$*")120 .getsRewrittenTo("test.Activity\$*")121 }122 @Test fun proGuard_typeMapper_innerWithDoubleStar() {123 ProGuardTester()124 .forGivenPrefixes(125 "support/"126 )127 .forGivenTypesMap(128 "support/Activity" to "test/Activity"129 )130 .testThatGivenType("support.Activity\$**")131 .getsRewrittenTo("test.Activity\$**")132 }133 @Test fun proGuard_typeMapper_innerClass_wildcard() {134 ProGuardTester()135 .forGivenPrefixes(136 "support/"137 )138 .forGivenProGuardMap(139 "**R\$Attrs" to "**R2\$Attrs"140 )141 .testThatGivenType("**R\$Attrs")142 .getsRewrittenTo("**R2\$Attrs")143 }144 @Test fun proGuard_argsMapper_tripleDots() {145 ProGuardTester()146 .testThatGivenArguments("...")147 .getRewrittenTo("...")148 }149 @Test fun proGuard_argsMapper_wildcard() {150 ProGuardTester()151 .testThatGivenArguments("*")152 .getRewrittenTo("*")153 }154 @Test fun proGuard_argsMapper_wildcards() {155 ProGuardTester()156 .testThatGivenArguments("**, **")157 .getRewrittenTo("**, **")158 }159 @Test fun proGuard_argsMapper_viaMaps() {160 ProGuardTester()161 .forGivenPrefixes(162 "support/"163 )164 .forGivenTypesMap(165 "support/Activity" to "test/Activity"166 )167 .forGivenProGuardMap(168 "support/v7/**" to "test/v7/**"169 )170 .testThatGivenArguments("support.Activity, support.v7.**, keep.Me")171 .getRewrittenTo("test.Activity, test.v7.**, keep.Me")172 }173 @Test fun proGuard_argsMapper_viaMaps_spaces() {174 ProGuardTester()175 .forGivenPrefixes(176 "support/"177 )178 .forGivenTypesMap(179 "support/Activity" to "test/Activity"180 )181 .forGivenProGuardMap(182 "support/v7/**" to "test/v7/**"183 )184 .testThatGivenArguments(" support.Activity , \t support.v7.**, keep.Me ")185 .getRewrittenTo("test.Activity, test.v7.**, keep.Me")186 }187 @Test fun proGuard_shouldIgnore() {188 ProGuardTester()189 .forGivenPrefixes(190 "support/"191 )192 .forGivenRules(193 "support/v7/Activity" to "ignore"194 )195 .testThatGivenType("support.v7.Activity")196 .getsRewrittenTo("support.v7.Activity")197 }198 @Test fun proGuard_shouldIgnore_withWildcard() {199 ProGuardTester()200 .forGivenPrefixes(201 "support/"202 )203 .forGivenRules(204 "support/v7/(.*)" to "ignore"205 )206 .testThatGivenType("support.v7.**")207 .getsRewrittenTo("support.v7.**")208 }209 @Test(expected = AssertionError::class)210 fun proGuard_shouldNotIgnore() {211 ProGuardTester()212 .forGivenPrefixes(213 "support/"214 )215 .forGivenRules(216 "support/v7/Activity" to "ignoreInPreprocessor"217 )218 .testThatGivenType("support.v7.Activity")219 .getsRewrittenTo("support.v7.Activity")220 }221 @Test fun proGuard_solver_wildcard_shouldRewrite() {222 ProGuardTester()223 .forGivenPrefixes(224 "support/"225 )226 .forGivenTypesMap(227 "support/v7/preference/Preference" to "test/preference/Preference",228 "support/v4/preference/PreferenceDialog" to "test/preference/PreferenceDialog",229 "support/v4/preference/SomethingElse" to "test/preference/SomethingElse",230 "support/v7/Random" to "test/Random"231 )232 .testThatGivenType("support.v?.preference.**")233 .getsRewrittenTo("test.preference.**")234 }235 @Test fun proGuard_solver_wildcard2_shouldRewrite() {236 ProGuardTester()237 .forGivenPrefixes(238 "support/"239 )240 .forGivenTypesMap(241 "support/v7/preference/Preference" to "test/preference/Preference",242 "support/v4/preference/SomethingElse" to "test/preference/SomethingElse",243 "support/v7/Random" to "test/Random"244 )245 .testThatGivenType("support.*.preference.**")246 .getsRewrittenTo("test.preference.**")247 }248 @Test fun proGuard_solver_wildcard3_shouldRewrite() {249 ProGuardTester()250 .forGivenPrefixes(251 "support/"252 )253 .forGivenTypesMap(254 "support/v7/preference/Preference" to "test/preference/Preference",255 "support/v4/preference/SomethingElse" to "test/preference/SomethingElse",256 "support/v4/preference/internal/Something" to "test/preference/internal/Something",257 "support/v7/Random" to "test/Random"258 )259 .testThatGivenType("support.*.preference.**")260 .getsRewrittenTo("test.preference.**")261 }262 @Test fun proGuard_solver_wildcard4_shouldRewrite() {263 ProGuardTester()264 .forGivenPrefixes(265 "support/"266 )267 .forGivenTypesMap(268 "support/v7/preference/Preference" to "test/preference/Preference",269 "support/v4/preference/PreferenceDialog" to "test/preference/PreferenceDialog",270 "support/v7/Random" to "test2/Random"271 )272 .testThatGivenType("support.**")273 .getsRewrittenTo("test.**", "test2.**")274 }275 @Test fun proGuard_solver_wildcard_needToMapPartOfClass_shouldRewrite() {276 ProGuardTester()277 .forGivenPrefixes(278 "support/"279 )280 .forGivenTypesMap(281 "support/v7/preference/Preference" to "test/preference/Preference",282 "support/v4/preference/PreferenceDialog" to "test/preference/PreferenceDialog",283 "support/v4/preference/SomethingElse" to "test/preference/SomethingElse"284 )285 .testThatGivenType("support.v7.preference.Preference*")286 .getsRewrittenTo("test.preference.Preference*")287 }288 @Test fun proGuard_solver_wildcard_oneToOne_shouldRewrite() {289 ProGuardTester()290 .forGivenPrefixes(291 "support/"292 )293 .forGivenTypesMap(294 "support/v7/preference/Preference" to "test/preference/Preference",295 "support/v4/preference/PreferenceDialog" to "test/preference/PreferenceDialog"296 )297 .testThatGivenType("support.v?.preference.Preference")298 .getsRewrittenTo("test.preference.Preference")299 }300 @Test fun proGuard_solver_wildcard_oneToOneStar_shouldRewrite() {301 ProGuardTester()302 .forGivenPrefixes(303 "support/"304 )305 .forGivenTypesMap(306 "support/v7/preference/Preference" to "test/preference/Preference"307 )308 .testThatGivenType("support.v?.preference.Preference*")309 .getsRewrittenTo("test.preference.Preference*")310 }311}...

Full Screen

Full Screen

ClassSpecTest.kt

Source:ClassSpecTest.kt Github

copy

Full Screen

...21 .forGivenPrefixes(22 "support/"23 )24 .forGivenTypesMap(25 "support/Activity" to "test/Activity",26 "support/Fragment" to "test/Fragment",27 "support/Annotation" to "test/Annotation"28 )29 .testThatGivenProGuard(30 "-keep class support.Activity"31 )32 .rewritesTo(33 "-keep class test.Activity"34 )35 }36 @Test fun proGuard_classSpec_allExistingRules() {37 ProGuardTester()38 .forGivenPrefixes(39 "support/"40 )41 .forGivenTypesMap(42 "support/Activity" to "test/Activity",43 "support/Fragment" to "test/Fragment",44 "support/Annotation" to "test/Annotation"45 )46 .testThatGivenProGuard(47 "-keep class support.Activity \n" +48 "-keepclassmembers class support.Activity \n" +49 "-keepclasseswithmembers class support.Activity \n" +50 "-keepnames class support.Activity \n" +51 "-keepclassmembernames class support.Activity \n" +52 "-keepclasseswithmembernames class support.Activity \n" +53 "-whyareyoukeeping class support.Activity \n" +54 "-assumenosideeffects class support.Activity"55 )56 .rewritesTo(57 "-keep class test.Activity \n" +58 "-keepclassmembers class test.Activity \n" +59 "-keepclasseswithmembers class test.Activity \n" +60 "-keepnames class test.Activity \n" +61 "-keepclassmembernames class test.Activity \n" +62 "-keepclasseswithmembernames class test.Activity \n" +63 "-whyareyoukeeping class test.Activity \n" +64 "-assumenosideeffects class test.Activity"65 )66 }67 @Test fun proGuard_classSpec_rulesModifiers() {68 ProGuardTester()69 .forGivenPrefixes(70 "support/"71 )72 .forGivenTypesMap(73 "support/Activity" to "test/Activity",74 "support/Fragment" to "test/Fragment",75 "support/Annotation" to "test/Annotation"76 )77 .testThatGivenProGuard(78 "-keep includedescriptorclasses class support.Activity \n" +79 "-keep allowshrinking class support.Activity \n" +80 "-keep allowoptimization class support.Activity \n" +81 "-keep allowobfuscation class support.Activity \n" +82 "-keep allowshrinking allowoptimization allowobfuscation class support.Activity" +83 " \n" +84 "-keep allowshrinking allowoptimization allowobfuscation class " +85 "support.Activity"86 )87 .rewritesTo(88 "-keep includedescriptorclasses class test.Activity \n" +89 "-keep allowshrinking class test.Activity \n" +90 "-keep allowoptimization class test.Activity \n" +91 "-keep allowobfuscation class test.Activity \n" +92 "-keep allowshrinking allowoptimization allowobfuscation class test.Activity \n" +93 "-keep allowshrinking allowoptimization allowobfuscation class test.Activity"94 )95 }96 @Test fun proGuard_classSpec_extends() {97 ProGuardTester()98 .forGivenPrefixes(99 "support/"100 )101 .forGivenTypesMap(102 "support/Activity" to "test/Activity",103 "support/Fragment" to "test/Fragment",104 "support/Annotation" to "test/Annotation"105 )106 .testThatGivenProGuard(107 "-keep class * extends support.Activity \n" +108 "-keep class support.Fragment extends support.Activity"109 )110 .rewritesTo(111 "-keep class * extends test.Activity \n" +112 "-keep class test.Fragment extends test.Activity"113 )114 }115 @Test fun proGuard_classSpec_modifiers_extends() {116 ProGuardTester()117 .forGivenPrefixes(118 "support/"119 )120 .forGivenTypesMap(121 "support/Activity" to "test/Activity"122 )123 .testThatGivenProGuard(124 "-keep !public enum * extends support.Activity \n" +125 "-keep public !final enum * extends support.Activity"126 )127 .rewritesTo(128 "-keep !public enum * extends test.Activity \n" +129 "-keep public !final enum * extends test.Activity"130 )131 }132 @Test fun proGuard_classSpec_annotation() {133 ProGuardTester()134 .forGivenPrefixes(135 "support/"136 )137 .forGivenTypesMap(138 "support/Activity" to "test/Activity",139 "support/Fragment" to "test/Fragment",140 "support/Annotation" to "test/Annotation"141 )142 .testThatGivenProGuard(143 "-keep @support.Annotation public class support.Activity \n" +144 "-keep @some.Annotation public class support.Activity"145 )146 .rewritesTo(147 "-keep @test.Annotation public class test.Activity \n" +148 "-keep @some.Annotation public class test.Activity"149 )150 }151 @Test fun proGuard_classSpec_annotation_extends() {152 ProGuardTester()153 .forGivenPrefixes(154 "support/"155 )156 .forGivenTypesMap(157 "support/Activity" to "test/Activity",158 "support/Fragment" to "test/Fragment",159 "support/Annotation" to "test/Annotation"160 )161 .testThatGivenProGuard(162 "-keep @support.Annotation public class * extends support.Activity\n" +163 "-keep @some.Annotation !public class * extends support.Activity"164 )165 .rewritesTo(166 "-keep @test.Annotation public class * extends test.Activity\n" +167 "-keep @some.Annotation !public class * extends test.Activity"168 )169 }170 @Test fun proGuard_classSpec_annotation_extends_spaces() {171 ProGuardTester()172 .forGivenPrefixes(173 "support/"174 )175 .forGivenTypesMap(176 "support/Activity" to "test/Activity",177 "support/Fragment" to "test/Fragment",178 "support/Annotation" to "test/Annotation"179 )180 .testThatGivenProGuard(181 "-keep \t @support.Annotation \t public class * extends support.Activity"182 )183 .rewritesTo(184 "-keep \t @test.Annotation \t public class * extends test.Activity"185 )186 }187 @Test fun proGuard_classSpec_multipleResults() {188 ProGuardTester()189 .forGivenPrefixes(190 "support/"191 )192 .forGivenProGuardMapSet(193 "support.**" to setOf("support.**", "androidx.**"))194 .testThatGivenProGuard(195 "-keep class support.**"196 )197 .rewritesTo(198 "-keep class support.**\n" +199 "-keep class androidx.**"200 )201 }202 @Test fun proGuard_classSpec_annotation_multipleResults() {203 ProGuardTester()204 .forGivenPrefixes(205 "support/"206 )207 .forGivenProGuardMapSet(208 "support.Activity*" to setOf("test.Activity1*", "test.Activity2*"),209 "support.Annotation*" to setOf("test.Annotation1*", "test.Annotation2*"))210 .testThatGivenProGuard(211 "-keep @support.Annotation* public class * extends support.Activity*"212 )213 .rewritesTo(214 "-keep @test.Annotation1* public class * extends test.Activity1*\n" +215 "-keep @test.Annotation2* public class * extends test.Activity1*\n" +216 "-keep @test.Annotation1* public class * extends test.Activity2*\n" +217 "-keep @test.Annotation2* public class * extends test.Activity2*"218 )219 }220}...

Full Screen

Full Screen

ClassSpecTest_NamedCtorSelector.kt

Source:ClassSpecTest_NamedCtorSelector.kt Github

copy

Full Screen

...21 .forGivenPrefixes(22 "support/"23 )24 .forGivenTypesMap(25 "support/Activity" to "test/Activity",26 "support/Fragment" to "test/Fragment"27 )28 .testThatGivenProGuard(29 "-keep public class * { \n" +30 " support.Activity(); \n" +31 " support.Activity(...); \n" +32 " support.Activity(*); \n" +33 " support.Activity(support.Activity); \n" +34 " support.Activity(support.Activity, support.Fragment, keep.Please); \n" +35 "}"36 )37 .rewritesTo(38 "-keep public class * { \n" +39 " test.Activity(); \n" +40 " test.Activity(...); \n" +41 " test.Activity(*); \n" +42 " test.Activity(test.Activity); \n" +43 " test.Activity(test.Activity, test.Fragment, keep.Please); \n" +44 "}"45 )46 }47 @Test fun proGuard_ctorSelector_modifiers() {48 ProGuardTester()49 .forGivenPrefixes(50 "support/"51 )52 .forGivenTypesMap(53 "support/Activity" to "test/Activity",54 "support/Fragment" to "test/Fragment"55 )56 .testThatGivenProGuard(57 "-keep public class * { \n" +58 " public support.Activity(); \n" +59 " public static support.Activity(...); \n" +60 " !private support.Activity(*); \n" +61 " !public !static support.Activity(support.Activity); \n" +62 " !protected support.Activity(support.Activity, support.Fragment, keep.Please);" +63 " \n" +64 "}"65 )66 .rewritesTo(67 "-keep public class * { \n" +68 " public test.Activity(); \n" +69 " public static test.Activity(...); \n" +70 " !private test.Activity(*); \n" +71 " !public !static test.Activity(test.Activity); \n" +72 " !protected test.Activity(test.Activity, test.Fragment, keep.Please); \n" +73 "}"74 )75 }76 @Test fun proGuard_ctorSelector_annotation() {77 ProGuardTester()78 .forGivenPrefixes(79 "support/"80 )81 .forGivenTypesMap(82 "support/Activity" to "test/Activity",83 "support/Fragment" to "test/Fragment",84 "support/Annotation" to "test/Annotation"85 )86 .testThatGivenProGuard(87 "-keep public class * { \n" +88 " @support.Annotation support.Activity(); \n" +89 " @support.Annotation support.Activity(...); \n" +90 " @support.Annotation support.Activity(*); \n" +91 " @support.Annotation support.Activity(support.Activity); \n" +92 " @support.Annotation support.Activity(support.Activity, support.Fragment, " +93 "keep.Please); \n" +94 "}"95 )96 .rewritesTo(97 "-keep public class * { \n" +98 " @test.Annotation test.Activity(); \n" +99 " @test.Annotation test.Activity(...); \n" +100 " @test.Annotation test.Activity(*); \n" +101 " @test.Annotation test.Activity(test.Activity); \n" +102 " @test.Annotation test.Activity(test.Activity, test.Fragment, keep.Please); \n" +103 "}"104 )105 }106 @Test fun proGuard_ctorSelector_modifiers_annotation() {107 ProGuardTester()108 .forGivenPrefixes(109 "support/"110 )111 .forGivenTypesMap(112 "support/Activity" to "test/Activity",113 "support/Fragment" to "test/Fragment",114 "support/Annotation" to "test/Annotation"115 )116 .testThatGivenProGuard(117 "-keep public class * { \n" +118 " @support.Annotation public support.Activity(); \n" +119 " @support.Annotation public static support.Activity(...); \n" +120 " @support.Annotation !private support.Activity(*); \n" +121 " @support.Annotation !public !static support.Activity(support.Activity); \n" +122 " @support.Annotation !protected support.Activity(support.Activity, " +123 "support.Fragment, keep.Please); \n" +124 "}"125 )126 .rewritesTo(127 "-keep public class * { \n" +128 " @test.Annotation public test.Activity(); \n" +129 " @test.Annotation public static test.Activity(...); \n" +130 " @test.Annotation !private test.Activity(*); \n" +131 " @test.Annotation !public !static test.Activity(test.Activity); \n" +132 " @test.Annotation !protected test.Activity(test.Activity, test.Fragment, " +133 "keep.Please); \n" +134 "}"135 )136 }137 @Test fun proGuard_ctorSelector_modifiers_annotation_spaces() {138 ProGuardTester()139 .forGivenPrefixes(140 "support/"141 )142 .forGivenTypesMap(143 "support/Activity" to "test/Activity",144 "support/Fragment" to "test/Fragment",145 "support/Annotation" to "test/Annotation"146 )147 .testThatGivenProGuard(148 "-keep public class * { \n" +149 " @support.Annotation !protected \t support.Activity( support.Activity ); \n" +150 "}"151 )152 .rewritesTo(153 "-keep public class * { \n" +154 " @test.Annotation !protected \t test.Activity(test.Activity); \n" +155 "}"156 )157 }158 @Test fun proGuard_ctorSelector_multiple() {159 ProGuardTester()160 .forGivenPrefixes(161 "support/"162 )163 .forGivenProGuardMapSet("support.**" to setOf("support.**", "androidx.**"))164 .testThatGivenProGuard(165 "-keep public class * { \n" +166 " support.**(support.**); \n" +167 "}"168 )169 .rewritesTo(170 "-keep public class * { \n" +171 " support.**(support.**); \n" +172 "}\n" +173 "-keep public class * { \n" +174 " androidx.**(support.**); \n" +175 "}\n" +176 "-keep public class * { \n" +177 " support.**(androidx.**); \n" +178 "}\n" +...

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1use \mageekguy\atoum;2{3 public function test()4 {5 ->if($this->newTestedInstance)6 ->object($this->testedInstance->getTest())7 ->isEqualTo($this)8 ;9 }10}11use \mageekguy\atoum;12{13 public function test()14 {15 ->if($this->newTestedInstance)16 ->object($this->testedInstance->getTest())17 ->isEqualTo($this)18 ;19 }20}21use \mageekguy\atoum;22{23 public function test()24 {25 ->if($this->newTestedInstance)26 ->object($this->testedInstance->getTest())27 ->isEqualTo($this)28 ;29 }30}31use \mageekguy\atoum;32{33 public function test()34 {35 ->if($this->newTestedInstance)36 ->object($this->testedInstance->getTest())37 ->isEqualTo($this)38 ;39 }40}41use \mageekguy\atoum;42{43 public function test()44 {45 ->if($this->newTestedInstance)46 ->object($this->testedInstance->getTest())47 ->isEqualTo($this)48 ;49 }50}51use \mageekguy\atoum;52{53 public function test()54 {

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1namespace Atoum;2require_once __DIR__ . '/vendor/autoload.php';3use mageekguy\atoum;4{5 public function testAdd()6 {7 ->if($add = new \Add())8 ->integer($add->add(2, 3))9 ->isEqualTo(5)10 ;11 }12}13namespace PHPUnit;14require_once __DIR__ . '/vendor/autoload.php';15{16 public function testAdd()17 {18 $add = new \Add();19 $this->assertEquals(5, $add->add(2, 3));20 }21}22namespace PHPSpec;23require_once __DIR__ . '/vendor/autoload.php';24{25 public function itShouldAdd()26 {27 $add = new \Add();28 $this->spec($add->add(2, 3))->should->be(5);29 }30}31namespace PHPUnit;32require_once __DIR__ . '/vendor/autoload.php';33{34 public function testAdd()35 {36 $add = new \Add();37 $this->assertEquals(5, $add->add(2, 3));38 }39}40namespace PHPSpec;41require_once __DIR__ . '/vendor/autoload.php';42{43 public function itShouldAdd()44 {45 $add = new \Add();46 $this->spec($add->add(2, 3))->should->be(5);47 }48}49namespace PHPSpec;50require_once __DIR__ . '/vendor/autoload.php';51{52 public function itShouldAdd()53 {54 $add = new \Add();55 $this->spec($add->add(2

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1require __DIR__ . '/vendor/autoload.php';2use mageekguy\atoum;3$script = new \mageekguy\atoum\scripts\runner();4$script->addDefaultReport();5$runner = $script->getRunner();6$runner->addTestsFromDirectory(__DIR__ . '/tests/units');7$runner->run();8namespace tests\units;9use atoum;10{11 public function testAdd()12 {13 ->given($a = 1, $b = 2)14 ->when($result = $a + $b)15 ->integer($result)16 ->isIdenticalTo(3);17 }18}19> PHP 5.6.7 (cli) (built: Mar 5 2015 12:05:27) by Zend Technologies with Xdebug 2.3.3

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1require_once 'vendor/autoload.php';2$test = new \mageekguy\atoum\test();3$test->run();4require_once 'vendor/autoload.php';5$test = new \mageekguy\atoum\test();6$test->run();7#0 [internal function]: mageekguy\atoum\autoloader->load('mageekguy\\atoum...')8#1 /var/www/html/atoum/vendor/atoum/atoum/classes/autoloader.php(52): spl_autoload_call('mageekguy\\atoum...')9#2 [internal function]: mageekguy\atoum\autoloader->load('mageekguy\\atoum...')10#3 /var/www/html/atoum/vendor/atoum/atoum/classes/autoloader.php(52): spl_autoload_call('mageekguy\\atoum...')

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1require 'vendor/autoload.php';2require 'test.php';3use atoum;4$test = new test();5$test->test1();6$test->test2();7$test->test3();8$test->test4();9class test extends atoum {10public function test1() {11$this->assert->string('toto')->isEqualTo('toto');12}13public function test2() {14$this->assert->string('toto')->isEqualTo('titi');15}16public function test3() {17$this->assert->string('toto')->isEqualTo('titi');18}19public function test4() {20$this->assert->string('toto')->isEqualTo('titi');21}22}

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1require_once 'vendor/autoload.php';2use atoum\test;3{4 public function test1()5 {6 ->if($var = '1')7 ->string($var)->isEqualTo('1');8 }9}10require_once 'vendor/autoload.php';11use atoum\test;12{13 public function test2()14 {15 ->if($var = '2')16 ->string($var)->isEqualTo('2');17 }18}19require_once 'vendor/autoload.php';20use atoum\test;21{22 public function test3()23 {24 ->if($var = '3')25 ->string($var)->isEqualTo('3');26 }27}28require_once 'vendor/autoload.php';29use atoum\test;30{31 public function test4()32 {33 ->if($var = '4')34 ->string($var)->isEqualTo('4');35 }36}37require_once 'vendor/autoload.php';38use atoum\test;39{40 public function test5()41 {42 ->if($var = '5')43 ->string($var)->isEqualTo('5');44 }45}46require_once 'vendor/autoload.php';47use atoum\test;48{49 public function test6()50 {51 ->if($var = '6')52 ->string($var)->isEqualTo('6');53 }54}55require_once 'vendor/autoload.php';56use atoum\test;

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1namespace atoum\tests\units;2use atoum;3{4public function testTest()5{6$this->boolean(true)->isTrue();7}8}9namespace atoum\tests\units;10use atoum;11{12public function testTest()13{14$this->boolean(false)->isTrue();15}16}17namespace atoum\tests\units;18use atoum;19{20public function testTest()21{22$this->boolean(false)->isFalse();23}24}25namespace atoum\tests\units;26use atoum;27{28public function testTest()29{30$this->boolean(true)->isFalse();31}32}33namespace atoum\tests\units;34use atoum;35{36public function testTest()37{38$this->boolean(true)->isTrue();39}40}41namespace atoum\tests\units;42use atoum;43{44public function testTest()45{46$this->boolean(false)->isTrue();47}48}49namespace atoum\tests\units;50use atoum;51{52public function testTest()53{54$this->boolean(false)->isFalse();55}56}57namespace atoum\tests\units;58use atoum;59{60public function testTest()61{62$this->boolean(true)->isFalse();63}64}65namespace atoum\tests\units;66use atoum;

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1require_once 'test.php';2{3 public function test1()4 {5 $this->assert->string($this->hello())->isIdenticalTo('hello world');6 }7}8require_once 'test.php';9{10 public function test2()11 {12 $this->assert->string($this->hello())->isIdenticalTo('hello world');13 }14}15require_once 'test.php';16{17 public function test3()18 {19 $this->assert->string($this->hello())->isIdenticalTo('hello world');20 }21}22require_once 'test.php';23{24 public function test4()25 {26 $this->assert->string($this->hello())->isIdenticalTo('hello world');27 }28}29require_once 'test.php';30{31 public function test5()32 {33 $this->assert->string($this->hello())->isIdenticalTo('hello world');34 }35}36require_once 'test.php';37{38 public function test6()39 {40 $this->assert->string($this->hello())->isIdenticalTo('hello world');41 }42}43require_once 'test.php';44{45 public function test7()46 {47 $this->assert->string($this->hello())->isIdenticalTo('hello world');48 }49}50require_once 'test.php';51{52 public function test8()53 {54 $this->assert->string($this->hello())->isIdenticalTo('hello world

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1namespace test\unit;2use atoum;3use \test\unit\testClass as testClass;4{5 public function testGet()6 {7 ->if($test = new testClass())8 ->object($test->get())9 ->isNotNull()10 ;11 }12}13namespace test\unit;14use atoum;15use \test\unit\testClass as testClass;16{17 public function testGet()18 {19 ->if($test = new testClass())20 ->object($test->get())21 ->isNotNull()22 ;23 }24}

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 Atoum automation tests on LambdaTest cloud grid

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

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful