Skip to content

Commit 245ef89

Browse files
committed
Revert gradle dependency changes
1 parent 17f5aa7 commit 245ef89

5 files changed

Lines changed: 128 additions & 76 deletions

File tree

app/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,11 @@ dependencies {
337337
/** Testing **/
338338
testImplementation libs.junit
339339
testImplementation libs.mockito.core
340-
androidTestImplementation libs.mockito.android
341-
androidTestImplementation libs.mockito.kotlin
342340

343341
androidTestImplementation libs.androidx.junit
344342
androidTestImplementation libs.androidx.runner
345343
androidTestImplementation libs.androidx.room.testing
346344
androidTestImplementation libs.assertj.core
347-
348-
androidTestImplementation platform(libs.androidx.compose.bom)
349-
androidTestImplementation libs.androidx.compose.ui.test.junit4
350-
debugImplementation libs.androidx.compose.ui.test.manifest
351345
}
352346

353347
static String getGitWorkingBranch() {

app/src/androidTest/java/org/schabi/newpipe/error/ErrorInfoTest.java

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,128 @@
11
package org.schabi.newpipe.error
22

3+
import android.content.Context
4+
import android.os.Parcel
5+
import android.os.Parcelable
6+
import androidx.test.core.app.ApplicationProvider
7+
import androidx.test.ext.junit.runners.AndroidJUnit4
8+
import androidx.test.filters.LargeTest
9+
import org.junit.Assert.assertEquals
10+
import org.junit.Assert.assertFalse
11+
import org.junit.Assert.assertNull
12+
import org.junit.Assert.assertTrue
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
15+
import org.schabi.newpipe.R
16+
import org.schabi.newpipe.extractor.ServiceList
17+
import org.schabi.newpipe.extractor.exceptions.ParsingException
18+
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException
19+
import java.io.IOException
20+
import java.net.SocketTimeoutException
21+
22+
/**
23+
* Instrumented tests for {@link ErrorInfo}.
24+
*/
25+
@RunWith(AndroidJUnit4::class)
26+
@LargeTest
327
class ErrorInfoTest {
4-
}
28+
private val context: Context by lazy { ApplicationProvider.getApplicationContext<Context>() }
29+
30+
/**
31+
* @param errorInfo the error info to access
32+
* @return the private field errorInfo.message.stringRes using reflection
33+
*/
34+
@Throws(NoSuchFieldException::class, IllegalAccessException::class)
35+
private fun getMessageFromErrorInfo(errorInfo: ErrorInfo): Int {
36+
val message = ErrorInfo::class.java.getDeclaredField("message")
37+
message.isAccessible = true
38+
val messageValue = message.get(errorInfo) as ErrorInfo.Companion.ErrorMessage
39+
40+
val stringRes = ErrorInfo.Companion.ErrorMessage::class.java.getDeclaredField("stringRes")
41+
stringRes.isAccessible = true
42+
return stringRes.get(messageValue) as Int
43+
}
44+
45+
@Test
46+
@Throws(NoSuchFieldException::class, IllegalAccessException::class)
47+
fun errorInfoTestParcelable() {
48+
val info = ErrorInfo(
49+
ParsingException("Hello"),
50+
UserAction.USER_REPORT,
51+
"request",
52+
ServiceList.YouTube.serviceId
53+
)
54+
// Obtain a Parcel object and write the parcelable object to it:
55+
val parcel = Parcel.obtain()
56+
info.writeToParcel(parcel, 0)
57+
parcel.setDataPosition(0)
58+
val creatorField = ErrorInfo::class.java.getDeclaredField("CREATOR")
59+
val creator = creatorField.get(null)
60+
check(creator is Parcelable.Creator<*>)
61+
val infoFromParcel = requireNotNull(
62+
creator.createFromParcel(parcel) as? ErrorInfo
63+
)
64+
assertTrue(
65+
infoFromParcel.stackTraces.contentToString()
66+
.contains(ErrorInfoTest::class.java.simpleName)
67+
)
68+
assertEquals(UserAction.USER_REPORT, infoFromParcel.userAction)
69+
assertEquals(
70+
ServiceList.YouTube.serviceInfo.name,
71+
infoFromParcel.getServiceName()
72+
)
73+
assertEquals("request", infoFromParcel.request)
74+
assertEquals(R.string.parsing_error, getMessageFromErrorInfo(infoFromParcel))
75+
76+
parcel.recycle()
77+
}
78+
79+
/**
80+
* Test: Network error on initial load (Resource.Error)
81+
*/
82+
83+
@Test
84+
fun testInitialCommentNetworkError() {
85+
val errorInfo = ErrorInfo(
86+
throwable = SocketTimeoutException("Connection timeout"),
87+
userAction = UserAction.REQUESTED_COMMENTS,
88+
request = "comments"
89+
)
90+
assertEquals(context.getString(R.string.network_error), errorInfo.getMessage(context))
91+
assertTrue(errorInfo.isReportable)
92+
assertTrue(errorInfo.isRetryable)
93+
assertNull(errorInfo.recaptchaUrl)
94+
}
95+
96+
/**
97+
* Test: Network error on paging (LoadState.Error)
98+
*/
99+
@Test
100+
fun testPagingNetworkError() {
101+
val errorInfo = ErrorInfo(
102+
throwable = IOException("Paging failed"),
103+
userAction = UserAction.REQUESTED_COMMENTS,
104+
request = "comments"
105+
)
106+
assertEquals(context.getString(R.string.network_error), errorInfo.getMessage(context))
107+
assertTrue(errorInfo.isReportable)
108+
assertTrue(errorInfo.isRetryable)
109+
assertNull(errorInfo.recaptchaUrl)
110+
}
111+
112+
/**
113+
* Test: ReCaptcha during comments load
114+
*/
115+
@Test
116+
fun testReCaptchaDuringComments() {
117+
val url = "https://www.google.com/recaptcha/api/fallback?k=test"
118+
val errorInfo = ErrorInfo(
119+
throwable = ReCaptchaException("ReCaptcha needed", url),
120+
userAction = UserAction.REQUESTED_COMMENTS,
121+
request = "comments"
122+
)
123+
assertEquals(context.getString(R.string.recaptcha_request_toast), errorInfo.getMessage(context))
124+
assertEquals(url, errorInfo.recaptchaUrl)
125+
assertFalse(errorInfo.isReportable)
126+
assertTrue(errorInfo.isRetryable)
127+
}
128+
}

app/src/main/java/org/schabi/newpipe/ui/components/common/ErrorPanel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.schabi.newpipe.ui.components.common
22

33
import android.content.Intent
4+
import android.content.res.Configuration
45
import androidx.compose.foundation.layout.Arrangement
56
import androidx.compose.foundation.layout.Column
67
import androidx.compose.material3.MaterialTheme
@@ -86,7 +87,8 @@ fun ErrorPanel(
8687
}
8788
}
8889

89-
@Preview(showBackground = true, widthDp = 360, heightDp = 640, backgroundColor = 0xffffffff)
90+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
91+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
9092
@Composable
9193
fun ErrorPanelPreview() {
9294
AppTheme {

gradle/libs.versions.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ lifecycle = "2.6.2"
3232
markwon = "4.6.2"
3333
material = "1.11.0"
3434
media = "1.7.0"
35-
mockitoAndroid = "5.6.0"
3635
mockitoCore = "5.6.0"
37-
mockitoKotlin = "5.2.1"
3836
navigationCompose = "2.8.3"
3937
okhttp = "4.12.0"
4038
pagingCompose = "3.3.2"
@@ -90,8 +88,6 @@ androidx-compose-adaptive = { group = "androidx.compose.material3.adaptive", nam
9088
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "jetpack-compose" }
9189
androidx-compose-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended" }
9290
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
93-
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
94-
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
9591
androidx-compose-ui-text = { group = "androidx.compose.ui", name = "ui-text" }
9692
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
9793
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
@@ -151,9 +147,7 @@ lisawray-groupie-viewbinding = { group = "com.github.lisawray.groupie", name = "
151147
livefront-bridge = { group = "com.github.livefront", name = "bridge", version.ref = "bridge" }
152148
markwon-core = { group = "io.noties.markwon", name = "core", version.ref = "markwon" }
153149
markwon-linkify = { group = "io.noties.markwon", name = "linkify", version.ref = "markwon" }
154-
mockito-android = { group = "org.mockito", name = "mockito-android", version.ref = "mockitoAndroid" }
155150
mockito-core = { group = "org.mockito", name = "mockito-core", version.ref = "mockitoCore" }
156-
mockito-kotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version.ref = "mockitoKotlin" }
157151
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
158152
prettytime = { group = "org.ocpsoft.prettytime", name = "prettytime", version.ref = "prettytime" }
159153
process-phoenix = { group = "com.jakewharton", name = "process-phoenix", version.ref = "processPhoenix" }

0 commit comments

Comments
 (0)