小编sta*_*r44的帖子

如何为CDI编写Junit测试用例?

我想为cdi编写测试用例.我在我的dao中使用了@inject.任何人都可以帮我如何为cdi编写测试用例.我尝试了下面的代码.但它不起作用.请帮我.

public class StudentTest {

    StudentService stuService;

    StudentDAO stuDAO;

    StudentVO stuVo;

    @Before
    public void setUp() throws Exception {

        System.out.println("In Setup");

        stuVo=new StudentVO ();

        stuService=new StudentService();

        stuDAO=Mockito.mock(StudentDAO.class);

        stuVo.setStudId("123");

        stuVo.setName("user1");

        Mockito.when(stuDAO.getStudent(stuVo.getStuId())).thenReturn(student);
    }

    @Test
    public void getStudent() throws DataAccessException {

        StudentVO stVO=stuService.getStudent(123);

        Assert.assertEquals("123", stVO.getStuId());
    }
}
Run Code Online (Sandbox Code Playgroud)

我的服务类是

public class StudentService {

    @Inject
    StudentDAO stuDao;

    public StudentVo getStudent(String id){

        return stuDao.getStudent(id);

    }

}
Run Code Online (Sandbox Code Playgroud)

在失败时跟踪它只是显示为"java.lang.NullPointerException

 at com.stu.StudentService.getStudent(StudentService.java:104)
 at com.stu.junit.POCJunit.getgetStudent(StudentTest.java:21)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
 at …
Run Code Online (Sandbox Code Playgroud)

java junit junit4 cdi

3
推荐指数
1
解决办法
4290
查看次数

angular2 typescript数组的对象按值过滤

我有一个数组从JSON文件获取数据.我能够将一系列对象存储到我的Task[].现在我想按状态检索数据('已提交'或'已解决'等).我尝试了很多方法,但无法实现.请帮我.

data: [{
  taskname: 'Test1',
  taskId: '1',
  status: 'Submitted'
}, {
  taskname: 'Test2',
  taskId: '2',
  status: 'Resolved'
}, {
  taskname: 'Test3',
  taskId: '4',
  status: 'Submitted'
}, {
  taskname: 'Test4',
  taskId: '5',
  status: 'In Progress'
}, {
  taskname: 'Test5',
  taskId: '6',
  status: 'Resolved'
}, {
  taskname: 'Test6',
  taskId: '7',
  status: 'Submitted'
}
}]
Run Code Online (Sandbox Code Playgroud)

Task.ts

export interface Task {
  taskId: any;
  taskname: any;
  status: any;
}
Run Code Online (Sandbox Code Playgroud)

taskService.ts

getTask() {
  return this.http.get('../app/common/task.json')
    .toPromise()
    .then(res => < Task[] > res.json().data)
    .then(data => …
Run Code Online (Sandbox Code Playgroud)

json typescript angular

3
推荐指数
1
解决办法
1万
查看次数

搜索多选下拉角4和材料2

嗨,我使用的是角4和材质2。我在下拉菜单中选择了多个选项。我可以显示带有多选选项的下拉菜单。现在,我想在选择下拉列表中实现搜索/过滤器选项。您能否让我知道,在material2中有什么方法可以实现这一点,还是我需要实现自己的可搜索组件?是否有<mat-select-header>之类的东西?

angular-material2 angular

2
推荐指数
1
解决办法
9451
查看次数

标签 统计

angular ×2

angular-material2 ×1

cdi ×1

java ×1

json ×1

junit ×1

junit4 ×1

typescript ×1