Skip to content

Commit cc09668

Browse files
fix: add null check in setFooterToolbar
Close #131
1 parent 3d73abc commit cc09668

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/main/java/com/flowingcode/vaadin/addons/gridhelpers/FooterToolbarGridHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.vaadin.flow.component.grid.FooterRow.FooterCell;
2525
import com.vaadin.flow.component.grid.Grid;
2626
import java.io.Serializable;
27+
import java.util.Objects;
2728
import lombok.RequiredArgsConstructor;
2829

2930
@SuppressWarnings("serial")
@@ -35,6 +36,7 @@ class FooterToolbarGridHelper implements Serializable {
3536
private FooterCell footerCell;
3637

3738
public void setFooterToolbar(Component toolBar) {
39+
Objects.requireNonNull(toolBar, "Toolbar component must not be null");
3840
Grid<?> grid = helper.getGrid();
3941
if (grid.getColumns().isEmpty()) {
4042
throw new IllegalStateException("Cannot set footer toolbar: Grid columns have not been configured.");

src/test/java/com/flowingcode/vaadin/addons/gridhelpers/test/FooterToolbarTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.vaadin.flow.component.grid.Grid;
2424
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
2525
import org.junit.Test;
26+
import org.junit.jupiter.api.Assertions;
2627

2728
public class FooterToolbarTest {
2829

@@ -42,4 +43,14 @@ public void testSetFooterToolbarBeforeColumnsConfiguredThrowsException() {
4243
var toolbarFooter = new HorizontalLayout();
4344
GridHelper.addToolbarFooter(grid, toolbarFooter);
4445
}
46+
47+
@Test
48+
public void testSetFooterToolbarWithNullToolbarThrowsException() {
49+
Grid<Bean> grid = new Grid<>(Bean.class, false);
50+
grid.addColumn(x -> x).setHeader("Header");
51+
NullPointerException exception = Assertions.assertThrows(NullPointerException.class, () -> {
52+
GridHelper.addToolbarFooter(grid, null);
53+
});
54+
Assertions.assertEquals("Toolbar component must not be null", exception.getMessage());
55+
}
4556
}

0 commit comments

Comments
 (0)