1
I’m developing unit test of a class with Junit and Mockite, and to facilitate the creation of a spy
of this class I created a function that builds and returns this spy
. The problem that is occurring is that in the call flow that is performed to perform the test, when the method call is made equals
of that Spy, instead of calling the function implemented in the class, is calling a function of the class MethodInterceptorFilter
. Does anyone know how to get him to get the function implemented in the class?
test function:
@Test
public void requisicaoInvalidaNomeDuplicado() {
prov.add(umProvTO("Premio", 5, new BenTO( 32, new BigDecimal(200) )));
prov.add(umProvTO("Premio", 10, new BenTO( 32, new BigDecimal(500) )));
assertEquals(false, requisicao.validarNomeDuplicado());
}
implementation of the function validarNomeDuplicado()
private List<ProvTO> provs;
public boolean validarNomeDuplicado() {
for (ProvTO prov : provs) {
if (Collections.frequency(provs, prov) > 1) {
return false;
}
}
return true;
}
class ProvTO
:
private String nome;
[...]
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ProvTO)) {
return false;
}
ProvTO other = (ProvTO) obj;
if (nome == null) {
if (other.nome != null) {
return false;
}
} else if (!nome.equals(other.nome)) {
return false;
}
return true;
}
Can you validate if the published code snippet is correct? The No Increase function is accessing provs and not Prov. And there is a class umProvTO.java?
– Daniela Morais
provs
is ofprivate List<ProvTO> provs;
– Isdeniel