1212import org .schabi .newpipe .extractor .exceptions .ParsingException ;
1313
1414import java .util .Arrays ;
15+ import java .util .Objects ;
1516
1617import static org .junit .Assert .assertEquals ;
1718import static org .junit .Assert .assertTrue ;
2324@ LargeTest
2425public 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