Skip to content

Commit

Permalink
style(association-manager): format using ktmft formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurelien9Code committed Dec 19, 2024
1 parent 6ca8480 commit b644cf5
Show file tree
Hide file tree
Showing 65 changed files with 7,842 additions and 7,842 deletions.
50 changes: 25 additions & 25 deletions app/src/androidTest/java/com/android/unio/HiltTestUtility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ import dagger.hilt.android.testing.HiltTestApplication
* configure the test application for Hilt.
*/
class HiltApplication : AndroidJUnitRunner() {
override fun onCreate(arguments: Bundle) {
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().permitAll().build())
super.onCreate(arguments)
}
override fun onCreate(arguments: Bundle) {
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder().permitAll().build())
super.onCreate(arguments)
}

override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application {
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
}
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application {
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
}

override fun onStart() {
// Ensure the test class is a subclass of TearDown or EndToEndTest.
val testClassName = InstrumentationRegistry.getArguments().getString("class")
testClassName?.let { className ->
try {
val testClass =
Class.forName(
className.replace(Regex("#[a-zA-Z0-9 ]*$"), "")) // Remove test method suffix.
override fun onStart() {
// Ensure the test class is a subclass of TearDown or EndToEndTest.
val testClassName = InstrumentationRegistry.getArguments().getString("class")
testClassName?.let { className ->
try {
val testClass =
Class.forName(
className.replace(Regex("#[a-zA-Z0-9 ]*$"), "")) // Remove test method suffix.

val extendsTearDown = TearDown::class.java.isAssignableFrom(testClass)
val extendsEndToEndTest = EndToEndTest::class.java.isAssignableFrom(testClass)
if (!extendsTearDown && !extendsEndToEndTest) {
throw IllegalStateException("Test class $className must extend TearDown or EndToEndTest.")
}
} catch (e: ClassNotFoundException) {
throw RuntimeException("Test class not found: $className", e)
}
val extendsTearDown = TearDown::class.java.isAssignableFrom(testClass)
val extendsEndToEndTest = EndToEndTest::class.java.isAssignableFrom(testClass)
if (!extendsTearDown && !extendsEndToEndTest) {
throw IllegalStateException("Test class $className must extend TearDown or EndToEndTest.")
}
super.onStart()
} catch (e: ClassNotFoundException) {
throw RuntimeException("Test class not found: $className", e)
}
}
}
super.onStart()
}
}
34 changes: 17 additions & 17 deletions app/src/androidTest/java/com/android/unio/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ import org.junit.After
* Scrolls to a component if it's not displayed and asserts if it is displayed
*/
fun SemanticsNodeInteraction.assertDisplayComponentInScroll() {
if (this.isNotDisplayed()) {
this.performScrollTo()
}
this.assertIsDisplayed()
if (this.isNotDisplayed()) {
this.performScrollTo()
}
this.assertIsDisplayed()
}

/*
* Adds a new user social to the list of user socials
*/
fun addNewUserSocial(composeTestRule: ComposeContentTestRule, username: String, platform: String) {
composeTestRule.onNodeWithTag(SocialsOverlayTestTags.ADD_BUTTON).performScrollTo().performClick()
composeTestRule.onNodeWithTag(SocialsOverlayTestTags.PROMPT_TEXT_FIELD).performTextInput(username)
composeTestRule.onNodeWithTag(SocialsOverlayTestTags.PROMPT_DROP_BOX).performClick()
composeTestRule
.onNodeWithTag(SocialsOverlayTestTags.PROMPT_DROP_BOX_ITEM + platform)
.performClick()
composeTestRule.onNodeWithTag(SocialsOverlayTestTags.PROMPT_SAVE_BUTTON).performClick()
composeTestRule.onNodeWithTag(SocialsOverlayTestTags.ADD_BUTTON).performScrollTo().performClick()
composeTestRule.onNodeWithTag(SocialsOverlayTestTags.PROMPT_TEXT_FIELD).performTextInput(username)
composeTestRule.onNodeWithTag(SocialsOverlayTestTags.PROMPT_DROP_BOX).performClick()
composeTestRule
.onNodeWithTag(SocialsOverlayTestTags.PROMPT_DROP_BOX_ITEM + platform)
.performClick()
composeTestRule.onNodeWithTag(SocialsOverlayTestTags.PROMPT_SAVE_BUTTON).performClick()
}

