Mockint objectmapper with mockito (#9017)

* Mockint objectmapper with mockito

* enforcing naming convention for test classes

* removed Spring

* removed unattended changes

* modified example

* simplified call stack in flower validator
This commit is contained in:
Gergo Petrik
2020-04-24 16:00:30 +02:00
committed by GitHub
parent 5738683a5b
commit b31b84d475
5 changed files with 118 additions and 1 deletions
@@ -0,0 +1,32 @@
package com.baeldung.mockito.objectmapper;
public class Flower {
private String name;
private Integer petals;
public Flower(String name, Integer petals) {
this.name = name;
this.petals = petals;
}
public Flower() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPetals() {
return petals;
}
public void setPetals(Integer petals) {
this.petals = petals;
}
}
@@ -0,0 +1,17 @@
package com.baeldung.mockito.objectmapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class FlowerJsonStringValidator {
private ObjectMapper objectMapper;
public FlowerJsonStringValidator(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
public boolean flowerHasPetals(String jsonFlowerAsString) throws JsonProcessingException {
Flower flower = objectMapper.readValue(jsonFlowerAsString, Flower.class);
return flower.getPetals() > 0;
}
}