fix bugs in refactoring of r1326562, CharFilter does not wrap all methods

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1326564 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-04-16 11:43:36 +00:00
parent cf9eb6de97
commit 9c8397dae2
2 changed files with 185 additions and 6 deletions

View File

@ -1,9 +1,12 @@
package org.apache.lucene.analysis.core;
import java.io.IOException;
import java.io.Reader;
import java.nio.CharBuffer;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.analysis.CharStream;
import org.apache.lucene.analysis.MockCharFilter;
import org.apache.lucene.analysis.MockTokenFilter;
import org.apache.lucene.analysis.MockTokenizer;
@ -61,4 +64,135 @@ public class TestBugInSomething extends BaseTokenStreamTestCase {
};
checkAnalysisConsistency(random(), a, false, "wmgddzunizdomqyj");
}
CharStream wrappedStream = new CharStream() {
@Override
public void mark(int readAheadLimit) throws IOException {
throw new UnsupportedOperationException("mark(int)");
}
@Override
public boolean markSupported() {
throw new UnsupportedOperationException("markSupported()");
}
@Override
public int read() throws IOException {
throw new UnsupportedOperationException("read()");
}
@Override
public int read(char[] cbuf) throws IOException {
throw new UnsupportedOperationException("read(char[])");
}
@Override
public int read(CharBuffer target) throws IOException {
throw new UnsupportedOperationException("read(CharBuffer)");
}
@Override
public boolean ready() throws IOException {
throw new UnsupportedOperationException("ready()");
}
@Override
public void reset() throws IOException {
throw new UnsupportedOperationException("reset()");
}
@Override
public long skip(long n) throws IOException {
throw new UnsupportedOperationException("skip(long)");
}
@Override
public int correctOffset(int currentOff) {
throw new UnsupportedOperationException("correctOffset(int)");
}
@Override
public void close() throws IOException {
throw new UnsupportedOperationException("close()");
}
@Override
public int read(char[] arg0, int arg1, int arg2) throws IOException {
throw new UnsupportedOperationException("read(char[], int, int)");
}
};
public void testWrapping() throws Exception {
CharStream cs = new TestRandomChains.CheckThatYouDidntReadAnythingReaderWrapper(wrappedStream);
try {
cs.mark(1);
fail();
} catch (Exception e) {
assertEquals("mark(int)", e.getMessage());
}
try {
cs.markSupported();
fail();
} catch (Exception e) {
assertEquals("markSupported()", e.getMessage());
}
try {
cs.read();
fail();
} catch (Exception e) {
assertEquals("read()", e.getMessage());
}
try {
cs.read(new char[0]);
fail();
} catch (Exception e) {
assertEquals("read(char[])", e.getMessage());
}
try {
cs.read(CharBuffer.wrap(new char[0]));
fail();
} catch (Exception e) {
assertEquals("read(CharBuffer)", e.getMessage());
}
try {
cs.reset();
fail();
} catch (Exception e) {
assertEquals("reset()", e.getMessage());
}
try {
cs.skip(1);
fail();
} catch (Exception e) {
assertEquals("skip(long)", e.getMessage());
}
try {
cs.correctOffset(1);
fail();
} catch (Exception e) {
assertEquals("correctOffset(int)", e.getMessage());
}
try {
cs.close();
fail();
} catch (Exception e) {
assertEquals("close()", e.getMessage());
}
try {
cs.read(new char[0], 0, 0);
fail();
} catch (Exception e) {
assertEquals("read(char[], int, int)", e.getMessage());
}
}
}

View File

@ -756,29 +756,74 @@ public class TestRandomChains extends BaseTokenStreamTestCase {
}
}
static final class CheckThatYouDidntReadAnythingReaderWrapper extends CharFilter {
boolean readSomething = false;
// wants charfilter to be a filterreader...
// do *NOT*, do *NOT* refactor me to be a charfilter: LUCENE-3990
static class CheckThatYouDidntReadAnythingReaderWrapper extends CharStream {
boolean readSomething;
CharStream in;
CheckThatYouDidntReadAnythingReaderWrapper(Reader in) {
super(CharReader.get(in));
this.in = CharReader.get(in);
}
@Override
public int correctOffset(int currentOff) {
return in.correctOffset(currentOff);
}
@Override
public void close() throws IOException {
in.close();
}
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
readSomething = true;
return input.read(cbuf, off, len);
return in.read(cbuf, off, len);
}
@Override
public int read() throws IOException {
readSomething = true;
return input.read();
return in.read();
}
@Override
public int read(CharBuffer target) throws IOException {
readSomething = true;
return in.read(target);
}
@Override
public void mark(int readAheadLimit) throws IOException {
in.mark(readAheadLimit);
}
@Override
public boolean markSupported() {
return in.markSupported();
}
@Override
public int read(char[] cbuf) throws IOException {
readSomething = true;
return in.read(cbuf);
}
@Override
public boolean ready() throws IOException {
return in.ready();
}
@Override
public void reset() throws IOException {
in.reset();
}
@Override
public long skip(long n) throws IOException {
readSomething = true;
return input.skip(n);
return in.skip(n);
}
}