Hallo zusammen, ich möchte in einem Unit Test Objekte mocken, die von einem anderen Typ angeleitet sind. Hier mal der Code :
Interfaces : (Modul Interface)
ImportedData : (Modul Imported Data)
TEST :
Der Test soll eigentlich nur das Interface Modul kennen und auf die konkrete Implementierung verzichten können.
Allerdings bekomme ich dann einen Fehler beim Compilieren :
Cannot resolve method 'thenReturn(java.util.Optional<T>)'
Kann mir jemand einen Tipp geben, wie ich das Problem beheben kann ?
Vielen Dank
Euer Tummi
Interfaces : (Modul Interface)
Java:
public interface IData {
...
Java:
public interface ILocationData extends IData .... {
Java:
public interface IMatchData extends IData {
...
Optional<? extends IData> getLocationData();
ImportedData : (Modul Imported Data)
Java:
public class ImportedMatchData implements IMatchData {
@NonNull
private ImportedLocationData locationData;
@Override
public Optional<ImportedLocationData> getLocationData() {
return Optional.ofNullable(locationData);
}
...
Java:
class ImportedLocationData implements ILocationData {
...
TEST :
Der Test soll eigentlich nur das Interface Modul kennen und auf die konkrete Implementierung verzichten können.
Java:
IResultData resultData = mock(IResultData.class);
ILocationData locationData = Mockito.mock(ILocationData.class);
IMatchData matchData = Mockito.mock(IMatchData.class);
...
when(matchData.getResultData()).thenReturn(Optional.of(resultData));
when(matchData.getLocationData()).thenReturn(Optional.of(locationData));
Allerdings bekomme ich dann einen Fehler beim Compilieren :
Cannot resolve method 'thenReturn(java.util.Optional<T>)'
Kann mir jemand einen Tipp geben, wie ich das Problem beheben kann ?
Vielen Dank
Euer Tummi