im mocking mapper.convertValue to return 2 different return type of same class.
Target target1 = new Target();
target1.setId("123);
Target target2 = new Target();
target2.setId("345);
Mockito.when(mapper.convertValue(anyMap(), eq(Target.class))).thenReturn(target1);
Mockito.when(mapper.convertValue(anyMap(), eq(Target.class))).thenReturn(target2);
The actual code is called this way , where i want to mock the objectmapper to return target1 or target2 depending on the pair. Right now its overriding one over the other in order i have defined.
List<Pair<String, Target>> targetPairs = targetPairList.entrySet().stream()
.map(pair -> ImmutablePair.of(pair.getKey(), mapper.convertValue(pair.getValue().getSourceAsMap(), Target.class)))
.collect(Collectors.toList());
Any help is appreciated.