代码拉取完成,页面将自动刷新
package com.example.jpa;
import com.example.jpa.models.user.Student;
import com.example.jpa.repositories.user.StudentRepository;
import com.example.jpa.services.user.StudentService;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
import java.time.LocalDate;
import java.util.List;
/**
* Created with IntelliJ IDEA.
*
* @author : 魔芋红茶
* @version : 1.0
* @Project : jpa
* @Package : com.example.jpa
* @ClassName : .java
* @createTime : 2023/6/25 12:43
* @Email : icexmoon@qq.com
* @Website : https://icexmoon.cn
* @Description :
*/
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
@SpringJUnitWebConfig(classes = {JpaApplication.class})
@TestPropertySource("classpath:application.properties")
public class StudentServiceTests {
@Autowired
private StudentService studentService;
@Autowired
private StudentRepository studentRepository;
private List<Student> students = List.of(
new Student("icexmoon", LocalDate.of(1989, 10, 1), Gender.MALE),
new Student("JackChen", LocalDate.of(1990, 5, 1), Gender.MALE),
new Student("HanMeimei", LocalDate.of(1991, 6, 1), Gender.FEMALE));
@BeforeEach
void beforeEach() {
studentRepository.deleteAll();
for(var student: students){
studentRepository.save(student);
}
}
@Test
void testList() {
List<Student> students = studentService.list();
Assertions.assertEquals(this.students, students);
}
@AfterEach
void afterEach(){
studentRepository.deleteAll();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。