samedi 7 novembre 2020

how to mock ServletUriComponentsBuilder

i have this good i am trying to mock it but i am getting lot of errors:

public String makeCreation(String name, String sureName, String familyName) {
        final Optional<String> port = Optional.ofNullable(environment.getProperty("local.server.port"));
        return ServletUriComponentsBuilder
            .fromCurrentServletMapping()
            .host( InetAddress.getLocalHost().getHostAddress())
            .port(port.orElse(DEFAULT_PORT))
            .path("/{name}/{sureName}/{familyName}")
            .encode()
            .buildAndExpand(name, sureName, familyNAme)
            .toUriString();
    }

while trying to mock this function like the following:

 given(familyService.makeCreation("alex", "adam", "alexAdam")).willReturn("http://someHost:8080" + "alex"+ "adam" + "/" + "alexAdamAlex"));

i am getting the following error:

Typically, stubbing argument mismatch indicates user mistake when writing tests. Mockito fails early so that you can debug potential problem easily. However, there are legit scenarios when this exception generates false negative signal:

Aucun commentaire:

Enregistrer un commentaire