Skip to content

Commit 204df4c

Browse files
committed
Fix test
1 parent 989c0cf commit 204df4c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1313

1414
import java.util.Arrays;
15+
import java.util.Objects;
1516

1617
import static org.junit.Assert.assertEquals;
1718
import static org.junit.Assert.assertTrue;
@@ -23,8 +24,23 @@
2324
@LargeTest
2425
public class ErrorInfoTest {
2526

27+
/**
28+
* @param errorInfo the error info to access
29+
* @return the private field errorInfo.message.stringRes using reflection
30+
*/
31+
private int getMessageFromErrorInfo(final ErrorInfo errorInfo)
32+
throws NoSuchFieldException, IllegalAccessException {
33+
final var message = ErrorInfo.class.getDeclaredField("message");
34+
message.setAccessible(true);
35+
final var messageValue = (ErrorInfo.Companion.ErrorMessage) message.get(errorInfo);
36+
37+
final var stringRes = ErrorInfo.Companion.ErrorMessage.class.getDeclaredField("stringRes");
38+
stringRes.setAccessible(true);
39+
return (int) Objects.requireNonNull(stringRes.get(messageValue));
40+
}
41+
2642
@Test
27-
public void errorInfoTestParcelable() {
43+
public void errorInfoTestParcelable() throws NoSuchFieldException, IllegalAccessException {
2844
final ErrorInfo info = new ErrorInfo(new ParsingException("Hello"),
2945
UserAction.USER_REPORT, "request", ServiceList.YouTube.getServiceId());
3046
// Obtain a Parcel object and write the parcelable object to it:
@@ -39,7 +55,7 @@ public void errorInfoTestParcelable() {
3955
assertEquals(ServiceList.YouTube.getServiceInfo().getName(),
4056
infoFromParcel.getServiceName());
4157
assertEquals("request", infoFromParcel.getRequest());
42-
assertEquals(R.string.parsing_error, infoFromParcel.getMessageStringId());
58+
assertEquals(R.string.parsing_error, getMessageFromErrorInfo(infoFromParcel));
4359

4460
parcel.recycle();
4561
}

0 commit comments

Comments
 (0)