package com.vaadin.tests.server.component.ui;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;

import org.junit.Test;

import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.LegacyWindow;

public class LegacyUIAddRemoveComponents {

    private static class TestUI extends LegacyWindow {
        @Override
        protected void init(VaadinRequest request) {
        }
    }

    @Test
    public void addComponent() {
        TestUI ui = new TestUI();
        Component c = new Label("abc");

        ui.addComponent(c);

        assertSame(c, ui.iterator().next());
        assertSame(c, ui.getContent().iterator().next());
        assertEquals(1, ui.getComponentCount());
        assertEquals(1, ui.getContent().getComponentCount());
    }

    @Test
    public void removeComponent() {
        TestUI ui = new TestUI();
        Component c = new Label("abc");

        ui.addComponent(c);

        ui.removeComponent(c);

        assertFalse(ui.iterator().hasNext());
        assertFalse(ui.getContent().iterator().hasNext());
        assertEquals(0, ui.getComponentCount());
        assertEquals(0, ui.getContent().getComponentCount());
    }

    @Test
    public void replaceComponent() {
        TestUI ui = new TestUI();
        Component c = new Label("abc");
        Component d = new Label("def");

        ui.addComponent(c);

        ui.replaceComponent(c, d);

        assertSame(d, ui.iterator().next());
        assertSame(d, ui.getContent().iterator().next());
        assertEquals(1, ui.getComponentCount());
        assertEquals(1, ui.getContent().getComponentCount());
    }
}

@@ -683,24 +683,36 @@
 assertSame(c
+.getParent()
 , ui.iterato
@@ -716,32 +716,32 @@
 ator().next());%0A
-
         assertSa
@@ -1096,22 +1096,40 @@
   assert
-False(
+Equals(ui.getContent(), 
 ui.itera
@@ -1126,36 +1126,33 @@
 , ui.iterator().
-hasN
+n
 ext());%0A        
@@ -1215,33 +1215,33 @@
    assertEquals(
-0
+1
 , ui.getComponen
@@ -1543,24 +1543,24 @@
 ent(c, d);%0A%0A
-
         asse
@@ -1563,24 +1563,36 @@
 assertSame(d
+.getParent()
 , ui.iterato

Fix LegacyUIAddRemoveComponents test (#2924)