-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3310 from nextcloud/Utils_and_Webrtc
Added Instrumentation Test and Unit Tests
- Loading branch information
Showing
9 changed files
with
422 additions
and
4 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
app/src/androidTest/java/com/nextcloud/talk/utils/VibrationUtilsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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 | ||
* 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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
app/src/test/java/com/nextcloud/talk/utils/BundleKeysTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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 | ||
* 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
41
app/src/test/java/com/nextcloud/talk/utils/UriUtilsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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 | ||
* 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
4
app/src/test/java/com/nextcloud/talk/utils/UserIdUtilsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
app/src/test/java/com/nextcloud/talk/webrtc/DataChannelMessageNotifierTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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 | ||
* 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
40
app/src/test/java/com/nextcloud/talk/webrtc/GlobalsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <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 | ||
* 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) | ||
} | ||
} |
Oops, something went wrong.