Results 1 to 4 of 4
- 03-27-2010, 05:34 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 57
- Rep Power
- 0
Stream Tokenizer Iterater Adapter not working
I have a Stream Tokenizer Iterater Adapter (STIA) class that has a test but it is not passing and was wondering if anyone can help me. I have posted this question on another forum but so far no one has helped. Here is the STIA class:
This class has a test which is:Java Code:public class StreamTokenizerIteratorAdapter implements Iterator<Token> { StreamTokenizer st; Iterator<Token> stia; public StreamTokenizerIteratorAdapter(final StreamTokenizer source) { if (source == null) throw new IllegalArgumentException("source == null"); st = source; Iterator<Token> stia = new StreamTokenizerIteratorAdapter(st); } @Override public boolean hasNext() { DefaultToken tempToken = new DefaultToken(st.sval, st.lineno()); int token = 0; while (token != StreamTokenizer.TT_EOF){ tempToken = new DefaultToken(st.sval, st.lineno()); } if (tempToken != null) return true; return false; } public Token next() { DefaultToken tempToken = new DefaultToken(st.sval, st.lineno());; return tempToken; } @Override public void remove() { throw new UnsupportedOperationException(); } }
The test is suppose to build a Tokenizer Iterater Index Builder with a STIA wrapped in a StreamTokenizer. So after running the test the two failures I get is this line on TokenIteratorIndexBuilder:Java Code:@Test public void testBuild() throws IOException { TokenIteratorIndexBuilder builder = new TokenIteratorIndexBuilder(index); st = new StreamTokenizer(new StringReader(s7)); int token; while ((token = st.nextToken()) != StreamTokenizer.TT_EOF) { if (token == StreamTokenizer.TT_WORD) { Token t = new DefaultToken(st.sval, st.lineno()); al.add(t); } } builder.buildFrom(al.iterator()); assertEquals(s7index, index); }
and the other line is on TestSTIA:Java Code:throw new IllegalArgumentException("index == null");
Sorry for all the code I just would like to explain the issue because there are a few different classes, if anyone can help I would be much appreciated.Java Code:TokenIteratorIndexBuilder builder = new TokenIteratorIndexBuilder(index);
- 03-27-2010, 05:52 PM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
It's not at all clear to me what you're trying to do (and I suspect it's not entirely clear to you either), but the immediate error seems pretty simple.
Where did "index" come from? It wasn't passed in to your method as a parameter, and it wasn't declared within the method. It could be an ivar in your class, but this looks like JUnit code, and I think it's unusual to have ivars in JUnit classes.Java Code:@Test public void testBuild() throws IOException { TokenIteratorIndexBuilder builder = new TokenIteratorIndexBuilder(index); ...
-Gary-
- 03-27-2010, 08:16 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 57
- Rep Power
- 0
The STIA test is suppose to create a TIIB, then build the index from a STIA wrapped around a StreamTokenizer,
I have another test for Stream Tokenizer Iterator Builder (STIB) and creating a index works fine for the test, here is the code for that test:
Any help to develop the test for STIA would be much appreciated.Java Code:@Test public void testBuild() { Index index = new DefaultIndexImpl(); StreamTokenizerIndexBuilder builder = new StreamTokenizerIndexBuilder(index); builder.buildFrom(new StreamTokenizer(new StringReader(s7))); assertEquals(s7index, index); }
- 03-27-2010, 08:23 PM #4
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Well, I don't know your code, but it looks to me that the red line in this test:
is missing from this test:Java Code:@Test public void testBuild() { [COLOR="Red"]Index index = new DefaultIndexImpl();[/COLOR] StreamTokenizerIndexBuilder builder = new StreamTokenizerIndexBuilder(index); builder.buildFrom(new StreamTokenizer(new StringReader(s7))); assertEquals(s7index, index); }
-Gary-Java Code:@Test public void testBuild() throws IOException { TokenIteratorIndexBuilder builder = new TokenIteratorIndexBuilder(index); st = new StreamTokenizer(new StringReader(s7)); int token; while ((token = st.nextToken()) != StreamTokenizer.TT_EOF) { if (token == StreamTokenizer.TT_WORD) { Token t = new DefaultToken(st.sval, st.lineno()); al.add(t); } } builder.buildFrom(al.iterator()); assertEquals(s7index, index); }
Similar Threads
-
How to make adapter class between FileConnection and StorageConnection?
By mikezang in forum CLDC and MIDPReplies: 5Last Post: 08-07-2009, 12:54 PM -
JDBC using adapter (and connection handles)
By Gideonzx in forum Advanced JavaReplies: 1Last Post: 07-28-2009, 06:54 AM -
Trouble implementng an Adapter/Strategy (GoF) design pattern
By Algatron in forum Advanced JavaReplies: 2Last Post: 03-24-2009, 05:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks