Java 无法将列表对象转换为列表<;clasname>;

Java 无法将列表对象转换为列表<;clasname>;,java,api,Java,Api,无法从列表转换为列表 当尝试在测试方法中使用列表时,将列表添加到ArrayList时出错。 这是错误所在的代码: @Test public void testGetAllModules_OK() throws Exception { List<Modules> modules = Arrays.asList(new Modules(1, "C02103", "Architecture", 1, true)); when(modRepo.findAll()).thenRetur

无法从列表转换为列表 当尝试在测试方法中使用列表时,将列表添加到ArrayList时出错。 这是错误所在的代码:

    @Test
public void testGetAllModules_OK() throws Exception {
List<Modules> modules = Arrays.asList(new Modules(1, "C02103", "Architecture", 1, true));
when(modRepo.findAll()).thenReturn(modules);
mockMvc.perform(get("/Modules"))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].ModuleCode", is ("C02103")))
.andExpect(jsonPath("$[0].title", is ("Architecture")))
.andExpect(jsonPath("$.[0].semester", is (1)))
.andExpect(jsonPath("$[0].CoreModule", is(true)));

verify(modRepo, times(1)).findAll();
}
@测试
public void testGetAllModules_OK()引发异常{
列表模块=Arrays.asList(新模块(1,“C02103”,“架构”,1,true));
when(modRepo.findAll())。然后返回(模块);
mockMvc.perform(get(“/Modules”))
.andExpect(状态().isOk())
.andExpect(jsonPath(“$[0].ModuleCode”,是(“C02103”))
.andExpect(jsonPath(“$[0].title”)是(“体系结构”))
.andExpect(jsonPath(“$[0].Serm”,是(1)))
.andExpect(jsonPath(“$[0].CoreModule”),为(true));
验证(modRepo,times(1)).findAll();
}
下面是模块类的创建

@Entity
public class Modules implements Iterable<Modules> {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int ModuleId;
private String ModuleCode;
private String title;
private int semester;
private boolean CoreModule;
ArrayList<String> lecture = new ArrayList<String>();
ArrayList<String> mod = new ArrayList<String>();

public Modules(int ModuleId, String ModuleCode, String title, int semester, boolean CoreModule) {
    this.ModuleId = ModuleId;
    this.ModuleCode = ModuleCode;
    this.title = title;
    this.semester = semester;
    this.CoreModule = CoreModule;
}
public Modules(String ModuleCode, String title, int semester, boolean CoreModule)
{
    this.ModuleCode = ModuleCode;
    this.title = title;
    this.semester = semester;
    this.CoreModule = CoreModule;
}
public Modules(String ModuleCode,String title, boolean CoreModule )
{
    this.ModuleCode = ModuleCode;
    this.title = title;
    this.CoreModule = CoreModule;
}
public Modules()
{}

/*
 * @ManyToOne(fetch = FetchType.EAGER, optional = false)
 * 
 * @OneToMany(mappedBy = "module", fetch = FetchType.EAGER, cascade =
 * CascadeType.ALL)
 */
public int getModuleId() {
    return ModuleId;
}
public void setModuleId(int moduleId) {
    ModuleId = moduleId;
}
public String getModuleCode() {
    return ModuleCode;
}
public void setModuleCode(String moduleCode) {
    ModuleCode = moduleCode;
}
public String getTitle() {
    return title;
}
public void setTitle(String title) {
    this.title = title;
}
public int getSemester() {
    return semester;
}
public void setSemester(int semester) {
    this.semester = semester;
}
public boolean isCoreModule() {
    return CoreModule;
}
public void setCoreModule(boolean coreModule) {
    CoreModule = coreModule;
}

@Override
public String toString() {
    return "Modules [ModuleId=" + ModuleId + ", ModuleCode=" + ModuleCode + ", title=" + title + ", semester="
            + semester + ", CoreModule=" + CoreModule + "]";
}
@实体
公共类模块实现了Iterable{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
私有int模块id;
私有字符串模块代码;
私有字符串标题;
私人学期;
私有布尔核模块;
ArrayList讲座=新建ArrayList();
ArrayList mod=新的ArrayList();
公共模块(整数模块ID、字符串模块代码、字符串标题、整数学期、布尔核心模块){
this.ModuleId=ModuleId;
this.ModuleCode=ModuleCode;
this.title=标题;
本学期=学期;
this.CoreModule=CoreModule;
}
公共模块(字符串模块代码、字符串标题、整数学期、布尔核心模块)
{
this.ModuleCode=ModuleCode;
this.title=标题;
本学期=学期;
this.CoreModule=CoreModule;
}
公共模块(字符串模块代码、字符串标题、布尔核心模块)
{
this.ModuleCode=ModuleCode;
this.title=标题;
this.CoreModule=CoreModule;
}
公共模块()
{}
/*
*@ManyToOne(fetch=FetchType.EAGER,可选=false)
* 
*@OneToMany(mappedBy=“module”,fetch=FetchType.EAGER,cascade=
*级联型(全部)
*/
public int getModuleId(){
返回模块ID;
}
公共void setModuleId(int moduleId){
ModuleId=ModuleId;
}
公共字符串getModuleCode(){
返回模块代码;
}
公共void setModuleCode(字符串moduleCode){
ModuleCode=ModuleCode;
}
公共字符串getTitle(){
返回标题;
}
公共无效集合标题(字符串标题){
this.title=标题;
}
公共学期{
返回学期;
}
公共教育学院(国际学期){
本学期=学期;
}
公共布尔值isCoreModule(){
返回模块;
}
公共void setCoreModule(布尔coreModule){
CoreModule=CoreModule;
}
@凌驾
公共字符串toString(){
返回“模块[ModuleId=“+ModuleId+”,模块代码=“+ModuleCode+”,标题=“+title+”,学期=”
+学期+”,CoreModule=“+CoreModule+”];
}
}
任何帮助都将不胜感激,因为我在类似的测试方法中遇到了相同的错误

请编辑您的问题,给出准确的编译错误消息,并准确说出它发生在哪一行。(你说:“我在向ArrayList添加列表时出错…”但据我所知,该代码没有添加任何内容。)请编辑你的问题,给出准确的编译错误消息,并准确说出它发生在哪一行。(您说:“我在向ArrayList添加列表时出错……”但据我所知,该代码没有向任何内容添加任何内容。)