mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Add few more tests for notification module (#4383)
This commit is contained in:
parent
2e0f8e6d68
commit
cb8a7c22da
2 changed files with 121 additions and 0 deletions
|
|
@ -0,0 +1,81 @@
|
|||
package fr.free.nrw.commons.notification
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.lang.reflect.Field
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class NotificationHelperUnitTests {
|
||||
|
||||
private lateinit var notificationHelper: NotificationHelper
|
||||
private lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
private lateinit var intent: Intent
|
||||
|
||||
@Mock
|
||||
private lateinit var notificationManager: NotificationManager
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
context = RuntimeEnvironment.application.applicationContext
|
||||
notificationHelper = NotificationHelper(context)
|
||||
|
||||
val fieldNotificationManager: Field =
|
||||
NotificationHelper::class.java.getDeclaredField("notificationManager")
|
||||
fieldNotificationManager.isAccessible = true
|
||||
fieldNotificationManager.set(notificationHelper, notificationManager)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checkNotNull() {
|
||||
Assert.assertNotNull(notificationHelper)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowNotification() {
|
||||
notificationHelper.showNotification(context, "", "", 0, intent)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testNotificationConstructorTypeUnknown() {
|
||||
Notification(
|
||||
notificationType = NotificationType.handledValueOf(""),
|
||||
notificationText = "",
|
||||
date = "",
|
||||
link = "",
|
||||
iconUrl = "",
|
||||
notificationId = ""
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testNotificationConstructorTypeMention() {
|
||||
Notification(
|
||||
notificationType = NotificationType.handledValueOf("mention"),
|
||||
notificationText = "",
|
||||
date = "",
|
||||
link = "",
|
||||
iconUrl = "",
|
||||
notificationId = ""
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package fr.free.nrw.commons.notification
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
class NotificationWorkerFragmentUnitTests {
|
||||
|
||||
private lateinit var fragment: NotificationWorkerFragment
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
fragment = NotificationWorkerFragment()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checkFragmentNotNull() {
|
||||
Assert.assertNotNull(fragment)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnCreate() {
|
||||
fragment.onCreate(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetNotificationList() {
|
||||
fragment.notificationList = null
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetNotificationList() {
|
||||
fragment.notificationList
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue