Hallo zusammen.
Ich möchte folgenden Unit Test gerne schreiben :
Die Model Klasse :
Und hier nun der Fehler :
Ich habe bereits die Mockito Abhängigkeit hinzugefügt :
Ich möchte folgenden Unit Test gerne schreiben :
Java:
private CSVSamsMatchDataImporter unitUnderTest;
@Mock
private CSVMatchDataDownloader csvMatchDataDownloader;
@Mock
private CSVSamsMatchDataParser csvSamsMatchDataParser;
@Mock
private SamsModelService samsModelService;
@BeforeEach
public void init() {
unitUnderTest = new CSVSamsMatchDataImporter(csvMatchDataDownloader, csvSamsMatchDataParser, samsModelService);
}
@Test
void canImportCSVMatchData() throws MalformedURLException {
given(csvMatchDataDownloader.downloadFileFromURL(any()))
.willReturn(Optional.of(Paths.get("src", "test", "resources", "TestData", "csv", "CommaSeparatedMatchWithoutResult.csv")));
unitUnderTest.importMatchDataFromURL(new URL(CSV_MATCH_DATA_URL));
}
Die Model Klasse :
Code:
@Service
@Log4j2
public record SamsModelService(@NonNull SamsAssociationService associationService,
@NonNull SamsSeasonService seasonService,
@NonNull SamsCompetitionService competitionService,
@NonNull SamsTeamService teamService,
@NonNull SamsMatchStatisticService matchStatisticService,
@NonNull SamsMatchService matchService) implements ModelService {
Und hier nun der Fehler :
Code:
Can not mock final classes with the following settings :
- explicit serialization (e.g. withSettings().serializable())
- extra interfaces (e.g. withSettings().extraInterfaces(...))
You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.
Underlying exception : java.lang.IllegalArgumentException: Could not create type
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class SamsModelService.
Can not mock final classes with the following settings :
- explicit serialization (e.g. withSettings().serializable())
- extra interfaces (e.g. withSettings().extraInterfaces(...))
Ich habe bereits die Mockito Abhängigkeit hinzugefügt :
Code:
implementation "org.mockito:mockito-inline:4.7.0"
testImplementation "org.mockito:mockito-inline:4.7.0"
Zuletzt bearbeitet: