fakeit icon indicating copy to clipboard operation
fakeit copied to clipboard

Can't use it from unit tests in Android

Open ivnsch opened this issue 7 years ago • 8 comments

When executed from a unit test in Android, Fakeit.init() throws an exception:

org.yaml.snakeyaml.error.YAMLException: java.io.IOException: Stream closed

at org.yaml.snakeyaml.reader.StreamReader.update(StreamReader.java:200) at org.yaml.snakeyaml.reader.StreamReader.(StreamReader.java:60) at org.yaml.snakeyaml.Yaml.load(Yaml.java:381) at com.mooveit.library.Fakeit.getValues(Fakeit.kt:79) at com.mooveit.library.Fakeit.(Fakeit.kt:69) at com.mooveit.library.Fakeit.(Fakeit.kt:49) at com.mooveit.library.Fakeit$Companion.fakeitInit(Fakeit.kt:233) at com.mooveit.library.Fakeit$Companion.initWithLocale(Fakeit.kt:253) at com.mooveit.library.Fakeit$Companion.initWithLocale(Fakeit.kt:259) at com.mooveit.library.Fakeit$Companion.init(Fakeit.kt:247) at xx.xxxxxx.xxxxx.viewmodels.LibraryViewModel.(LibraryViewModel.kt:104) at xx.xxxxxx.xxxxx.SMMLibraryNavTests.setup(SMMLibraryNavTests.kt:27) 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.RunBefores.evaluate(RunBefores.java:24) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 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.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84) 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.AppMain.main(AppMain.java:147)

ivnsch avatar Jun 16 '17 16:06 ivnsch

Thanks for the report @i-schuetz. Can you test it on v0.5?

https://github.com/moove-it/fakeit/releases/tag/v0.5

jotaemepereira avatar Jun 16 '17 19:06 jotaemepereira

@jotaemepereira I have the same bug on v0.7 on v0.5 I get an error java.io.FileNotFoundException: library/src/main/assets/locales/en.yml (No such file or directory)

jmfayard avatar Aug 14 '17 10:08 jmfayard

Tested it again, bug still present

jmfayard avatar Oct 10 '17 10:10 jmfayard

I was having this issue while running the project (not from unit tests), downgrading to 0.4 fixed it for me

mrjano avatar Nov 28 '17 11:11 mrjano

Same here, 0.5 isn't working and I'm getting the same exception as above. 0.4 works fine though

TheMaxCoder avatar Jan 04 '18 01:01 TheMaxCoder

v0.4, v0.6, and v0.7 give me org.yaml.snakeyaml.error.YAMLException: java.io.IOException: Stream closed when I try to do Fakeit.init().

v0.5 gives me java.io.FileNotFoundException: library/src/main/assets/locales/en.yml (No such file or directory), just like @jmfayard mentioned.

Byronium avatar Feb 24 '18 00:02 Byronium

I get the same error as @Byronium with v0.7 unless I copy the correct yml file to my app's debug/res/raw folder.

dsebastien avatar Mar 16 '18 21:03 dsebastien

Same for me in Unit testing

org.yaml.snakeyaml.error.YAMLException: java.io.IOException: Stream closed in v0.7

tamhuynhit avatar Jan 23 '19 05:01 tamhuynhit