Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Instrumentation Test and Unit Tests #3310

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Nextcloud Talk application
*
* @author Samanwith KSN
* Copyright (C) 2023 Samanwith KSN <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.utils

import android.content.Context
import android.os.Build
import android.os.VibrationEffect
import android.os.Vibrator
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnitRunner

@RunWith(MockitoJUnitRunner::class)
class VibrationUtilsTest {

@Mock
private lateinit var mockContext: Context

@Mock
private lateinit var mockVibrator: Vibrator

@Before
fun setup() {
Mockito.`when`(mockContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mockVibrator)
}

@Test
fun testVibrateShort() {
VibrationUtils.vibrateShort(mockContext)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Mockito.verify(mockVibrator)
.vibrate(
VibrationEffect
.createOneShot(
VibrationUtils.SHORT_VIBRATE,
VibrationEffect.DEFAULT_AMPLITUDE
)
)
} else {
Mockito.verify(mockVibrator).vibrate(VibrationUtils.SHORT_VIBRATE)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import android.os.VibrationEffect
import android.os.Vibrator

object VibrationUtils {
private const val SHORT_VIBRATE: Long = 100
const val SHORT_VIBRATE: Long = 100

fun vibrateShort(context: Context) {
val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
*/
public class DataChannelMessageNotifier {

private final Set<PeerConnectionWrapper.DataChannelMessageListener> dataChannelMessageListeners = new LinkedHashSet<>();
public final Set<PeerConnectionWrapper.DataChannelMessageListener> dataChannelMessageListeners =
new LinkedHashSet<>();

public synchronized void addListener(PeerConnectionWrapper.DataChannelMessageListener listener) {
if (listener == null) {
Expand Down
103 changes: 103 additions & 0 deletions app/src/test/java/com/nextcloud/talk/utils/BundleKeysTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Nextcloud Talk application
*
* @author Samanwith KSN
* Copyright (C) 2023 Samanwith KSN <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.utils

import com.nextcloud.talk.utils.bundle.BundleKeys
import junit.framework.TestCase.assertEquals
import org.junit.Test
class BundleKeysTest {

@Test
fun testBundleKeysValues() {
assertEquals("KEY_SELECTED_USERS", BundleKeys.KEY_SELECTED_USERS)
assertEquals("KEY_SELECTED_GROUPS", BundleKeys.KEY_SELECTED_GROUPS)
assertEquals("KEY_SELECTED_CIRCLES", BundleKeys.KEY_SELECTED_CIRCLES)
assertEquals("KEY_SELECTED_EMAILS", BundleKeys.KEY_SELECTED_EMAILS)
assertEquals("KEY_USERNAME", BundleKeys.KEY_USERNAME)
assertEquals("KEY_TOKEN", BundleKeys.KEY_TOKEN)
assertEquals("KEY_TRANSLATE_MESSAGE", BundleKeys.KEY_TRANSLATE_MESSAGE)
assertEquals("KEY_BASE_URL", BundleKeys.KEY_BASE_URL)
assertEquals("KEY_IS_ACCOUNT_IMPORT", BundleKeys.KEY_IS_ACCOUNT_IMPORT)
assertEquals("KEY_ORIGINAL_PROTOCOL", BundleKeys.KEY_ORIGINAL_PROTOCOL)
assertEquals("KEY_OPERATION_CODE", BundleKeys.KEY_OPERATION_CODE)
assertEquals("KEY_APP_ITEM_PACKAGE_NAME", BundleKeys.KEY_APP_ITEM_PACKAGE_NAME)
assertEquals("KEY_APP_ITEM_NAME", BundleKeys.KEY_APP_ITEM_NAME)
assertEquals("KEY_CONVERSATION_PASSWORD", BundleKeys.KEY_CONVERSATION_PASSWORD)
assertEquals("KEY_ROOM_TOKEN", BundleKeys.KEY_ROOM_TOKEN)
assertEquals("KEY_ROOM_ONE_TO_ONE", BundleKeys.KEY_ROOM_ONE_TO_ONE)
assertEquals("KEY_NEW_CONVERSATION", BundleKeys.KEY_NEW_CONVERSATION)
assertEquals("KEY_ADD_PARTICIPANTS", BundleKeys.KEY_ADD_PARTICIPANTS)
assertEquals("KEY_EXISTING_PARTICIPANTS", BundleKeys.KEY_EXISTING_PARTICIPANTS)
assertEquals("KEY_CALL_URL", BundleKeys.KEY_CALL_URL)
assertEquals("KEY_NEW_ROOM_NAME", BundleKeys.KEY_NEW_ROOM_NAME)
assertEquals("KEY_MODIFIED_BASE_URL", BundleKeys.KEY_MODIFIED_BASE_URL)
assertEquals("KEY_NOTIFICATION_SUBJECT", BundleKeys.KEY_NOTIFICATION_SUBJECT)
assertEquals("KEY_NOTIFICATION_SIGNATURE", BundleKeys.KEY_NOTIFICATION_SIGNATURE)
assertEquals("KEY_INTERNAL_USER_ID", BundleKeys.KEY_INTERNAL_USER_ID)
assertEquals("KEY_CONVERSATION_TYPE", BundleKeys.KEY_CONVERSATION_TYPE)
assertEquals("KEY_INVITED_PARTICIPANTS", BundleKeys.KEY_INVITED_PARTICIPANTS)
assertEquals("KEY_INVITED_CIRCLE", BundleKeys.KEY_INVITED_CIRCLE)
assertEquals("KEY_INVITED_GROUP", BundleKeys.KEY_INVITED_GROUP)
assertEquals("KEY_INVITED_EMAIL", BundleKeys.KEY_INVITED_EMAIL)
}

@Test
fun testBundleKeysValues2() {
assertEquals("KEY_CONVERSATION_NAME", BundleKeys.KEY_CONVERSATION_NAME)
assertEquals("KEY_RECORDING_STATE", BundleKeys.KEY_RECORDING_STATE)
assertEquals("KEY_CALL_VOICE_ONLY", BundleKeys.KEY_CALL_VOICE_ONLY)
assertEquals("KEY_CALL_WITHOUT_NOTIFICATION", BundleKeys.KEY_CALL_WITHOUT_NOTIFICATION)
assertEquals("KEY_FROM_NOTIFICATION_START_CALL", BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)
assertEquals("KEY_ROOM_ID", BundleKeys.KEY_ROOM_ID)
assertEquals("KEY_ARE_CALL_SOUNDS", BundleKeys.KEY_ARE_CALL_SOUNDS)
assertEquals("KEY_FILE_PATHS", BundleKeys.KEY_FILE_PATHS)
assertEquals("KEY_ACCOUNT", BundleKeys.KEY_ACCOUNT)
assertEquals("KEY_FILE_ID", BundleKeys.KEY_FILE_ID)
assertEquals("KEY_NOTIFICATION_ID", BundleKeys.KEY_NOTIFICATION_ID)
assertEquals("KEY_NOTIFICATION_TIMESTAMP", BundleKeys.KEY_NOTIFICATION_TIMESTAMP)
assertEquals("KEY_SHARED_TEXT", BundleKeys.KEY_SHARED_TEXT)
assertEquals("KEY_GEOCODING_QUERY", BundleKeys.KEY_GEOCODING_QUERY)
assertEquals("KEY_META_DATA", BundleKeys.KEY_META_DATA)
assertEquals("KEY_FORWARD_MSG_FLAG", BundleKeys.KEY_FORWARD_MSG_FLAG)
assertEquals("KEY_FORWARD_MSG_TEXT", BundleKeys.KEY_FORWARD_MSG_TEXT)
assertEquals("KEY_FORWARD_HIDE_SOURCE_ROOM", BundleKeys.KEY_FORWARD_HIDE_SOURCE_ROOM)
assertEquals("KEY_SYSTEM_NOTIFICATION_ID", BundleKeys.KEY_SYSTEM_NOTIFICATION_ID)
assertEquals("KEY_MESSAGE_ID", BundleKeys.KEY_MESSAGE_ID)
assertEquals("KEY_MIME_TYPE_FILTER", BundleKeys.KEY_MIME_TYPE_FILTER)
assertEquals(
"KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_AUDIO",
BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_AUDIO
)
assertEquals(
"KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO",
BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO
)
assertEquals("KEY_IS_MODERATOR", BundleKeys.KEY_IS_MODERATOR)
assertEquals("KEY_SWITCH_TO_ROOM", BundleKeys.KEY_SWITCH_TO_ROOM)
assertEquals("KEY_START_CALL_AFTER_ROOM_SWITCH", BundleKeys.KEY_START_CALL_AFTER_ROOM_SWITCH)
assertEquals("KEY_IS_BREAKOUT_ROOM", BundleKeys.KEY_IS_BREAKOUT_ROOM)
assertEquals("KEY_NOTIFICATION_RESTRICT_DELETION", BundleKeys.KEY_NOTIFICATION_RESTRICT_DELETION)
assertEquals("KEY_DISMISS_RECORDING_URL", BundleKeys.KEY_DISMISS_RECORDING_URL)
assertEquals("KEY_SHARE_RECORDING_TO_CHAT_URL", BundleKeys.KEY_SHARE_RECORDING_TO_CHAT_URL)
assertEquals("KEY_GEOCODING_RESULT", BundleKeys.KEY_GEOCODING_RESULT)
assertEquals("ADD_ACCOUNT", BundleKeys.ADD_ACCOUNT)
assertEquals("SAVED_TRANSLATED_MESSAGE", BundleKeys.SAVED_TRANSLATED_MESSAGE)
}
}
41 changes: 41 additions & 0 deletions app/src/test/java/com/nextcloud/talk/utils/UriUtilsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Nextcloud Talk application
*
* @author Samanwith KSN
* Copyright (C) 2023 Samanwith KSN <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.utils

import org.junit.Assert
import org.junit.Test

class UriUtilsTest {

@Test
fun testHasHttpProtocolPrefixed() {
val uriHttp = "http://www.example.com"
val resultHttp = UriUtils.hasHttpProtocollPrefixed(uriHttp)
Assert.assertTrue(resultHttp)

val uriHttps = "https://www.example.com"
val resultHttps = UriUtils.hasHttpProtocollPrefixed(uriHttps)
Assert.assertTrue(resultHttps)

val uriWithoutPrefix = "www.example.com"
val resultWithoutPrefix = UriUtils.hasHttpProtocollPrefixed(uriWithoutPrefix)
Assert.assertFalse(resultWithoutPrefix)
}
}
4 changes: 2 additions & 2 deletions app/src/test/java/com/nextcloud/talk/utils/UserIdUtilsTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* @author Marcel Hibbe
* @author Samanwith KSN
* Copyright (C) 2023 Marcel Hibbe <[email protected]>
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
* Copyright (C) 2023 Samanwith KSN <samanwith21@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Nextcloud Talk application
*
* @author Samanwith KSN
* Copyright (C) 2023 Samanwith KSN <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.webrtc

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify

class DataChannelMessageNotifierTest {

private lateinit var notifier: DataChannelMessageNotifier
private lateinit var listener: PeerConnectionWrapper.DataChannelMessageListener

@Before
fun setUp() {
notifier = DataChannelMessageNotifier()
listener = mock(PeerConnectionWrapper.DataChannelMessageListener::class.java)
}

@Test
fun testAddListener() {
notifier.addListener(listener)
assertTrue(notifier.dataChannelMessageListeners.contains(listener))
}

@Test
fun testRemoveListener() {
notifier.addListener(listener)
notifier.removeListener(listener)
assertFalse(notifier.dataChannelMessageListeners.contains(listener))
}

@Test
fun testNotifyAudioOn() {
notifier.addListener(listener)
notifier.notifyAudioOn()
verify(listener).onAudioOn()
}

@Test
fun testNotifyAudioOff() {
notifier.addListener(listener)
notifier.notifyAudioOff()
verify(listener).onAudioOff()
}

@Test
fun testNotifyVideoOn() {
notifier.addListener(listener)
notifier.notifyVideoOn()
verify(listener).onVideoOn()
}

@Test
fun testNotifyVideoOff() {
notifier.addListener(listener)
notifier.notifyVideoOff()
verify(listener).onVideoOff()
}

@Test
fun testNotifyNickChanged() {
notifier.addListener(listener)
val newNick = "NewNick"
notifier.notifyNickChanged(newNick)
verify(listener).onNickChanged(newNick)
}
}
40 changes: 40 additions & 0 deletions app/src/test/java/com/nextcloud/talk/webrtc/GlobalsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Nextcloud Talk application
*
* @author Samanwith KSN
* Copyright (C) 2023 Samanwith KSN <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.webrtc

import org.junit.Assert
import org.junit.Test

class GlobalsTest {
@Test
fun testRoomToken() {
Assert.assertEquals("roomToken", Globals.ROOM_TOKEN)
}

@Test
fun testTargetParticipants() {
Assert.assertEquals("participants", Globals.TARGET_PARTICIPANTS)
}

@Test
fun testTargetRoom() {
Assert.assertEquals("room", Globals.TARGET_ROOM)
}
}
Loading
Loading