Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java EasyMock测试SecurityException_Java_Unit Testing_Easymock_Securityexception - Fatal编程技术网

Java EasyMock测试SecurityException

Java EasyMock测试SecurityException,java,unit-testing,easymock,securityexception,Java,Unit Testing,Easymock,Securityexception,我试图使用easyMock编写一个测试,在下面的代码中测试SecurityException 对于NumberFormatException,我使用以下公式 expect(mockEntityManager.find(UserProfile.class,“abc”))和row(new) NumberFormatException()) 关于抛出SecurityException的内容有什么想法吗 公共对象getAsObject(FacesContext FacesContext,UICompon

我试图使用easyMock编写一个测试,在下面的代码中测试SecurityException

对于NumberFormatException,我使用以下公式

expect(mockEntityManager.find(UserProfile.class,“abc”))和row(new) NumberFormatException())

关于抛出SecurityException的内容有什么想法吗

公共对象getAsObject(FacesContext FacesContext,UIComponent uiComponent,字符串s){

EntityManager EntityManager=(EntityManager)组件.getInstance(“EntityManager”)


我觉得您还没有编写该代码,这就是为什么您想知道可能会抛出什么
SecurityException
。答案是什么都没有,只要您使用的是EntityManager的良好实现


EntityManager.find()的文档化版本不会抛出
SecurityException
但是如果您在使用EntityManager自定义版本的J2EE应用程序服务器中运行该代码,可能是它抛出了该异常……但我认为它不应该抛出该异常。

感谢您的回答。。下面是我对SecurityException的预期

MyClass abc = new MyClass();

EasyMock.expect(mockEntityManager.find(MyClass.class,111L)).andThrow(new SecurityException());

EasyMock.replay(mockEntityManager);

Object target = abc.getAsObject(mockFacesContext, mockUiComponent,"111");

Assert.assertEquals(null, target);

我不太明白。如果用新的SecurityException()替换新的NumberFormatException(),有什么不起作用?
MyClass abc = new MyClass();

EasyMock.expect(mockEntityManager.find(MyClass.class,111L)).andThrow(new SecurityException());

EasyMock.replay(mockEntityManager);

Object target = abc.getAsObject(mockFacesContext, mockUiComponent,"111");

Assert.assertEquals(null, target);