Код: Выделить всё
2023-05-03T08:10:06.508+01:00 INFO 57176 --- [ main] t.c.s.AnnotationConfigContextLoaderUtils : Could not detect default configuration classes for test class [com.schrodingdong.resourcemanager.controller.Tests]: Tests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
Test ignored.
Test ignored.
Test ignored.
Test ignored.
java.lang.NullPointerException: Cannot invoke "java.nio.file.attribute.BasicFileAttributes.lastModifiedTime()" because "this.attrs" is null
Код: Выделить всё
@RestController
@RequestMapping("/resource")
@CrossOrigin
public class ResourceController {
private final ResourceService resourceService;
public ResourceController(ResourceService resourceService) {
this.resourceService = resourceService;
}
@PostMapping("/upload")
public ResponseEntity uploadObject(@RequestParam ("file") MultipartFile multipartFile,
@RequestParam String userMail,
@RequestParam String resourceDescription,
@RequestParam String resourceVisibility) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
// ...
}
@GetMapping("/download")
public ResponseEntity downloadObject(@RequestParam String resourceId,
@RequestParam String userMail,
@RequestParam String downloadName) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
//...
}
@NotNull
private String getExtension(String fileName) {
// ...
}
@DeleteMapping("/delete")
public ResponseEntity deleteObject(@RequestParam String resourceId,
@RequestParam String userMail) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
// ...
}
}
Код: Выделить всё
@WebMvcTest(ResourceController.class)
public class ResourceControllerTests {
@Autowired
private MockMvc mockMvc;
@MockBean
private ResourceService mockResourceService;
private ObjectMapper objectMapper;
@BeforeEach
void setUp() {
objectMapper = new ObjectMapper();
}
@Test
void uploadObject() throws Exception {
// ...
}
@Test
void downloadObject() throws Exception {
// ...
}
@Test
void deleteObject() throws Exception {
// ...
}
}
ПРИМЕЧАНИЕ. У меня уже есть другой класс контроллера, который отлично тестируется автономно или с помощью команды mvn test, поэтому я действительно не знаю, в чем здесь проблема
Подробнее здесь: https://stackoverflow.com/questions/761 ... test-class