简体   繁体   English

更新Pushwoosh时发生ExceptionInInitializerError

[英]ExceptionInInitializerError when updated Pushwoosh

Good afternoon. 下午好。

I do not know what to do next. 我不知道下一步该怎么做。 Already tried and updated robolectric and changed some implementations test runner (it is custom). 已经尝试并更新了robolectric,并更改了一些实现测试运行程序(这是自定义的)。 I upgraded the library in build.gradle and the application on the tests began to fall with an error: 我升级了build.gradle中的库,测试中的应用程序开始因错误而掉线:

java.lang.ExceptionInInitializerError
    at com.pushwoosh.location.geofencer.GeofenceReceiver.<init>(Unknown Source)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.robolectric.util.ReflectionHelpers.callConstructor(ReflectionHelpers.java:321)
    at org.robolectric.internal.bytecode.ShadowImpl.newInstanceOf(ShadowImpl.java:20)
    at org.robolectric.shadow.api.Shadow.newInstanceOf(Shadow.java:35)
    at org.robolectric.shadows.ShadowApplication.registerBroadcastReceivers(ShadowApplication.java:138)
    at org.robolectric.shadows.ShadowApplication.bind(ShadowApplication.java:127)
    at org.robolectric.shadows.CoreShadowsAdapter.bind(CoreShadowsAdapter.java:71)
    at org.robolectric.android.internal.ParallelUniverse.setUpApplicationState(ParallelUniverse.java:107)
    at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:290)
    at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:203)
    at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:109)
    at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:36)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.internal.SandboxTestRunner$1.evaluate(SandboxTestRunner.java:63)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
Caused by: java.lang.NullPointerException
    at com.pushwoosh.location.d.a.<init>(Unknown Source)
    at com.pushwoosh.location.internal.a.<clinit>(Unknown Source)
    ... 33 more

my Test class: 我的测试班:

@RunWith(CustomRobolectricRunner.class)
@Config(constants = BuildConfig.class)
@FragmentScope
public class LentaPresenterTest {

    @Mock
    private LentaItem lentaItemMock;
    @Mock
    private ChampionatRepository championatDataRepositoryMock;
    @Mock
    private CommentsRepository commentsRepositoryMock;
    @Mock
    private LocalRepository localRepositoryMock;
    @Inject
    BookmarkRepository bookmarkRepository;
    @Mock
    private LentaView lentaViewMock;
    @Mock
    private Exception exceptionMock;
    @Inject
    Context context;
    @Inject
    LocalRepository localRepository;
    @Mock
    private NetworkInfoManager networkInfoManager;
    @Inject
    protected LentaPresenter lentaPresenterTest;

    private List<LentaItem> lentaItemListMock;
    private Observable<GetLentaInteractor.LentaResponce> observable;
    private Observable<Boolean> isShowFontObservable;

    private TestScheduler testScheduler = Schedulers.test();

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        TestApp.getTestComponent().createTestActivityComponent(new TestActivityModule(mock(Activity.class))).
                createTestFragmentComponent(new TestFragmentModule(mock(Fragment.class))).inject(this);
        lentaPresenterTest = spy(lentaPresenterTest);

        assert lentaPresenterTest.getLentaInteractor != null;

        lentaItemListMock = new ArrayList<>();
        lentaItemListMock.add(lentaItemMock);

        observable = Observable.just(new GetLentaInteractor.LentaResponce(lentaItemListMock, 2));
        lentaPresenterTest.setView(lentaViewMock);
        lentaPresenterTest.getLentaInteractor = spy(new GetLentaInteractor(championatDataRepositoryMock, commentsRepositoryMock, localRepositoryMock, bookmarkRepository, networkInfoManager) {

            @Override
            public Subscription execute(LentaFilter lentaFilter, Subscriber<LentaResponce> subscriber) {
                return observable.subscribe(subscriber);
            }
        });

        lentaPresenterTest.isShowRatingViewInteractor = spy(new IsShowRatingViewInteractor(localRepository, context) {
            @Override
            protected Observable<Boolean> buildObservable() {
                return isShowFontObservable;
            }
        });

        lentaPresenterTest.isShowRatingViewInteractor.setJobScheduler(testScheduler);
        lentaPresenterTest.isShowRatingViewInteractor.setIuScheduler(testScheduler);
    }


    @Test
    public void interactorOnErrorTest() {
        observable = Observable.error(exceptionMock);

        lentaPresenterTest.initialize();

        verify(lentaViewMock, times(1)).startProgress();
        verify(lentaViewMock, times(1)).setSelectedSportsKinds(anyList());
        verify(lentaViewMock, times(1)).showLayoutWithInformation();
        verify(lentaViewMock, times(1)).stopProgress();
        verifyNoMoreInteractions(lentaViewMock);
    }

    @Test
    public void interactorOnErrorTest_showTop() {
        observable = observable.concatWith(Observable.<GetLentaInteractor.LentaResponce>error(exceptionMock));

        lentaPresenterTest.initialize();
        verify(lentaViewMock, times(1)).startProgress();
        verify(lentaViewMock, times(1)).setSelectedSportsKinds(anyList());
        verify(lentaViewMock, times(1)).inflateData(anyList());
        verify(lentaViewMock, times(1)).hideBottomErrorMessage();
        verify(lentaViewMock, times(1)).showTopErrorMessage();
        verify(lentaViewMock, times(1)).stopProgress();
        verifyNoMoreInteractions(lentaViewMock);
    }

    @Test
    public void interactorOnNextTest_first_request_true() {
        isShowFontObservable = Observable.just(true);
        lentaPresenterTest.lentaFilter = LentaFilter.EMPTY;
        lentaPresenterTest.initialize();

        testScheduler.triggerActions();
        verify(lentaPresenterTest.getLentaInteractor, times(1)).execute(any(LentaFilter.class), any(Subscriber.class));
        verify(lentaPresenterTest.isShowRatingViewInteractor, times(1)).execute(any(Subscriber.class));
        verify(lentaViewMock, times(1)).inflateData(lentaItemListMock);
    }

    @Test
    public void interactorOnNextTest_first_request_false() {
        isShowFontObservable = Observable.just(true);
        lentaPresenterTest.lentaFilter = LentaFilter.EMPTY.lentaBefore("before id");
        lentaPresenterTest.initialize();

        testScheduler.triggerActions();
        verify(lentaPresenterTest.getLentaInteractor, times(1)).execute(any(LentaFilter.class), any(Subscriber.class));
        verify(lentaPresenterTest.isShowRatingViewInteractor, times(1)).execute(any(Subscriber.class));
        verify(lentaViewMock, times(1)).appendData(lentaItemListMock);
    }
}

My build.gradle: 我的build.gradle:

testCompile 'org.robolectric:robolectric:3.3.2'
testCompile 'org.robolectric:shadows-multidex:3.3.2'
testCompile 'org.robolectric:shadows-play-services:3.1'

I got an error after updating the pushwoosh library. 更新pushwoosh库后出现错误。

For help in advance thanks! 提前寻求帮助,谢谢!

PS The files are actually larger (it is logical that in principle the tests), but all fall with the only error that I showed above. PS文件实际上更大(原则上测试是合乎逻辑的),但全部都属于我上面显示的唯一错误。

The issue is caused by Robolectric trying to create a GeofenceReceiver, which just cannot exist before Pushwoosh is initialized. 该问题是由Robolectric尝试创建GeofenceReceiver引起的,该对象在初始化Pushwoosh之前就不存在。

You can find workaround the issue by removing unnecessary receivers like described in this thread: 您可以通过删除此线程中所述的不必要的接收器来解决此问题:

Android Instrumentation test java.lang.UnsatisfiedLinkError on using AndroidJunitRunner and AndroidJUnit4 Android Instrumentation在使用AndroidJunitRunner和AndroidJUnit4时测试java.lang.UnsatisfiedLinkError

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM