You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2012/04/16 13:43:36 UTC
svn commit: r1326564 - in
/lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core:
TestBugInSomething.java TestRandomChains.java
Author: rmuir
Date: Mon Apr 16 11:43:36 2012
New Revision: 1326564
URL: http://svn.apache.org/viewvc?rev=1326564&view=rev
Log:
fix bugs in refactoring of r1326562, CharFilter does not wrap all methods
Modified:
lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java
lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java
Modified: lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java?rev=1326564&r1=1326563&r2=1326564&view=diff
==============================================================================
--- lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java (original)
+++ lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java Mon Apr 16 11:43:36 2012
@@ -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
};
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());
+ }
+ }
}
Modified: lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java?rev=1326564&r1=1326563&r2=1326564&view=diff
==============================================================================
--- lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java (original)
+++ lucene/dev/trunk/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java Mon Apr 16 11:43:36 2012
@@ -756,29 +756,74 @@ public class TestRandomChains extends Ba
}
}
- 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);
}
}