我有一个非常简单的测试用例,它使用的是Mockito和Spring Test框架.当我做
when(pcUserService.read("1")).thenReturn(pcUser);
Run Code Online (Sandbox Code Playgroud)
我得到了这个例外.
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);
Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
2. inside when() you don't call method on mock but on some other object.
at com.project.cleaner.controller.test.PcUserControllerTest.shouldGetPcUser(PcUserControllerTest.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
Run Code Online (Sandbox Code Playgroud)
我尝试过不同的方法,但继续收到此错误消息.我正在使用Spring 3.1.0.RELEASE和Mockito.请分享并指导我正确的方向.
在我的应用程序中,我使用hibernate,连接数据库并创建会话.这是我的hibernate.cfg.xml文件.还行吧.它运作正常.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/country</property>
<property name="connection.username">root</property>
<property name="connection.password">password</property>
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
但是当我尝试db.property file
使用hibernate.cfg.xml
它来读取数据库配置属性时,它显示了Exception,这是我的另一个hibernate.cfg.xml
文件
<util:properties id="db" location="classpath:db.properties" />
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="driverClassName" value="#{db['driverClassName']}"></property>
<property name="url" value="#{db['url']}"></property>
<property name="username" value="#{db['username']}"></property>
<property name="password" value="#{db['password']}"></property>
</session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)
这是错误
org.dom4j.DocumentException: Error on line 8 of document : The prefix "util" for element "util:properties" is not bound. …
Run Code Online (Sandbox Code Playgroud) 当用户单击某个链接时,使用Web服务将文档从远程ECM系统传输到用户计算机.
所以我创建了servlet并从Query字符串中获取了URL中的参数.
根据参数属性,调用了几个与Web服务相关的方法来获取文件详细信息和文件内容.现在调用servlet和用户系统之间的文件传输.
最大的担忧是,由于以下例外,代码片段工作正常.用户可以将文档保存在所需位置.我试图弄清楚为什么我会收到这个错误.
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:611)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
t DownloadServlet.doGet(DownloadServlet.java:99)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Run Code Online (Sandbox Code Playgroud)
getDocument(HttpServletRequest request,HttpServletResponse response)
{
\\used Custom web services methods to get filename with extensions from external ECM system
File resultFile = content.getAsFile();
response.setContentType("application/octet-stream");
ServletOutputStream outStream = response.getOutputStream();
try {
response.setHeader("Content-Disposition", …
Run Code Online (Sandbox Code Playgroud) 目前我正在学习hibernate.我正在尝试在eclipse中创建一个关于hibernate的项目.在hibernate.cfg.xml中,它显示警告.."stream not available"
hibernate.cfg.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="studentFactory">
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/nithya</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.pool_size">5</property>
<property name="dialect">org.hibernate.dialect.mysqlDialect</property>
<property name="show_sql">false</property>
<property name="hbm2ddl.auto">update</property>
<mapping resource="\com\\xmls\\Student.hbm.xml" />
</session-factory>
Run Code Online (Sandbox Code Playgroud)
警告线是......" http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd ">
任何人帮助我克服它,并建议学习和创建hibernate项目的最佳方法..提前感谢..