Component implements HasElement, AttachNotifier, DetachNotifier { public boolean isAttached() { return getElement().getNode().isAttached(); } protected  Component(); protected  Component(Element element); @Override Element getElement(); Optional<Component> getParent(); Stream<Component> getChildren(); Optional<UI> getUI(); void setId(String id); Optional<String> getId(); boolean isAttached(); static T from(Element element,
            Class<T> componentType); void setVisible(boolean visible); boolean isVisible(); void onEnabledStateChanged(boolean enabled); String getTranslation(String key, Object... params); String getTranslation(String key, Locale locale, Object... params);  }
@Test public void testIsAttached() { UI ui = new UI(); Assert.assertTrue(ui.isAttached()); TestComponentContainer parent = new TestComponentContainer(); TestComponentContainer child = new TestComponentContainer(); TestComponent grandChild = new TestComponent(); child.track(); grandChild.addAttachListener( event -> Assert.assertTrue(grandChild.isAttached())); grandChild.addDetachListener( event -> grandChild.getDetachEvents().incrementAndGet()); parent.add(child); child.add(grandChild); Assert.assertFalse(parent.isAttached()); Assert.assertFalse(child.isAttached()); Assert.assertFalse(grandChild.isAttached()); ui.add(parent); Assert.assertTrue(parent.isAttached()); Assert.assertTrue(child.isAttached()); Assert.assertTrue(grandChild.isAttached()); ui.remove(parent); Assert.assertFalse(parent.isAttached()); Assert.assertFalse(child.isAttached()); Assert.assertFalse(grandChild.isAttached()); ui.add(parent); Assert.assertTrue(parent.isAttached()); Assert.assertTrue(child.isAttached()); Assert.assertTrue(grandChild.isAttached()); ui.getInternals().setSession(Mockito.mock(VaadinSession.class)); ui.close(); ui.getInternals().setSession(null); Assert.assertFalse(parent.isAttached()); Assert.assertFalse(child.isAttached()); Assert.assertFalse(grandChild.isAttached()); Assert.assertFalse(ui.isAttached()); }