我有一个DBHandler接受查询的类,通过SQL服务器运行它,检查错误并返回结果.我怎样才能对这门课进行单元测试?
编辑:我会尝试更精确:
DBHandler负责将查询传递给服务器.为了测试它实际上是这样,抛出正确的异常等,我想将它连接到我将填充的模拟数据库.我的问题是 - 怎么做?如何创建处理调用的模拟"服务器"?
我在Java中动态创建类并尝试在其中调用方法,但是,有时候我会得到一个java.lang.reflect.InvocationTargetException.
PageGenerator1.java(动态创建)
import java.io.PrintStream;
import java.util.Map;
public class PageGenerator1 implements DynamicPageGenerator {
public PageGenerator1() {
}
@Override
public void generate(PrintStream out, Map<String,String> params, Session session) {
out.print("<html>\r\n<body>\r\n");
if (session.get("counter") == null) {
session.set("counter", 2);
out.println("<h1>Hi "+params.get("name")+" this is your first visit</h1>");
} else {
out.println("<h1>This is your "+session.get("counter")+" visit</h1>");
session.set("counter", 1+((Integer)session.get("counter")));
}
out.print("\r\n</body>\r\n</html>");
}
}
Run Code Online (Sandbox Code Playgroud)
我试图像这样调用它:
logger.info(
"Attempting to invoke the method " + generateMethod + " with an instance of " + generatedClassName + "with the following …Run Code Online (Sandbox Code Playgroud) 我想了解如何在Java中对静态方法进行锁定.
假设我有以下课程:
class Foo {
private static int bar = 0;
public static synchronized void inc() { bar++; }
public synchronized int get() { return bar; }
Run Code Online (Sandbox Code Playgroud)
我的理解是,当我调用时f.get(),线程获取对象的锁定f,当我执行时Foo.inc(),线程获取类的锁定Foo.
我的问题是两个呼叫如何相互同步?调用静态方法也会获取所有实例化的锁定,或者相反(这似乎更合理)?
编辑:
我的问题并不完全是如何static synchronized工作的,但静态和非静态方法是如何相互同步的.也就是说,我不希望两个线程同时调用这两个f.get()和Foo.inc(),但这些方法获得不同的锁.我的问题是这是如何可以预防的,并且在上面的代码中是否被阻止了.
我收到以下错误:
06/08/2011 02:56:33 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet UploadTheme threw exception
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
at org.apache.commons.fileupload.servlet.ServletRequestContext.getContentType(ServletRequestContext.java:73)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:905)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
at cs236369.hw5.servlets.xml.UploadTheme.doPost(UploadTheme.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
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:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
我放置JARS WEB-INF/lib.这是项目类路径的样子:

这是运行配置:
添加FileUpload后麻烦开始了.
知道什么是错的吗?
是否有可能在LyX中创建Zed Notation方案?怎么做到呢?
如何在Vim中启用自动完成功能?
我试着这样做,但我不熟悉vimrc文件等,所以它没有用.你能给我一步一步说明如何做到这一点吗?
编辑
我尝试安装OmniCppComplete.按照说明操作,但是当我尝试使用它时,我收到以下错误:
处理函数omni时检测到错误#cpp #complete#Main..24_InitComplete:
第24行:
E10:\应该跟/,?要么 &
目前我正在创建一个这样的新集:
std::set<A> s;
s.insert(a1);
s.insert(a2);
s.insert(a3);
...
s.insert(a10);
Run Code Online (Sandbox Code Playgroud)
有没有办法s在一行中创建?
我正在大学里做一个项目,它包括一个MySQL数据库.我根据表列表及其各自的字段设计了数据库.
我应该以什么形式展示这种设计?只是表格和内容列表?在ERD?你如何展示你的设计?
为了澄清 - 无论你回答什么,我不仅要指出你如何呈现你的设计,还要使用哪些工具创建图表/列表/表等.
我已经使用Java一段时间了,但我从未创建过GUI - 总是CLI.如何在Java中创建GUI?你能建议一个好的教程/参考吗?
我正在寻找一个简单的GUI,它有两个长文本区域和一些按钮.
正如我在上一个问题中描述的那样,我有一个编写代理服务器的任务.它现在部分工作,但我仍然有处理gzip信息的问题.我将HttpResponse存储在一个字符串中,看起来我不能用gzip压缩内容.但是,标题是我需要解析的文本,它们都来自同一个文本InputStream.我的问题是,为了正确处理二进制响应,我还需要做什么,同时仍然将头解析为字符串?
>>在查看代码之前,请参阅下面的编辑.
这是Response类实现:
public class Response {
private String fullResponse = "";
private BufferedReader reader;
private boolean busy = true;
private int responseCode;
private CacheControl cacheControl;
public Response(String input) {
this(new ByteArrayInputStream(input.getBytes()));
}
public Response(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
try {
while (!reader.ready());//wait for initialization.
String line;
while ((line = reader.readLine()) != null) {
fullResponse += "\r\n" + line;
if (HttpPatterns.RESPONSE_CODE.matches(line)) {
responseCode = (Integer) HttpPatterns.RESPONSE_CODE.process(line);
} else if …Run Code Online (Sandbox Code Playgroud) java ×6
c++ ×2
database ×2
encoding ×1
erd ×1
http ×1
httpresponse ×1
jar ×1
junit ×1
latex ×1
lyx ×1
reflection ×1
servlets ×1
set ×1
sql ×1
stl ×1
synchronized ×1
unit-testing ×1
unix ×1
vim ×1
z-notation ×1