fun clearTest() {
Firebase.auth.unregisterAllAuthStateListeners()
unregisterAllSnapshotListeners()
unmockkAll()
clearAllMocks()
Firebase.auth.unregisterAllAuthStateListeners()
unregisterAllSnapshotListeners()
unmockkAll()
clearAllMocks()
}

open class TearDown {
@After open fun tearDown() = clearTest()
}
@After open fun tearDown() = clearTest()
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,50 @@ import org.mockito.kotlin.mock

class BottomNavigationTest : TearDown() {

@MockK private lateinit var navigationAction: NavigationAction
@MockK private lateinit var navigationAction: NavigationAction

private lateinit var eventRepository: EventRepository
private lateinit var eventViewModel: EventViewModel
private lateinit var eventRepository: EventRepository
private lateinit var eventViewModel: EventViewModel

@MockK private lateinit var imageRepository: ImageRepositoryFirebaseStorage
@MockK private lateinit var associationRepositoryFirestore: AssociationRepositoryFirestore
@MockK private lateinit var userDeletionRepository: UserDeletionUseCaseFirestore
@MockK
private lateinit var eventUserPictureRepositoryFirestore: EventUserPictureRepositoryFirestore
@MockK private lateinit var concurrentEventUserRepositoryFirestore: SaveUseCaseFirestore
@MockK private lateinit var imageRepository: ImageRepositoryFirebaseStorage
@MockK private lateinit var associationRepositoryFirestore: AssociationRepositoryFirestore
@MockK private lateinit var userDeletionRepository: UserDeletionUseCaseFirestore
@MockK
private lateinit var eventUserPictureRepositoryFirestore: EventUserPictureRepositoryFirestore
@MockK private lateinit var concurrentEventUserRepositoryFirestore: SaveUseCaseFirestore

private lateinit var userRepository: UserRepository
private lateinit var userViewModel: UserViewModel
private lateinit var userRepository: UserRepository
private lateinit var userViewModel: UserViewModel

@get:Rule val composeTestRule = createComposeRule()
@get:Rule val composeTestRule = createComposeRule()

private lateinit var searchViewModel: SearchViewModel
@MockK(relaxed = true) private lateinit var searchRepository: SearchRepository
private lateinit var searchViewModel: SearchViewModel
@MockK(relaxed = true) private lateinit var searchRepository: SearchRepository

@Before
fun setUp() {
MockKAnnotations.init(this)
eventRepository = mock { EventRepository::class.java }
eventViewModel =
EventViewModel(
eventRepository,
imageRepository,
associationRepositoryFirestore,
eventUserPictureRepositoryFirestore,
concurrentEventUserRepositoryFirestore)
@Before
fun setUp() {
MockKAnnotations.init(this)
eventRepository = mock { EventRepository::class.java }
eventViewModel =
EventViewModel(
eventRepository,
imageRepository,
associationRepositoryFirestore,
eventUserPictureRepositoryFirestore,
concurrentEventUserRepositoryFirestore)

userRepository = mock { UserRepositoryFirestore::class.java }
userViewModel = UserViewModel(userRepository, imageRepository, userDeletionRepository)
userRepository = mock { UserRepositoryFirestore::class.java }
userViewModel = UserViewModel(userRepository, imageRepository, userDeletionRepository)

searchViewModel = spyk(SearchViewModel(searchRepository))
searchViewModel = spyk(SearchViewModel(searchRepository))

composeTestRule.setContent {
HomeScreen(navigationAction, eventViewModel, userViewModel, searchViewModel)
}
composeTestRule.setContent {
HomeScreen(navigationAction, eventViewModel, userViewModel, searchViewModel)
}
}

@Test
fun testBottomNavigationMenuDisplayed() {
composeTestRule.onNodeWithTag(NavigationActionTestTags.BOTTOM_NAV_MENU).assertIsDisplayed()
}
}
@Test
fun testBottomNavigationMenuDisplayed() {
composeTestRule.onNodeWithTag(NavigationActionTestTags.BOTTOM_NAV_MENU).assertIsDisplayed()
}
}
Loading

0 comments on commit b644cf5

Please sign in to comment.