- 论坛徽章:
- 0
|
编译Test.java时的错误信息:
D:\java\com\bruceeckel\simpletest>javac Test.java
Test.java:64: cannot resolve symbol
symbol : variable OutputVerifier
location: class com.bruceeckel.simpletest.Test
OutputVerifier.verifyIgnoreOrder(output, exp);
^
Test.java:66: cannot resolve symbol
symbol : variable OutputVerifier
location: class com.bruceeckel.simpletest.Test
OutputVerifier.verifyAtLeast(output,
^
Test.java:69: cannot resolve symbol
symbol : variable OutputVerifier
location: class com.bruceeckel.simpletest.Test
OutputVerifier.verify(output, arrayToList(exp));
^
3 errors:
编译OutputVerifier.java时的错误提示:
D:\java\com\bruceeckel\simpletest>javac OutputVerifier.java
OutputVerifier.java:11: cannot resolve symbol
symbol : variable Test
location: class com.bruceeckel.simpletest.OutputVerifier
if((compare == Test.EXACT && expected != output)
^
OutputVerifier.java:12: cannot resolve symbol
symbol : variable Test
location: class com.bruceeckel.simpletest.OutputVerifier
|| (compare == Test.AT_LEAST && output < expected))
^
OutputVerifier.java:16: cannot resolve symbol
symbol : variable Test
location: class com.bruceeckel.simpletest.OutputVerifier
verifyLength(output.size(),expected.size(),Test.EXACT);
^
OutputVerifier.java:31: cannot resolve symbol
symbol : variable Test
location: class com.bruceeckel.simpletest.OutputVerifier
verifyLength(expected.length,output.size(),Test.EXACT);
^
OutputVerifier.java:53: cannot resolve symbol
symbol : variable Test
location: class com.bruceeckel.simpletest.OutputVerifier
Test.AT_LEAST);
^
5 errors
这两个原文件如下:
package com.bruceeckel.simpletest;
import java.util.*;
import java.io.PrintStream;
public class OutputVerifier {
private static void verifyLength(
int output, int expected, int compare) {
if((compare == Test.EXACT && expected != output)
|| (compare == Test.AT_LEAST && output < expected))
throw new NumOfLinesException(expected, output);
}
public static void verify(List output, List expected) {
verifyLength(output.size(),expected.size(),Test.EXACT);
if(!expected.equals(output)) {
//find the line of mismatch
ListIterator it1 = expected.listIterator();
ListIterator it2 = output.listIterator();
while(it1.hasNext()
&& it2.hasNext()
&& it1.next().equals(it2.next()));
throw new LineMismatchException(
it1.nextIndex(), it1.previous().toString(),
it2.previous().toString());
}
}
public static void
verifyIgnoreOrder(List output, Object[] expected) {
verifyLength(expected.length,output.size(),Test.EXACT);
if(!(expected instanceof String[]))
throw new RuntimeException(
"IGNORE_ORDER only works with String objects");
String[] out = new String[output.size()];
Iterator it = output.iterator();
for(int i = 0; i < out.length; i++)
out = it.next().toString();
Arrays.sort(out);
Arrays.sort(expected);
int i =0;
if(!Arrays.equals(expected, out)) {
while(expected.equals(out)) {i++;}
throw new SimpleTestException(
((String) out).compareTo(expected) < 0
? "output: <" + out + ">"
: "expected: <" + expected + ">");
}
}
public static void
verifyAtLeast(List output, List expected) {
verifyLength(output.size(), expected.size(),
Test.AT_LEAST);
if(!output.containsAll(expected)) {
ListIterator it = expected.listIterator();
while(output.contains(it.next())) {}
throw new SimpleTestException(
"expected: <" + it.previous().toString() + ">");
}
}
}
下面这个是Test.java的代码:
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class Test {
public static final int
EXACT = 1 << 0,
AT_LEAST = 1 << 1,
IGNORE_ORDER = 1 << 2,
WAIT = 1 << 3;
private String className;
private TestStream testStream;
public Test() {
className =
new Throwable().getStackTrace()[1].getClassName();
testStream = new TestStream(className);
}
public static List fileToList(String fname) {
ArrayList list = new ArrayList();
try {
BufferedReader in =
new BufferedReader(new FileReader(fname));
try {
String line;
while((line = in.readLine()) != null) {
if(fname.endsWith(".txt"))
list.add(line);
else
list.add(new TestExpression(line));
}
} finally {
in.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return list;
}
public static List arrayToList(Object[] array) {
List l = new ArrayList();
for(int i = 0; i < array.length; i++) {
if(array instanceof TestExpression) {
TestExpression re = (TestExpression)array;
for(int j = 0; j < re.getNumber(); j++)
l.add(re);
} else {
l.add(new TestExpression(array.toString()));
}
}
return l;
}
public void expect(Object[] exp, int flags) {
if((flags & WAIT) != 0)
while(testStream.numOfLines < exp.length) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
List output = fileToList(className + "Output.txt");
if((flags & IGNORE_ORDER) == IGNORE_ORDER)
OutputVerifier.verifyIgnoreOrder(output, exp);
else if((flags & AT_LEAST) == AT_LEAST)
OutputVerifier.verifyAtLeast(output,
arrayToList(exp));
else
OutputVerifier.verify(output, arrayToList(exp));
testStream.openOutputFile();
}
public void expect(Object[] expected) {
expect(expected, EXACT);
}
public void expect(Object[] expectFirst,
String fname, int flags) {
List expected = fileToList(fname);
for(int i = 0; i < expectFirst.length; i++)
expected.add(i, expectFirst);
expect(expected.toArray(), flags);
}
public void expect(Object[] expectFirst, String fname) {
expect(expectFirst, fname, EXACT);
}
public void expect(String fname) {
expect(new Object[] {}, fname, EXACT);
}
}
好了,其他的类都已经放在com/bruceeckel/simpleTest下面了.
帮我分析这个错误:不胜感激. |
|