-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ShadowCountDownTimer not work #7479
Comments
Hi @WingsII , 4.2.1 is old in a sense. Could you try latest 4.8.1 to check whether this problem was fixed? I remember there are some fixes were checked in for time. Looking forward your feedback. Thanks. |
After testing, this problem still exists on the latest version. Robolectric & Android VersionRobolectric : 4.8.1 |
Ah good catch. I notice that ShadowCountDownTimer's |
@WingsII from the shadow API it appears thata you have to call ShadowCountDownTimer.invokeTick: |
Looks like the real code uses SystemClock.elapsedRealtime(), which gives a virtual/fake time in Robolectric. However, it should be possible to idle the scheduler to invoke the ticks. |
There are several points:
|
It is because the constructor of CountDownTimer is shadowed in ShadowCountDownTimer (the |
Specifically, the constructor should probably be doing this: @Implementation
protected void __constructor__(long millisInFuture, long countDownInterval) {
this.countDownInterval = countDownInterval;
this.millisInFuture = millisInFuture;
this.started = false;
// call the original constructor
Shadow.invokeConstructor(
CountDownTimer.class,
countDownTimer,
ClassParameter.from(long.class, millisInFuture),
ClassParameter.from(long.class, countDownInterval));
} |
It works, great! |
This allows CountDownTimer's internal members to be properly initialized. At some point it may be worth investigating if we can remove ShadowCountDownTimer altogether. Fixes #7479 PiperOrigin-RevId: 465712347
This allows CountDownTimer's internal members to be properly initialized. At some point it may be worth investigating if we can remove ShadowCountDownTimer altogether. Fixes #7479 PiperOrigin-RevId: 466084183
This allows CountDownTimer's internal members to be properly initialized. At some point it may be worth investigating if we can remove ShadowCountDownTimer altogether. Fixes #7479 PiperOrigin-RevId: 466084183
This allows CountDownTimer's internal members to be properly initialized. At some point it may be worth investigating if we can remove ShadowCountDownTimer altogether. Fixes robolectric#7479 PiperOrigin-RevId: 466084183
Description
If CountDownTimer is used in the code, robolectric will automatically use ShadowCountDownTimer, I found that it cannot trigger onTick() callback. And its internal data (mHandler, etc.) are empty.
If I use the original CountDownTimer object, or a custom empty Shadow object, this problem does not occur. Member variables are also normal.
Steps to Reproduce
Create a CountDownTimer in the Test case and run timer.start(), its member variables are empty, and will not trigger onTick.
Robolectric & Android Version
Robolectric : 4.2.1
JDK 1.8.0_332
Link to a public git repo demonstrating the problem:
NA
The text was updated successfully, but these errors were encountered: