Skip to content
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

Exceção disparada: Method clear in android.util.SparseArray not mocked. #57

Open
giovannicmelo opened this issue Jan 6, 2022 · 1 comment

Comments

@giovannicmelo
Copy link

Em cenários de testes unitários com JUnit 4 que utilizem a classe ValidadorCPFCNPJ.java, a seguinte exceção é disparada:

Caused by: java.lang.RuntimeException: Method clear in android.util.SparseArray not mocked. See http://g.co/androidstudio/not-mocked for details.
	at android.util.SparseArray.clear(SparseArray.java)
	at br.com.concrete.canarinho.DigitoPara$Builder.trocandoPorSeEncontrar(DigitoPara.java:202)
	at br.com.concrete.canarinho.validator.ValidadorCPF.<clinit>(ValidadorCPF.java:18)
	... 56 more

Uma solução possível seria alterar na classe DigitoPara.java na linha 133, conforme abaixo

private final SparseArray<String> substituicoes = new SparseArray<String>();

para

private final SparseArrayCompat<String> substituicoes = new SparseArrayCompat<String>();

Desta forma, poderá ser usada em testes unitários na JVM.
https://developer.android.com/reference/android/support/v4/util/SparseArrayCompat.html

@AlyssonPHN
Copy link

Também preciso dessa correção.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants