diff --git a/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationHelperUnitTests.kt b/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationHelperUnitTests.kt new file mode 100644 index 000000000..4d95f4f5f --- /dev/null +++ b/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationHelperUnitTests.kt @@ -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 = "" + ) + } + +} \ No newline at end of file diff --git a/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationWorkerFragmentUnitTests.kt b/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationWorkerFragmentUnitTests.kt new file mode 100644 index 000000000..86ad99858 --- /dev/null +++ b/app/src/test/kotlin/fr/free/nrw/commons/notification/NotificationWorkerFragmentUnitTests.kt @@ -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 + } + +} \ No newline at end of file