Add few more tests for notification module (#4383)

This commit is contained in:
Madhur Gupta 2021-04-28 12:41:52 +05:30 committed by GitHub
parent 2e0f8e6d68
commit cb8a7c22da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 121 additions and 0 deletions

View file

@ -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 = ""
)
}
}

View file

@ -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
}
}