这是我对schemaController的单元测试。但是,当我在Intellij IDEA中对覆盖率进行测试时,没有关于schemaController
的覆盖率报告。我不知道是什么导致了这个问题。是配置问题还是模拟问题?
package edu.cmu.isri.mse.blackthunder.mapdesigner.roadelement;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import edu.cmu.isri.mse.blackthunder.mapdesigner.common.Validator;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
class SchemaControllerTest {
@InjectMocks
private SchemaController controller;
@Mock
private SchemaRepository repository;
@Mock
private Validator validator;
@Test
void createNewSchemaShouldSucceed() {
Schema schema = mock(Schema.class);
doNothing().when(validator).validateJsonSchema(schema);
when(schema.getId()).thenReturn("crosswalk-0.1.0");
when(repository.existsById("crosswalk-0.1.0")).thenReturn(false);
controller.createSchema(schema);
verify(repository, times(1)).save(schema);
}
@Test
void createExistingSchemaShouldThrowException() {
Schema schema = mock(Schema.class);
when(schema.getId()).thenReturn("crosswalk-0.1.0");
when(repository.existsById("crosswalk-0.1.0")).thenReturn(true);
assertThrows(SchemaAlreadyExistsException.class, () -> {
controller.createSchema(schema);
});
}
@Test
void createSchemaInvalidJsonShouldThrowException() {
Schema schema = mock(Schema.class);
doThrow(new SchemaFormatException("")).when(validator).validateJsonSchema(schema);
assertThrows(SchemaFormatException.class, () -> {
controller.createSchema(schema);
});
}
}