Carsten Ziegeler schrieb:
> Felix Knecht wrote:
>> Hi all
>>
>> I have found at different locations [1] an implementation (more or less 
>> similar) for an EmptyIterator, e.g.
>>
>> static class EmptyIterator implements Iterator {
>>     public boolean hasNext() { return false; }
>>     public Object next() { return null; }
>>     public void remove() {}
>> }
>>
>> Many of them are lacking the same problem:
>> Iterator next() [2] method says to throws an exception when there are no 
>> more elements to return (what would be the case
>> here). In fact null is returned instead of an error.
>>
>> Is this done this way on purpose?
> No, it's a mistake - I never read the java docs correctly :(
> So it should throw an exception.

Trying to fix it I run into following testcase failure:

-------------------------------------------------------------------------------
Test set: org.apache.cocoon.template.jxtg.JXTemplateGeneratorTestCase
-------------------------------------------------------------------------------
Tests run: 18, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 4.133 sec <<< 
FAILURE!
testJXForEach(org.apache.cocoon.template.jxtg.JXTemplateGeneratorTestCase)  
Time elapsed: 0.174 sec  <<< FAILURE!
junit.framework.AssertionFailedError: Test if the assertion document is equal, 
org.custommonkey.xmlunit.Diff
[different] Expected presence of child nodes to be 'true' but was 'false' - 
comparing <loop...> to <loop...>
 expected:<true> but was:<false>
        at junit.framework.Assert.fail(Assert.java:47)
        at junit.framework.Assert.failNotEquals(Assert.java:280)
        at junit.framework.Assert.assertEquals(Assert.java:64)
        at junit.framework.Assert.assertEquals(Assert.java:146)
        at 
org.apache.cocoon.SitemapComponentTestCase.assertEqual(SitemapComponentTestCase.java:726)
        ....

The problem is, that I'm not really sure if the testcase is testing the way it 
should. - and this is what I'd like to
discuss.

(before JXTransformation)
<root xmlns:jx="http://apache.org/cocoon/templates/jx/1.0";>
  <snip />

  <loop>
    <jx:forEach varStatus="status" begin="1" end="5">
      <forEach>${status.index}</forEach>
    </jx:forEach>
  </loop>
</root>

should produce (so the testcase) (,after JXTransformation)
<root>
  <snip />

  <loop>
      <forEach>1</forEach>
      <forEach>2</forEach>
      <forEach>3</forEach>
      <forEach>4</forEach>
      <forEach>5</forEach>
  </loop>
</root>

Now my question:

Documentation for 2.2. is still not complete, so the link to 2.1 [1]
"The forEach tag allows you to iterate over a collection of objects, ..."

In the 'before' I'm completely missing a collection thus a result should IMO 
rather look like
<root>
  <snip />
</root>


WDYT?

Felix


[1] http://cocoon.apache.org/2.1/userdocs/flow/jxtemplate.html [forEach]

Reply via email to