Open ninad458 opened 6 years ago
Same error... What could be wrong?
I am facing the same issue too
The following will fix this:
@Test
fun isProjectsCacheExpiredReturnsNotExpired() {
cache.setLastCacheTime(System.currentTimeMillis() - 1000).test()
val testObserver = cache.isProjectsCacheExpired().test()
testObserver.assertValue(false)
}
Sorry about that, I was using the incorrect value for the cache check. Here we now:
currentTime - it.lastCacheTime > expirationTime
Here, previously lastCacheTime was 1000 which meant the incorrect value was always being used in the calculation. @jeanPokou @AlanUeyn @ninad458 does this work for you here?
Thanks, @hitherejoe It is working now
Hello Joe.
It remains with error for the test of test method isProjectsCacheExpiredReturnsNotExpired:
"/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java" -ea -Didea.test.cyclic.buffer.size=1048576 -Didea.launcher.port=50193 ...
WARNING: No manifest file found at ./AndroidManifest.xml.
Falling back to the Android OS resources only.
To remove this warning, annotate your test class with @Config(manifest=Config.NONE).
java.lang.AssertionError: Expected: false (class: Boolean), Actual:
at io.reactivex.observers.BaseTestConsumer.fail(BaseTestConsumer.java:162)
at io.reactivex.observers.BaseTestConsumer.assertValue(BaseTestConsumer.java:327)
at br.cericatto.cache.ProjectsCacheImplTest.isProjectsCacheExpiredReturnsNotExpired(ProjectsCacheImplTest.kt:104)
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 org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:497)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.robolectric.internal.SandboxTestRunner$2.evaluate(SandboxTestRunner.java:228)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:110)
at org.robolectric.internal.SandboxTestRunner.runChild(SandboxTestRunner.java:37)
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:64)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
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)
Process finished with exit code 255
Also the same error happens for this other test method isProjectsCacheExpiredReturnsExpired.
Hi, @graffiti75 what version of Robolectric are you using? you should upgrade to 4.0.2. I was finally able to make it work with
@Test
fun isProjectCacheReturnsExpired() {
projectsCacheLocal.setLastCacheTime(1000L).test()
projectsCacheLocal.isProjectsCacheExpired().test().assertValue(true)
}
@Test
fun isProjectsCacheReturnsNotExpired() {
projectsCacheLocal.setLastCacheTime(System.currentTimeMillis()).test()
projectsCacheLocal.isProjectsCacheExpired().test().assertValue(true)
}
Here is the isProjectsCachedExpired function
override fun isProjectsCacheExpired(): Single<Boolean> {
val currentTime = System.currentTimeMillis()
val expirationInterval =(1000 * 60 * 60 ).toLong() // 1 hour
return projectsDataBase.configDao().getConfig()
.single(
// if config empty set last cache time to zero
Config(lastCacheTime = 0)).map {
currentTime - it.lastCacheTime > expirationInterval
}
}
Ps: You may have differents functions names
Robolectric
Version 3.4.2.
I tried updating the Robolectric version, but the same errors persists.
https://github.com/hitherejoe/GithubTrending/blob/da09a1dfcf39e84a8b29173d12fee7afd5790023/cache/src/test/java/co/joebirch/cache/ProjectsCacheImplTest.kt#L98