use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.
the class MarkupContainerTest method singleChildShouldAllowReplacingVisitedChildButNotRevisitReplacementChild.
@Test
public void singleChildShouldAllowReplacingVisitedChildButNotRevisitReplacementChild() {
WebMarkupContainer wmc = new WebMarkupContainer("id");
Label label1 = new Label("label1", "Label1");
Label label2 = new Label("label1", "Label2");
wmc.add(label1);
Iterator<Component> iterator = wmc.iterator();
Assert.assertThat(iterator.hasNext(), is(true));
Assert.assertThat(iterator.next(), is(equalToObject(label1)));
wmc.replace(label2);
Assert.assertThat(iterator.hasNext(), is(false));
}
use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.
the class MarkupContainerTest method iteratorShouldAllowRemovingComponentAfterIterationStarted2.
@Test
public void iteratorShouldAllowRemovingComponentAfterIterationStarted2() {
WebMarkupContainer wmc = new WebMarkupContainer("id");
Label label1;
Label label2;
Label label3;
wmc.add(label1 = new Label("label1", "Label1"));
wmc.add(label2 = new Label("label2", "Label2"));
wmc.add(label3 = new Label("label3", "Label3"));
Iterator<Component> iterator = wmc.iterator();
Assert.assertThat(iterator.next(), is(equalToObject(label1)));
Assert.assertThat(iterator.next(), is(equalToObject(label2)));
wmc.remove(label1);
Assert.assertThat(iterator.next(), is(equalToObject(label3)));
Assert.assertThat(iterator.hasNext(), is(false));
}
use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.
the class MarkupContainerTest method noChildAddingAndRemoveChildAfterIteratorAcquiredShouldNotIterate.
@Test
public void noChildAddingAndRemoveChildAfterIteratorAcquiredShouldNotIterate() {
WebMarkupContainer wmc = new WebMarkupContainer("id");
Label label1 = new Label("label1", "Label1");
Iterator<Component> iterator = wmc.iterator();
wmc.add(label1);
wmc.remove(label1);
assertThat(wmc.size(), is(0));
Assert.assertThat(iterator.hasNext(), is(false));
}
use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.
the class MarkupContainerTest method replacingTheFirstChildAfterIteratingDoesntIterateTheNewChild.
@Test
public void replacingTheFirstChildAfterIteratingDoesntIterateTheNewChild() {
WebMarkupContainer wmc = new WebMarkupContainer("id");
Label label1 = new Label("label1", "Label1");
Component label2 = new Label("label2", "Label2");
addNChildren(wmc, NUMBER_OF_CHILDREN_FOR_A_MAP);
wmc.add(label1);
wmc.add(label2);
Iterator<Component> iterator = wmc.iterator();
takeNChildren(iterator, NUMBER_OF_CHILDREN_FOR_A_MAP);
iterator.next();
// replace the first child **after** we already passed the child with the iterator
Label newChild = new Label("label1", "newChild");
wmc.replace(newChild);
// the next child is still label 2
assertThat(iterator.next(), is(sameInstance(label2)));
// and the new child is not iterated (was replaced before the current position of the
// iterator).
Assert.assertThat(iterator.hasNext(), is(false));
}
use of org.apache.wicket.markup.html.basic.Label in project wicket by apache.
the class MarkupContainerTest method noChildAddingAndReplaceChildAfterIteratorAcquiredShouldIterateAndReturnNewReplacementChild.
@Test
public void noChildAddingAndReplaceChildAfterIteratorAcquiredShouldIterateAndReturnNewReplacementChild() {
WebMarkupContainer wmc = new WebMarkupContainer("id");
Label label1 = new Label("label1", "Label1");
Label label2 = new Label("label1", "Label2");
Iterator<Component> iterator = wmc.iterator();
wmc.add(label1);
wmc.replace(label2);
Assert.assertThat(iterator.hasNext(), is(true));
Assert.assertThat(iterator.next(), is(equalToObject(label2)));
Assert.assertThat(iterator.hasNext(), is(false));
}
Aggregations