[dna-commits] DNA SVN: r1255 - in trunk/dna-common/src: test/java/org/jboss/dna/common/text and 1 other directory.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Sep 23 14:56:58 EDT 2009


Author: rhauch
Date: 2009-09-23 14:56:58 -0400 (Wed, 23 Sep 2009)
New Revision: 1255

Modified:
   trunk/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java
   trunk/dna-common/src/test/java/org/jboss/dna/common/text/TokenStreamTest.java
Log:
Changed the JavaDoc and the behavior of the TokenStream.hasNext() method to reflect how it is actually used.

Modified: trunk/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java
===================================================================
--- trunk/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java	2009-09-23 18:56:31 UTC (rev 1254)
+++ trunk/dna-common/src/main/java/org/jboss/dna/common/text/TokenStream.java	2009-09-23 18:56:58 UTC (rev 1255)
@@ -1167,16 +1167,16 @@
     }
 
     /**
-     * Determine if this stream has another token beyond the current position.
+     * Determine if this stream has another token to be consumed.
      * 
-     * @return true if there is another token, or false otherwise
+     * @return true if there is another token ready for consumption, or false otherwise
      * @throws IllegalStateException if this method was called before the stream was {@link #start() started}
      */
     public boolean hasNext() {
         if (tokenIterator == null) {
             throw new IllegalStateException(CommonI18n.startMethodMustBeCalledBeforeNext.text());
         }
-        return tokenIterator.hasNext();
+        return !completed;
     }
 
     /**

Modified: trunk/dna-common/src/test/java/org/jboss/dna/common/text/TokenStreamTest.java
===================================================================
--- trunk/dna-common/src/test/java/org/jboss/dna/common/text/TokenStreamTest.java	2009-09-23 18:56:31 UTC (rev 1254)
+++ trunk/dna-common/src/test/java/org/jboss/dna/common/text/TokenStreamTest.java	2009-09-23 18:56:58 UTC (rev 1255)
@@ -23,11 +23,9 @@
  */
 package org.jboss.dna.common.text;
 
-import java.util.Arrays;
-
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertThat;
-
+import java.util.Arrays;
 import org.jboss.dna.common.text.TokenStream.BasicTokenizer;
 import org.jboss.dna.common.text.TokenStream.Tokenizer;
 import org.junit.Before;
@@ -90,6 +88,14 @@
     }
 
     @Test
+    public void shouldReturnTrueFromHasNextIfThereIsACurrentToken() {
+        content = "word";
+        makeCaseSensitive();
+        assertThat(tokens.currentToken().matches("word"), is(true));
+        assertThat(tokens.hasNext(), is(true));
+    }
+
+    @Test
     public void shouldConsumeInCaseSensitiveMannerWithExpectedValuesWhenMatchingExactCase() {
         makeCaseSensitive();
         tokens.consume("Select");
@@ -358,7 +364,7 @@
         assertThat(tokens.canConsume("SELECT", "ALL", "COLUMNS", "FROM", TokenStream.ANY_VALUE, "TABLE"), is(true));
         assertThat(tokens.hasNext(), is(false));
     }
-    
+
     @Test
     public void shouldCanConsumeSingleAfterTokensCompleteFromCanConsumeStringList() {
         makeCaseInsensitive();
@@ -369,7 +375,7 @@
         assertThat(tokens.canConsume(TokenStream.ANY_VALUE), is(false));
         assertThat(tokens.canConsume(BasicTokenizer.SYMBOL), is(false));
     }
-    
+
     @Test
     public void shouldCanConsumeStringAfterTokensCompleteFromCanConsumeStringArray() {
         makeCaseInsensitive();
@@ -380,10 +386,10 @@
         assertThat(tokens.canConsume(TokenStream.ANY_VALUE), is(false));
         assertThat(tokens.canConsume(BasicTokenizer.SYMBOL), is(false));
     }
-    
+
     @Test
     public void shouldCanConsumeStringAfterTokensCompleteFromCanConsumeStringIterator() {
-        makeCaseInsensitive();       
+        makeCaseInsensitive();
         // consume ALL the tokens using canConsume()
         tokens.canConsume(Arrays.asList(new String[] {"SELECT", "ALL", "COLUMNS", "FROM", "THIS", "TABLE"}));
         // try to canConsume() single word



More information about the dna-commits mailing list