Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ default void add(Component... components) {
* @param components
* the components to add
*/
default void add(Collection<Component> components) {
default void add(Collection<? extends Component> components) {
Objects.requireNonNull(components, "Components should not be null");
throwIfTextBindingIsActive("add");
if (hasChildrenBinding()) {
Expand Down Expand Up @@ -145,7 +145,7 @@ default void remove(Component... components) {
* if there is a component whose non {@code null} parent is not
* this component
*/
default void remove(Collection<Component> components) {
default void remove(Collection<? extends Component> components) {
Objects.requireNonNull(components, "Components should not be null");
throwIfTextBindingIsActive("remove");
if (hasChildrenBinding()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component;

import java.util.List;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -432,6 +434,45 @@ public void textBindingActive_bindChildrenThrows() {
"bindChildren should throw while text binding is active");
}

@Test
public void add_typedCollectionOfSubtypes_addsAllChildren() {
TestComponent container = new TestComponent();

List<TestComponent> typedComponents = List.of(
new TestComponent("comp1"), new TestComponent("comp2"),
new TestComponent("comp3"));

container.add(typedComponents);

assertEquals(3, container.getChildren().count());
assertEquals("comp1",
container.getChildren().toList().get(0).getId().orElse(null));
assertEquals("comp2",
container.getChildren().toList().get(1).getId().orElse(null));
assertEquals("comp3",
container.getChildren().toList().get(2).getId().orElse(null));
}

@Test
public void remove_typedCollectionOfSubtypes_removesMatchingChildren() {
TestComponent container = new TestComponent();

TestComponent comp1 = new TestComponent("comp1");
TestComponent comp2 = new TestComponent("comp2");
TestComponent comp3 = new TestComponent("comp3");

container.add(comp1, comp2, comp3);
assertEquals(3, container.getChildren().count());

List<TestComponent> typedComponents = List.of(comp1, comp2);

container.remove(typedComponents);

assertEquals(1, container.getChildren().count());
assertEquals("comp3",
container.getChildren().toList().get(0).getId().orElse(null));
}

private TestComponent createContainerWithTextBinding() {
TestComponent container = new TestComponent();
TextBindingFeature feature = container.getElement().getNode()
Expand Down
Loading