1 /* 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javafx.scene.control; 27 28 import com.sun.javafx.scene.control.infrastructure.StageLoader; 29 import com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils; 30 import javafx.scene.control.skin.TableColumnHeader; 31 import javafx.beans.property.BooleanProperty; 32 import javafx.beans.property.DoubleProperty; 33 import javafx.beans.property.ObjectProperty; 34 import javafx.beans.property.SimpleBooleanProperty; 35 import javafx.beans.property.SimpleDoubleProperty; 36 import javafx.beans.property.SimpleObjectProperty; 37 import javafx.beans.property.SimpleStringProperty; 38 import javafx.beans.property.StringProperty; 39 import javafx.beans.value.ObservableValue; 40 import javafx.collections.FXCollections; 41 import javafx.collections.ObservableList; 42 import javafx.event.EventHandler; 43 import javafx.event.EventType; 44 import javafx.scene.Node; 45 import javafx.scene.shape.Rectangle; 46 import javafx.util.Callback; 47 48 import java.util.Arrays; 49 import java.util.Collections; 50 import java.util.Comparator; 51 import java.util.List; 52 53 import com.sun.javafx.scene.control.test.Person; 54 import org.junit.Before; 55 import org.junit.Ignore; 56 import org.junit.Test; 57 58 import static org.junit.Assert.*; 59 60 /** 61 */ 62 public class TableColumnTest { 63 private static final double MIN_WIDTH = 35; 64 private static final double MAX_WIDTH = 2000; 65 private static final double PREF_WIDTH = 100; 66 67 private TableColumn<Person,String> column; 68 private TableView<Person> table; 69 private ObservableList<Person> model; 70 71 @Before public void setup() { 72 column = new TableColumn<Person,String>(""); 73 model = FXCollections.observableArrayList( 74 new Person("Humphrey McPhee", 76), 75 new Person("Justice Caldwell", 30), 76 new Person("Orrin Davies", 30), 77 new Person("Emma Wilson", 8) 78 ); 79 table = new TableView<Person>(model); 80 } 81 82 /********************************************************************* 83 * Tests for the constructors * 84 ********************************************************************/ 85 86 @Test public void defaultConstructorHasDefaultCellFactory() { 87 assertSame(TableColumn.DEFAULT_CELL_FACTORY, column.getCellFactory()); 88 assertSame(TableColumn.DEFAULT_CELL_FACTORY, column.cellFactoryProperty().get()); 89 } 90 91 @Test public void defaultConstructorHasDefaultComparator() { 92 assertSame(TableColumn.DEFAULT_COMPARATOR, column.getComparator()); 93 assertSame(TableColumn.DEFAULT_COMPARATOR, column.comparatorProperty().get()); 94 } 95 96 @Test public void defaultConstructorHasEmptyStringText() { 97 assertEquals("", column.getText()); 98 assertEquals("", column.textProperty().get()); 99 } 100 101 // @Test public void defaultConstructorHasNonNullEditCommitHandler() { 102 // // This is questionable 103 // } 104 105 /********************************************************************* 106 * Tests for the tableView property * 107 ********************************************************************/ 108 109 @Test public void tableViewIsNullByDefault() { 110 assertNull(column.getTableView()); 111 assertNull(column.tableViewProperty().get()); 112 } 113 114 @Test public void tableViewCanBeSpecified() { 115 column.setTableView(table); 116 assertSame(table, column.getTableView()); 117 assertSame(table, column.tableViewProperty().get()); 118 } 119 120 @Test public void tableViewCanBeResetToNull() { 121 column.setTableView(table); 122 column.setTableView(null); 123 assertNull(column.getTableView()); 124 assertNull(column.tableViewProperty().get()); 125 } 126 127 @Test public void tableViewPropertyBeanIsCorrect() { 128 assertSame(column, column.tableViewProperty().getBean()); 129 } 130 131 @Test public void tableViewPropertyNameIsCorrect() { 132 assertEquals("tableView", column.tableViewProperty().getName()); 133 } 134 135 @Test public void whenTableViewIsChangedChildColumnsAreUpdated() { 136 TableColumn<Person,String> child = new TableColumn<Person,String>(); 137 column.getColumns().add(child); 138 table.getColumns().add(column); 139 140 TableView<Person> other = new TableView<Person>(); 141 table.getColumns().clear(); 142 other.getColumns().add(column); 143 144 assertSame(other, child.getTableView()); 145 } 146 147 /********************************************************************* 148 * Tests for the text property * 149 ********************************************************************/ 150 151 @Test public void textIsEmptyByDefault() { 152 assertEquals("", column.getText()); 153 assertEquals("", column.textProperty().get()); 154 } 155 156 @Test public void textCanBeSpecified() { 157 column.setText("Name"); 158 assertEquals("Name", column.getText()); 159 assertEquals("Name", column.textProperty().get()); 160 } 161 162 @Test public void textCanBeSetToNull() { 163 column.setText(null); 164 assertNull(column.getText()); 165 assertNull(column.textProperty().get()); 166 } 167 168 @Test public void textPropertyBeanIsCorrect() { 169 assertSame(column, column.textProperty().getBean()); 170 } 171 172 @Test public void textPropertyNameIsCorrect() { 173 assertEquals("text", column.textProperty().getName()); 174 } 175 176 @Test public void textCanBeBound() { 177 StringProperty other = new SimpleStringProperty("Name"); 178 column.textProperty().bind(other); 179 assertEquals("Name", column.getText()); 180 assertEquals("Name", column.textProperty().get()); 181 other.set("Age"); 182 assertEquals("Age", column.getText()); 183 assertEquals("Age", column.textProperty().get()); 184 } 185 186 /********************************************************************* 187 * Tests for the visible property * 188 ********************************************************************/ 189 190 @Test public void visibleIsTrueByDefault() { 191 assertTrue(column.isVisible()); 192 assertTrue(column.visibleProperty().get()); 193 } 194 195 @Test public void visibleCanBeSpecified() { 196 column.setVisible(false); 197 assertFalse(column.isVisible()); 198 assertFalse(column.visibleProperty().get()); 199 } 200 201 @Test public void visiblePropertyBeanIsCorrect() { 202 assertSame(column, column.visibleProperty().getBean()); 203 } 204 205 @Test public void visiblePropertyNameIsCorrect() { 206 assertEquals("visible", column.visibleProperty().getName()); 207 } 208 209 @Test public void visibleCanBeBound() { 210 BooleanProperty other = new SimpleBooleanProperty(false); 211 column.visibleProperty().bind(other); 212 assertFalse(column.isVisible()); 213 assertFalse(column.visibleProperty().get()); 214 other.set(true); 215 assertTrue(column.isVisible()); 216 assertTrue(column.visibleProperty().get()); 217 } 218 219 /********************************************************************* 220 * Tests for the parentColumn property * 221 ********************************************************************/ 222 223 @Test public void parentColumnIsNullByDefault() { 224 TableColumn child = new TableColumn(); 225 assertNull(child.getParentColumn()); 226 assertNull(child.parentColumnProperty().get()); 227 } 228 229 @Test public void parentColumnIsUpdatedWhenAddedToParent() { 230 TableColumn child = new TableColumn(); 231 column.getColumns().add(child); 232 assertSame(column, child.getParentColumn()); 233 assertSame(column, child.parentColumnProperty().get()); 234 } 235 236 @Test public void parentColumnIsClearedWhenRemovedFromParent() { 237 TableColumn child = new TableColumn(); 238 column.getColumns().add(child); 239 column.getColumns().remove(child); 240 assertNull(child.getParentColumn()); 241 assertNull(child.parentColumnProperty().get()); 242 } 243 244 @Test public void parentColumnIsClearedWhenParentColumnsIsCleared() { 245 TableColumn child = new TableColumn(); 246 column.getColumns().add(child); 247 column.getColumns().clear(); 248 assertNull(child.getParentColumn()); 249 assertNull(child.parentColumnProperty().get()); 250 } 251 252 @Test public void tableViewReferenceIsUpdatedWhenAddedToParent() { 253 table.getColumns().add(column); 254 TableColumn child = new TableColumn(); 255 column.getColumns().add(child); 256 assertSame(table, child.getTableView()); 257 assertSame(table, child.tableViewProperty().get()); 258 } 259 260 @Test public void tableViewReferenceIsClearedWhenRemovedFromParent() { 261 table.getColumns().add(column); 262 TableColumn child = new TableColumn(); 263 column.getColumns().add(child); 264 column.getColumns().remove(child); 265 assertNull(child.getTableView()); 266 assertNull(child.tableViewProperty().get()); 267 } 268 269 @Test public void tableViewReferenceIsClearedWhenParentColumnsIsCleared() { 270 table.getColumns().add(column); 271 TableColumn child = new TableColumn(); 272 column.getColumns().add(child); 273 column.getColumns().clear(); 274 assertNull(child.getTableView()); 275 assertNull(child.tableViewProperty().get()); 276 } 277 278 @Test public void visibleIsUpdatedWhenParentColumnVisibleChanges() { 279 TableColumn child = new TableColumn(); 280 column.getColumns().add(child); 281 column.setVisible(true); 282 assertTrue(child.visibleProperty().get()); 283 column.setVisible(false); 284 assertFalse(child.isVisible()); 285 } 286 287 @Test public void visibleIsTrueWhenAddedToParentColumnWithVisibleTrue() { 288 TableColumn child = new TableColumn(); 289 column.setVisible(true); 290 column.getColumns().add(child); 291 assertTrue(child.isVisible()); 292 assertTrue(child.visibleProperty().get()); 293 } 294 295 @Test public void visibleIsNotChangedWhenAddedToParentColumnWithVisibleFalse() { 296 TableColumn child = new TableColumn(); 297 child.setVisible(true); 298 column.setVisible(false); 299 column.getColumns().add(child); 300 assertTrue(child.isVisible()); 301 assertFalse(column.isVisible()); 302 } 303 304 @Test public void visibleIsNotChangedWhenRemovedFromParentColumn() { 305 TableColumn child = new TableColumn(); 306 column.getColumns().add(child); 307 column.setVisible(false); 308 column.getColumns().clear(); 309 assertFalse(child.isVisible()); 310 assertFalse(child.visibleProperty().get()); 311 } 312 313 @Test public void childVisibleChangesAccordingToParentVisibleWhenParentVisibleIsBound() { 314 TableColumn<Person,String> child = new TableColumn<Person,String>(); 315 column.getColumns().add(child); 316 BooleanProperty other = new SimpleBooleanProperty(false); 317 column.visibleProperty().bind(other); 318 assertFalse(child.isVisible()); 319 assertFalse(child.visibleProperty().get()); 320 other.set(true); 321 assertTrue(child.isVisible()); 322 assertTrue(child.visibleProperty().get()); 323 } 324 325 /********************************************************************* 326 * Tests for the contextMenu property * 327 ********************************************************************/ 328 329 @Test public void contextMenuIsNullByDefault() { 330 assertNull(column.getContextMenu()); 331 assertNull(column.contextMenuProperty().get()); 332 } 333 334 @Test public void contextMenuCanBeSpecified() { 335 ContextMenu ctx = new ContextMenu(); 336 column.setContextMenu(ctx); 337 assertSame(ctx, column.getContextMenu()); 338 assertSame(ctx, column.contextMenuProperty().get()); 339 } 340 341 @Test public void contextMenuCanBeSetBackToNull() { 342 ContextMenu ctx = new ContextMenu(); 343 column.setContextMenu(ctx); 344 column.setContextMenu(null); 345 assertNull(column.getContextMenu()); 346 assertNull(column.contextMenuProperty().get()); 347 } 348 349 @Test public void contextMenuPropertyBeanIsCorrect() { 350 assertSame(column, column.contextMenuProperty().getBean()); 351 } 352 353 @Test public void contextMenuPropertyNameIsCorrect() { 354 assertEquals("contextMenu", column.contextMenuProperty().getName()); 355 } 356 357 @Test public void contextMenuCanBeBound() { 358 ContextMenu ctx = new ContextMenu(); 359 ObjectProperty<ContextMenu> other = new SimpleObjectProperty<ContextMenu>(ctx); 360 column.contextMenuProperty().bind(other); 361 assertSame(ctx, column.getContextMenu()); 362 assertSame(ctx, column.contextMenuProperty().get()); 363 other.set(null); 364 assertNull(column.getContextMenu()); 365 assertNull(column.contextMenuProperty().get()); 366 } 367 368 /********************************************************************* 369 * Tests for the cellValueFactory property * 370 ********************************************************************/ 371 372 @Test public void cellValueFactoryIsNullByDefault() { 373 assertNull(column.getCellValueFactory()); 374 assertNull(column.cellValueFactoryProperty().get()); 375 } 376 377 @Test public void cellValueFactoryCanBeSpecified() { 378 CellValueFactory<Person,String> factory = param -> param.getValue().firstNameProperty(); 379 380 column.setCellValueFactory(factory); 381 assertSame(factory, column.getCellValueFactory()); 382 assertSame(factory, column.cellValueFactoryProperty().get()); 383 } 384 385 @Test public void cellValueFactoryCanBeResetToNull() { 386 CellValueFactory<Person,String> factory = param -> param.getValue().firstNameProperty(); 387 388 column.setCellValueFactory(factory); 389 column.setCellValueFactory(null); 390 assertNull(column.getCellValueFactory()); 391 assertNull(column.cellValueFactoryProperty().get()); 392 } 393 394 @Test public void cellValueFactoryPropertyBeanIsCorrect() { 395 assertSame(column, column.cellValueFactoryProperty().getBean()); 396 } 397 398 @Test public void cellValueFactoryPropertyNameIsCorrect() { 399 assertEquals("cellValueFactory", column.cellValueFactoryProperty().getName()); 400 } 401 402 @Test public void cellValueFactoryCanBeBound() { 403 CellValueFactory<Person,String> factory = param -> param.getValue().firstNameProperty(); 404 ObjectProperty<CellValueFactory<Person,String>> other = 405 new SimpleObjectProperty<CellValueFactory<Person, String>>(factory); 406 column.cellValueFactoryProperty().bind(other); 407 assertSame(factory, column.getCellValueFactory()); 408 assertSame(factory, column.cellValueFactoryProperty().get()); 409 other.set(null); 410 assertNull(column.getCellValueFactory()); 411 assertNull(column.cellValueFactoryProperty().get()); 412 } 413 414 /********************************************************************* 415 * Tests for the cellFactory property * 416 ********************************************************************/ 417 418 @Test public void cellFactoryCanBeSpecified() { 419 CellFactory<Person,String> factory = param -> null; 420 column.setCellFactory(factory); 421 assertSame(factory, column.getCellFactory()); 422 assertSame(factory, column.cellFactoryProperty().get()); 423 } 424 425 @Test public void cellFactoryCanBeResetToNull() { 426 CellFactory<Person,String> factory = param -> null; 427 column.setCellFactory(factory); 428 column.setCellFactory(null); 429 assertNull(column.getCellFactory()); 430 assertNull(column.cellFactoryProperty().get()); 431 } 432 433 @Test public void cellFactoryPropertyBeanIsCorrect() { 434 assertSame(column, column.cellFactoryProperty().getBean()); 435 } 436 437 @Test public void cellFactoryPropertyNameIsCorrect() { 438 assertEquals("cellFactory", column.cellFactoryProperty().getName()); 439 } 440 441 @Test public void cellFactoryCanBeBound() { 442 CellFactory<Person,String> factory = param -> null; 443 ObjectProperty<CellFactory<Person,String>> other = 444 new SimpleObjectProperty<CellFactory<Person, String>>(factory); 445 column.cellFactoryProperty().bind(other); 446 assertSame(factory, column.getCellFactory()); 447 assertSame(factory, column.cellFactoryProperty().get()); 448 other.set(null); 449 assertNull(column.getCellFactory()); 450 assertNull(column.cellFactoryProperty().get()); 451 } 452 453 /**************************************************************************** 454 * minWidth Tests * 455 ***************************************************************************/ 456 457 @Ignore ("Fails with hardcoded value of 10") 458 @Test public void minWidthIs_USE_COMPUTED_SIZE_ByDefault() { 459 assertEquals(Control.USE_COMPUTED_SIZE, column.getMinWidth(), 0); 460 assertEquals(Control.USE_COMPUTED_SIZE, column.minWidthProperty().get(), 0); 461 } 462 463 @Test public void minWidthCanBeSet() { 464 column.setMinWidth(234); 465 assertEquals(234, column.getMinWidth(), 0); 466 assertEquals(234, column.minWidthProperty().get(), 0); 467 } 468 469 @Test public void minWidthCanBeBound() { 470 DoubleProperty other = new SimpleDoubleProperty(939); 471 column.minWidthProperty().bind(other); 472 assertEquals(939, column.getMinWidth(), 0); 473 other.set(332); 474 assertEquals(332, column.getMinWidth(), 0); 475 } 476 477 @Test public void minWidthPropertyHasBeanReference() { 478 assertSame(column, column.minWidthProperty().getBean()); 479 } 480 481 @Test public void minWidthPropertyHasName() { 482 assertEquals("minWidth", column.minWidthProperty().getName()); 483 } 484 485 /**************************************************************************** 486 * maxWidth Tests * 487 ***************************************************************************/ 488 489 @Ignore ("Fails with hardcoded value of 5000") 490 @Test public void maxWidthIs_USE_COMPUTED_SIZE_ByDefault() { 491 assertEquals(Control.USE_COMPUTED_SIZE, column.getMaxWidth(), 0); 492 assertEquals(Control.USE_COMPUTED_SIZE, column.maxWidthProperty().get(), 0); 493 } 494 495 @Test public void maxWidthCanBeSet() { 496 column.setMaxWidth(500); 497 assertEquals(500, column.getMaxWidth(), 0); 498 assertEquals(500, column.maxWidthProperty().get(), 0); 499 } 500 501 @Test public void maxWidthCanBeBound() { 502 DoubleProperty other = new SimpleDoubleProperty(939); 503 column.maxWidthProperty().bind(other); 504 assertEquals(939, column.getMaxWidth(), 0); 505 other.set(332); 506 assertEquals(332, column.getMaxWidth(), 0); 507 } 508 509 @Test public void maxWidthPropertyHasBeanReference() { 510 assertSame(column, column.maxWidthProperty().getBean()); 511 } 512 513 @Test public void maxWidthPropertyHasName() { 514 assertEquals("maxWidth", column.maxWidthProperty().getName()); 515 } 516 517 /**************************************************************************** 518 * prefWidth Tests * 519 ***************************************************************************/ 520 521 @Ignore ("Fails with hardcoded value of 80") 522 @Test public void prefWidthIs_USE_COMPUTED_SIZE_ByDefault() { 523 assertEquals(Control.USE_COMPUTED_SIZE, column.getPrefWidth(), 0); 524 assertEquals(Control.USE_COMPUTED_SIZE, column.prefWidthProperty().get(), 0); 525 } 526 527 @Test public void prefWidthCanBeSet() { 528 column.setPrefWidth(80); 529 assertEquals(80, column.getPrefWidth(), 0); 530 assertEquals(80, column.prefWidthProperty().get(), 0); 531 } 532 533 @Test public void prefWidthCanBeBound() { 534 DoubleProperty other = new SimpleDoubleProperty(939); 535 column.prefWidthProperty().bind(other); 536 assertEquals(939, column.getPrefWidth(), 0); 537 other.set(332); 538 assertEquals(332, column.getPrefWidth(), 0); 539 } 540 541 @Test public void prefWidthPropertyHasBeanReference() { 542 assertSame(column, column.prefWidthProperty().getBean()); 543 } 544 545 @Test public void prefWidthPropertyHasName() { 546 assertEquals("prefWidth", column.prefWidthProperty().getName()); 547 } 548 549 /********************************************************************* 550 * Tests for the resizable property * 551 ********************************************************************/ 552 553 @Test public void resizableIsTrueByDefault() { 554 assertTrue(column.isResizable()); 555 assertTrue(column.resizableProperty().get()); 556 } 557 558 @Test public void resizableCanBeSpecified() { 559 column.setResizable(false); 560 assertFalse(column.isResizable()); 561 assertFalse(column.resizableProperty().get()); 562 } 563 564 @Test public void resizablePropertyBeanIsCorrect() { 565 assertSame(column, column.resizableProperty().getBean()); 566 } 567 568 @Test public void resizablePropertyNameIsCorrect() { 569 assertEquals("resizable", column.resizableProperty().getName()); 570 } 571 572 @Test public void resizableCanBeBound() { 573 BooleanProperty other = new SimpleBooleanProperty(false); 574 column.resizableProperty().bind(other); 575 assertFalse(column.isResizable()); 576 assertFalse(column.resizableProperty().get()); 577 other.set(true); 578 assertTrue(column.isResizable()); 579 assertTrue(column.resizableProperty().get()); 580 } 581 582 /********************************************************************* 583 * Tests for the sortable property * 584 ********************************************************************/ 585 586 @Test public void sortableIsTrueByDefault() { 587 assertTrue(column.isSortable()); 588 assertTrue(column.sortableProperty().get()); 589 } 590 591 @Test public void sortableCanBeSpecified() { 592 column.setSortable(false); 593 assertFalse(column.isSortable()); 594 assertFalse(column.sortableProperty().get()); 595 } 596 597 @Test public void sortablePropertyBeanIsCorrect() { 598 assertSame(column, column.sortableProperty().getBean()); 599 } 600 601 @Test public void sortablePropertyNameIsCorrect() { 602 assertEquals("sortable", column.sortableProperty().getName()); 603 } 604 605 @Test public void sortableCanBeBound() { 606 BooleanProperty other = new SimpleBooleanProperty(false); 607 column.sortableProperty().bind(other); 608 assertFalse(column.isSortable()); 609 assertFalse(column.sortableProperty().get()); 610 other.set(true); 611 assertTrue(column.isSortable()); 612 assertTrue(column.sortableProperty().get()); 613 } 614 615 /********************************************************************* 616 * Tests for the sortType property * 617 ********************************************************************/ 618 619 @Test public void sortTypeIsASCENDINGByDefault() { 620 assertSame(TableColumn.SortType.ASCENDING, column.getSortType()); 621 assertSame(TableColumn.SortType.ASCENDING, column.sortTypeProperty().get()); 622 } 623 624 @Test public void sortTypeCanBeSpecified() { 625 column.setSortType(TableColumn.SortType.DESCENDING); 626 assertSame(TableColumn.SortType.DESCENDING, column.getSortType()); 627 assertSame(TableColumn.SortType.DESCENDING, column.sortTypeProperty().get()); 628 } 629 630 @Test public void sortTypeCanBeNull() { 631 column.setSortType(null); 632 assertNull(column.getSortType()); 633 assertNull(column.sortTypeProperty().get()); 634 } 635 636 @Test public void sortTypePropertyBeanIsCorrect() { 637 assertSame(column, column.sortTypeProperty().getBean()); 638 } 639 640 @Test public void sortTypePropertyNameIsCorrect() { 641 assertEquals("sortType", column.sortTypeProperty().getName()); 642 } 643 644 @Test public void sortTypeCanBeBound() { 645 ObjectProperty<TableColumn.SortType> other = 646 new SimpleObjectProperty<TableColumn.SortType>(TableColumn.SortType.DESCENDING); 647 column.sortTypeProperty().bind(other); 648 assertSame(TableColumn.SortType.DESCENDING, column.getSortType()); 649 assertSame(TableColumn.SortType.DESCENDING, column.sortTypeProperty().get()); 650 other.set(null); 651 assertNull(column.getSortType()); 652 assertNull(column.sortTypeProperty().get()); 653 } 654 655 /********************************************************************* 656 * Tests for the editable property * 657 ********************************************************************/ 658 659 @Test public void editableIsTrueByDefault() { 660 assertTrue(column.isEditable()); 661 assertTrue(column.editableProperty().get()); 662 } 663 664 @Test public void editableCanBeSpecified() { 665 column.setEditable(false); 666 assertFalse(column.isEditable()); 667 assertFalse(column.editableProperty().get()); 668 } 669 670 @Test public void editablePropertyBeanIsCorrect() { 671 assertSame(column, column.editableProperty().getBean()); 672 } 673 674 @Test public void editablePropertyNameIsCorrect() { 675 assertEquals("editable", column.editableProperty().getName()); 676 } 677 678 @Test public void editableCanBeBound() { 679 BooleanProperty other = new SimpleBooleanProperty(false); 680 column.editableProperty().bind(other); 681 assertFalse(column.isEditable()); 682 assertFalse(column.editableProperty().get()); 683 other.set(true); 684 assertTrue(column.isEditable()); 685 assertTrue(column.editableProperty().get()); 686 } 687 688 /********************************************************************* 689 * Tests for the reorderable property * 690 ********************************************************************/ 691 692 @Test public void reorderableIsTrueByDefault() { 693 assertTrue(column.impl_isReorderable()); 694 assertTrue(column.impl_reorderableProperty().get()); 695 } 696 697 @Test public void reorderableCanBeSpecified() { 698 column.impl_setReorderable(false); 699 assertFalse(column.impl_isReorderable()); 700 assertFalse(column.impl_reorderableProperty().get()); 701 } 702 703 @Test public void reorderablePropertyBeanIsCorrect() { 704 assertSame(column, column.impl_reorderableProperty().getBean()); 705 } 706 707 @Test public void reorderablePropertyNameIsCorrect() { 708 assertEquals("reorderable", column.impl_reorderableProperty().getName()); 709 } 710 711 @Test public void reorderableCanBeBound() { 712 BooleanProperty other = new SimpleBooleanProperty(false); 713 column.impl_reorderableProperty().bind(other); 714 assertFalse(column.impl_isReorderable()); 715 assertFalse(column.impl_reorderableProperty().get()); 716 other.set(true); 717 assertTrue(column.impl_isReorderable()); 718 assertTrue(column.impl_reorderableProperty().get()); 719 } 720 721 /********************************************************************* 722 * Tests for the comparator property * 723 ********************************************************************/ 724 725 @Test public void comparatorCanBeSpecified() { 726 Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2); 727 column.setComparator(comparator); 728 assertSame(comparator, column.getComparator()); 729 assertSame(comparator, column.comparatorProperty().get()); 730 } 731 732 @Test public void comparatorCanBeResetToNull() { 733 Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2); 734 column.setComparator(comparator); 735 column.setComparator(null); 736 assertNull(column.getComparator()); 737 assertNull(column.comparatorProperty().get()); 738 } 739 740 @Test public void comparatorPropertyBeanIsCorrect() { 741 assertSame(column, column.comparatorProperty().getBean()); 742 } 743 744 @Test public void comparatorPropertyNameIsCorrect() { 745 assertEquals("comparator", column.comparatorProperty().getName()); 746 } 747 748 @Test public void comparatorCanBeBound() { 749 Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2); 750 ObjectProperty<Comparator<String>> other = 751 new SimpleObjectProperty<Comparator<String>>(comparator); 752 column.comparatorProperty().bind(other); 753 assertSame(comparator, column.getComparator()); 754 assertSame(comparator, column.comparatorProperty().get()); 755 other.set(null); 756 assertNull(column.getComparator()); 757 assertNull(column.comparatorProperty().get()); 758 } 759 760 /********************************************************************* 761 * Tests for the onEditStart property * 762 ********************************************************************/ 763 764 @Test public void onEditStartIsNullByDefault() { 765 assertNull(column.getOnEditStart()); 766 assertNull(column.onEditStartProperty().get()); 767 } 768 769 @Test public void onEditStartCanBeSpecified() { 770 EventHandler<TableColumn.CellEditEvent<Person,String>> handler = 771 event -> { 772 }; 773 column.setOnEditStart(handler); 774 assertSame(handler, column.getOnEditStart()); 775 assertSame(handler, column.onEditStartProperty().get()); 776 } 777 778 @Test public void onEditStartCanBeResetToNull() { 779 EventHandler<TableColumn.CellEditEvent<Person,String>> handler = 780 event -> { 781 }; 782 column.setOnEditStart(handler); 783 column.setOnEditStart(null); 784 assertNull(column.getOnEditStart()); 785 assertNull(column.onEditStartProperty().get()); 786 } 787 788 @Test public void onEditStartPropertyBeanIsCorrect() { 789 assertSame(column, column.onEditStartProperty().getBean()); 790 } 791 792 @Test public void onEditStartPropertyNameIsCorrect() { 793 assertEquals("onEditStart", column.onEditStartProperty().getName()); 794 } 795 796 @Test public void onEditStartCanBeBound() { 797 EventHandler<TableColumn.CellEditEvent<Person,String>> handler = 798 event -> { 799 }; 800 ObjectProperty<EventHandler<TableColumn.CellEditEvent<Person,String>>> other = 801 new SimpleObjectProperty<EventHandler<TableColumn.CellEditEvent<Person, String>>>(handler); 802 column.onEditStartProperty().bind(other); 803 assertSame(handler, column.getOnEditStart()); 804 assertSame(handler, column.onEditStartProperty().get()); 805 other.set(null); 806 assertNull(column.getOnEditStart()); 807 assertNull(column.onEditStartProperty().get()); 808 } 809 810 /********************************************************************* 811 * Tests for the onEditCancel property * 812 ********************************************************************/ 813 814 @Test public void onEditCancelIsNullByDefault() { 815 assertNull(column.getOnEditCancel()); 816 assertNull(column.onEditCancelProperty().get()); 817 } 818 819 @Test public void onEditCancelCanBeSpecified() { 820 EventHandler<TableColumn.CellEditEvent<Person,String>> handler = 821 event -> { 822 }; 823 column.setOnEditCancel(handler); 824 assertSame(handler, column.getOnEditCancel()); 825 assertSame(handler, column.onEditCancelProperty().get()); 826 } 827 828 @Test public void onEditCancelCanBeResetToNull() { 829 EventHandler<TableColumn.CellEditEvent<Person,String>> handler = 830 event -> { 831 }; 832 column.setOnEditCancel(handler); 833 column.setOnEditCancel(null); 834 assertNull(column.getOnEditCancel()); 835 assertNull(column.onEditCancelProperty().get()); 836 } 837 838 @Test public void onEditCancelPropertyBeanIsCorrect() { 839 assertSame(column, column.onEditCancelProperty().getBean()); 840 } 841 842 @Test public void onEditCancelPropertyNameIsCorrect() { 843 assertEquals("onEditCancel", column.onEditCancelProperty().getName()); 844 } 845 846 @Test public void onEditCancelCanBeBound() { 847 EventHandler<TableColumn.CellEditEvent<Person,String>> handler = 848 event -> { 849 }; 850 ObjectProperty<EventHandler<TableColumn.CellEditEvent<Person,String>>> other = 851 new SimpleObjectProperty<EventHandler<TableColumn.CellEditEvent<Person, String>>>(handler); 852 column.onEditCancelProperty().bind(other); 853 assertSame(handler, column.getOnEditCancel()); 854 assertSame(handler, column.onEditCancelProperty().get()); 855 other.set(null); 856 assertNull(column.getOnEditCancel()); 857 assertNull(column.onEditCancelProperty().get()); 858 } 859 860 /********************************************************************* 861 * Tests for the onEditCommit property * 862 ********************************************************************/ 863 864 // @Test public void onEditCommitIsNullByDefault() { 865 // assertNull(column.getOnEditCommit()); 866 // assertNull(column.onEditCommitProperty().get()); 867 // } 868 869 @Test public void onEditCommitCanBeSpecified() { 870 EventHandler<TableColumn.CellEditEvent<Person,String>> handler = 871 event -> { 872 }; 873 column.setOnEditCommit(handler); 874 assertSame(handler, column.getOnEditCommit()); 875 assertSame(handler, column.onEditCommitProperty().get()); 876 } 877 878 @Test public void onEditCommitCanBeResetToNull() { 879 EventHandler<TableColumn.CellEditEvent<Person,String>> handler = 880 event -> { 881 }; 882 column.setOnEditCommit(handler); 883 column.setOnEditCommit(null); 884 assertNull(column.getOnEditCommit()); 885 assertNull(column.onEditCommitProperty().get()); 886 } 887 888 @Test public void onEditCommitPropertyBeanIsCorrect() { 889 assertSame(column, column.onEditCommitProperty().getBean()); 890 } 891 892 @Test public void onEditCommitPropertyNameIsCorrect() { 893 assertEquals("onEditCommit", column.onEditCommitProperty().getName()); 894 } 895 896 @Test public void onEditCommitCanBeBound() { 897 EventHandler<TableColumn.CellEditEvent<Person,String>> handler = 898 event -> { 899 }; 900 ObjectProperty<EventHandler<TableColumn.CellEditEvent<Person,String>>> other = 901 new SimpleObjectProperty<EventHandler<TableColumn.CellEditEvent<Person, String>>>(handler); 902 column.onEditCommitProperty().bind(other); 903 assertSame(handler, column.getOnEditCommit()); 904 assertSame(handler, column.onEditCommitProperty().get()); 905 other.set(null); 906 assertNull(column.getOnEditCommit()); 907 assertNull(column.onEditCommitProperty().get()); 908 } 909 910 /********************************************************************* 911 * Tests for getCellData * 912 ********************************************************************/ 913 914 @Test public void getCellDataReturnsNullWhenTableViewIsNull() { 915 assertNull(column.getCellData(0)); 916 } 917 918 @Test public void getCellDataReturnsNullWhenTableViewIsNull2() { 919 assertNull(column.getCellData(table.getItems().get(1))); 920 } 921 922 @Test public void getCellDataReturnsNullWhenTableViewItemsIsNull() { 923 table.getColumns().add(column); 924 table.setItems(null); 925 assertNull(column.getCellData(0)); 926 } 927 928 @Test public void getCellDataReturnsNullWhenTableViewItemsIsNull2() { 929 final Person person = table.getItems().get(1); 930 table.getColumns().add(column); 931 table.setItems(null); 932 assertNull(column.getCellData(person)); 933 } 934 935 @Test public void getCellDataReturnsNullWhenRowDataIsNullByDefault() { 936 table.getColumns().add(column); 937 table.getItems().set(0, null); 938 assertNull(column.getCellData(0)); 939 } 940 941 @Test public void getCellDataReturnsNullWhenRowDataIsNullByDefault2() { 942 table.getColumns().add(column); 943 assertNull(column.getCellData(null)); 944 } 945 946 @Test public void getCellDataReturnsNullWhenIndexIsNegative() { 947 table.getColumns().add(column); 948 assertNull(column.getCellData(-1)); 949 } 950 951 @Test public void getCellDataReturnsNullWhenIndexIsTooLarge() { 952 table.getColumns().add(column); 953 assertNull(column.getCellData(table.getItems().size())); 954 } 955 956 @Test public void getCellDataReturnsNullWhenCellValueFactoryIsNull() { 957 table.getColumns().add(column); 958 assertNull(column.getCellData(0)); 959 } 960 961 @Test public void getCellDataReturnsNullWhenCellValueFactoryIsNull2() { 962 table.getColumns().add(column); 963 assertNull(column.getCellData(table.getItems().get(1))); 964 } 965 966 @Test public void getCellDataReturnsValue() { 967 table.getColumns().add(column); 968 column.setCellValueFactory(param -> param.getValue().firstNameProperty()); 969 assertEquals("Humphrey McPhee", column.getCellData(0)); 970 } 971 972 @Test public void getCellDataReturnsValue2() { 973 table.getColumns().add(column); 974 column.setCellValueFactory(param -> param.getValue().firstNameProperty()); 975 assertEquals("Humphrey McPhee", column.getCellData(table.getItems().get(0))); 976 } 977 978 @Test public void cellDataFeaturesHasTableViewSpecified() { 979 final boolean[] passed = new boolean[] { false }; 980 table.getColumns().add(column); 981 column.setCellValueFactory(param -> { 982 passed[0] = param.getTableView() == table; 983 return param.getValue().firstNameProperty(); 984 }); 985 column.getCellData(table.getItems().get(0)); 986 assertTrue(passed[0]); 987 } 988 989 @Test public void cellDataFeaturesHasTableColumnSpecified() { 990 final boolean[] passed = new boolean[] { false }; 991 table.getColumns().add(column); 992 column.setCellValueFactory(param -> { 993 passed[0] = param.getTableColumn() == column; 994 return param.getValue().firstNameProperty(); 995 }); 996 column.getCellData(table.getItems().get(0)); 997 assertTrue(passed[0]); 998 } 999 1000 @Test public void cellDataFeaturesHasRowItemSpecified() { 1001 final boolean[] passed = new boolean[] { false }; 1002 table.getColumns().add(column); 1003 column.setCellValueFactory(param -> { 1004 passed[0] = param.getValue() == table.getItems().get(0); 1005 return param.getValue().firstNameProperty(); 1006 }); 1007 column.getCellData(table.getItems().get(0)); 1008 assertTrue(passed[0]); 1009 } 1010 1011 /********************************************************************* 1012 * Tests for the DEFAULT_EDIT_COMMIT_HANDLER. By default each * 1013 * TableColumn has a DEFAULT_EDIT_COMMIT_HANDLER installed which * 1014 * will, if the value returned by cellValueFactory is a * 1015 * WritableValue, commit. If not, then nothing happens. * 1016 ********************************************************************/ 1017 1018 @Test public void onEditCommitHandlerInstalledByDefault() { 1019 assertNotNull(column.getOnEditCommit()); 1020 } 1021 1022 @Test public void defaultOnEditCommitHandlerWillSaveToWritableValue() { 1023 table.getColumns().add(column); 1024 column.setCellValueFactory(param -> param.getValue().firstNameProperty()); 1025 TablePosition<Person,String> pos = new TablePosition<Person, String>(table, 0, column); 1026 EventType<TableColumn.CellEditEvent<Person,String>> eventType = TableColumn.editCommitEvent(); 1027 column.getOnEditCommit().handle(new TableColumn.CellEditEvent<Person,String>( 1028 table, pos, (EventType)eventType, "Richard Bair")); 1029 assertEquals("Richard Bair", table.getItems().get(0).getFirstName()); 1030 } 1031 1032 @Test public void defaultOnEditCommitHandlerWillIgnoreReadOnlyValue() { 1033 TableColumn<Person,Number> ageColumn = new TableColumn<Person,Number>(); 1034 table.getColumns().add(ageColumn); 1035 ageColumn.setCellValueFactory(param -> param.getValue().ageProperty()); 1036 TablePosition<Person,Number> pos = new TablePosition<Person, Number>(table, 0, ageColumn); 1037 EventType<TableColumn.CellEditEvent<Person,Number>> eventType = TableColumn.editCommitEvent(); 1038 ageColumn.getOnEditCommit().handle(new TableColumn.CellEditEvent<Person,Number>( 1039 table, pos, (EventType)eventType, 109)); 1040 assertEquals(76, table.getItems().get(0).getAge()); 1041 } 1042 1043 @Test(expected=NullPointerException.class) 1044 public void defaultOnEditCommitHandlerDealsWithNullTableView() { 1045 table.getColumns().add(column); 1046 column.setCellValueFactory(param -> param.getValue().firstNameProperty()); 1047 TablePosition<Person,String> pos = new TablePosition<Person, String>(table, 0, column); 1048 EventType<TableColumn.CellEditEvent<Person,String>> eventType = TableColumn.editCommitEvent(); 1049 column.getOnEditCommit().handle(new TableColumn.CellEditEvent<Person, String>( 1050 null, pos, (EventType) eventType, "Richard Bair")); 1051 } 1052 1053 @Test(expected=NullPointerException.class) 1054 public void defaultOnEditCommitHandlerDealsWithNullTablePosition() { 1055 table.getColumns().add(column); 1056 column.setCellValueFactory(param -> param.getValue().firstNameProperty()); 1057 TablePosition<Person,String> pos = new TablePosition<Person, String>(table, 0, column); 1058 EventType<TableColumn.CellEditEvent<Person,String>> eventType = TableColumn.editCommitEvent(); 1059 column.getOnEditCommit().handle(new TableColumn.CellEditEvent<Person, String>( 1060 table, null, (EventType) eventType, "Richard Bair")); 1061 } 1062 1063 @Test public void defaultOnEditCommitHandlerDealsWithInvalidTablePosition_indexIsNegative() { 1064 table.getColumns().add(column); 1065 column.setCellValueFactory(param -> param.getValue().firstNameProperty()); 1066 TablePosition<Person,String> pos = new TablePosition<Person, String>(table, -1, column); 1067 EventType<TableColumn.CellEditEvent<Person,String>> eventType = TableColumn.editCommitEvent(); 1068 column.getOnEditCommit().handle(new TableColumn.CellEditEvent<Person,String>( 1069 table, pos, (EventType)eventType, "Richard Bair")); 1070 assertEquals("Humphrey McPhee", table.getItems().get(0).getFirstName()); 1071 } 1072 1073 @Test public void defaultOnEditCommitHandlerDealsWithInvalidTablePosition_indexIsTooLarge() { 1074 table.getColumns().add(column); 1075 column.setCellValueFactory(param -> param.getValue().firstNameProperty()); 1076 TablePosition<Person,String> pos = new TablePosition<Person, String>(table, 100, column); 1077 EventType<TableColumn.CellEditEvent<Person,String>> eventType = TableColumn.editCommitEvent(); 1078 column.getOnEditCommit().handle(new TableColumn.CellEditEvent<Person, String>( 1079 table, pos, (EventType) eventType, "Richard Bair")); 1080 assertEquals("Humphrey McPhee", table.getItems().get(0).getFirstName()); 1081 } 1082 1083 /********************************************************************* 1084 * Tests for the default comparator * 1085 ********************************************************************/ 1086 1087 @Test public void sortingWithNullItems() { 1088 List<String> items = Arrays.asList("Hippo", null, "Fish", "Eagle", null); 1089 Collections.sort(items, TableColumn.DEFAULT_COMPARATOR); 1090 assertNull(items.get(0)); 1091 assertNull(items.get(1)); 1092 assertEquals("Eagle", items.get(2)); 1093 assertEquals("Fish", items.get(3)); 1094 assertEquals("Hippo", items.get(4)); 1095 } 1096 1097 @Test public void sortingWithSameItems() { 1098 List<String> items = Arrays.asList("Hippo", "Hippo", "Fish", "Eagle", "Fish"); 1099 Collections.sort(items, TableColumn.DEFAULT_COMPARATOR); 1100 assertEquals("Eagle", items.get(0)); 1101 assertEquals("Fish", items.get(1)); 1102 assertEquals("Fish", items.get(2)); 1103 assertEquals("Hippo", items.get(3)); 1104 assertEquals("Hippo", items.get(4)); 1105 } 1106 1107 @Test public void sortingWithNonComparableItemsSortsByToString() { 1108 Person fred = new Person("Fred", 36); 1109 Person wilma = new Person("Wilma", 34); 1110 Person barney = new Person("Barney", 34); 1111 List<Person> items = Arrays.asList(fred, wilma, barney); 1112 Collections.sort(items, TableColumn.DEFAULT_COMPARATOR); 1113 assertSame(barney, items.get(0)); 1114 assertSame(fred, items.get(1)); 1115 assertSame(wilma, items.get(2)); 1116 } 1117 1118 @Ignore("This started failing when I upgraded to Java 7") 1119 @Test public void sortingMixOfComparableAndNonComparable() { 1120 Person fred = new Person("Fred", 36); 1121 Person wilma = new Person("Wilma", 34); 1122 Person barney = new Person("Barney", 34); 1123 List<Object> items = Arrays.asList(fred, wilma, barney, "Pebbles"); 1124 Collections.sort(items, TableColumn.DEFAULT_COMPARATOR); 1125 assertSame(barney, items.get(0)); 1126 assertSame(fred, items.get(1)); 1127 assertEquals("Pebbles", items.get(2)); 1128 assertSame(wilma, items.get(3)); 1129 } 1130 1131 /********************************************************************* 1132 * Tests for the default cell factory * 1133 ********************************************************************/ 1134 1135 @Test public void defaultCellFactoryHasNullTextByDefault() { 1136 table.getColumns().add(column); 1137 TableCell<Person,String> cell = column.getCellFactory().call(column); 1138 assertNull(cell.getText()); 1139 } 1140 1141 @Test public void defaultCellFactoryHasNullGraphicByDefault() { 1142 table.getColumns().add(column); 1143 TableCell<Person,String> cell = column.getCellFactory().call(column); 1144 assertNull(cell.getGraphic()); 1145 } 1146 1147 @Test public void defaultCellFactorySetsTextToNameWhenItemIsPerson() { 1148 table.getColumns().add(column); 1149 TableCell<Person,String> cell = column.getCellFactory().call(column); 1150 cell.updateIndex(0); 1151 cell.updateItem(table.getItems().get(0).getFirstName(), false); 1152 assertEquals(table.getItems().get(0).getFirstName(), cell.getText()); 1153 } 1154 1155 @Test public void defaultCellFactorySetsTextToNullWhenItemIsNull() { 1156 table.getColumns().add(column); 1157 TableCell<Person,String> cell = column.getCellFactory().call(column); 1158 // First have to set to a value, or it short-cuts 1159 cell.updateIndex(0); 1160 cell.updateItem(table.getItems().get(0).getFirstName(), false); 1161 // Now we're good to go 1162 table.getItems().set(0, null); 1163 cell.updateItem(null, false); 1164 assertNull(cell.getText()); 1165 } 1166 1167 @Test public void defaultCellFactorySetsGraphicToNullWhenItemIsPerson() { 1168 table.getColumns().add(column); 1169 TableCell<Person,String> cell = column.getCellFactory().call(column); 1170 cell.updateIndex(0); 1171 cell.updateItem(table.getItems().get(0).getFirstName(), false); 1172 assertNull(cell.getGraphic()); 1173 } 1174 1175 @Test public void defaultCellFactorySetsGraphicToNullWhenItemIsNull() { 1176 table.getColumns().add(column); 1177 TableCell<Person,String> cell = column.getCellFactory().call(column); 1178 table.getItems().set(0, null); 1179 cell.updateIndex(0); 1180 cell.updateItem(null, false); 1181 assertNull(cell.getGraphic()); 1182 } 1183 1184 @Test public void defaultCellFactorySetsGraphicToItemWhenItemIsNode() { 1185 TableView<Node> nodeTable = new TableView<Node>(); 1186 Rectangle rect = new Rectangle(); 1187 nodeTable.getItems().add(rect); 1188 TableColumn<Node,Node> nodeColumn = new TableColumn<Node,Node>(); 1189 nodeTable.getColumns().add(nodeColumn); 1190 TableCell<Node,Node> cell = nodeColumn.getCellFactory().call(nodeColumn); 1191 cell.updateIndex(0); 1192 cell.updateItem(rect, false); 1193 assertSame(rect, cell.getGraphic()); 1194 } 1195 1196 @Test public void defaultCellFactorySetsTextToNullWhenItemIsNode() { 1197 TableView<Node> nodeTable = new TableView<Node>(); 1198 Rectangle rect = new Rectangle(); 1199 nodeTable.getItems().add(rect); 1200 TableColumn<Node,Node> nodeColumn = new TableColumn<Node,Node>(); 1201 nodeTable.getColumns().add(nodeColumn); 1202 TableCell<Node,Node> cell = nodeColumn.getCellFactory().call(nodeColumn); 1203 cell.updateIndex(0); 1204 cell.updateItem(rect, false); 1205 assertNull(cell.getText()); 1206 } 1207 1208 // column with null cellValueFactory still updates item when row item changes 1209 1210 // children widths always add up to parent width 1211 // change sibling width 1212 // change parent width 1213 1214 1215 public interface CellValueFactory<S,T> extends Callback<TableColumn.CellDataFeatures<S,T>, ObservableValue<T>> { 1216 } 1217 1218 public interface CellFactory<S,T> extends Callback<TableColumn<S,T>, TableCell<S,T>> { 1219 } 1220 1221 @Test public void test_rt36715_idIsNullAtStartup() { 1222 assertNull(column.getId()); 1223 } 1224 1225 @Test public void test_rt36715_idIsSettable() { 1226 column.setId("test-id"); 1227 assertEquals("test-id", column.getId()); 1228 } 1229 1230 @Test public void test_rt36715_columnHeaderIdMirrorsTableColumnId_setIdBeforeHeaderInstantiation() { 1231 test_rt36715_columnHeaderPropertiesMirrorTableColumnProperties(true, true, false, false); 1232 } 1233 1234 @Test public void test_rt36715_columnHeaderIdMirrorsTableColumnId_setIdAfterHeaderInstantiation() { 1235 test_rt36715_columnHeaderPropertiesMirrorTableColumnProperties(true, false, false, false); 1236 } 1237 1238 @Test public void test_rt36715_styleIsEmptyStringAtStartup() { 1239 assertEquals("", column.getStyle()); 1240 } 1241 1242 @Test public void test_rt36715_styleIsSettable() { 1243 column.setStyle("-fx-border-color: red"); 1244 assertEquals("-fx-border-color: red", column.getStyle()); 1245 } 1246 1247 @Test public void test_rt36715_columnHeaderStyleMirrorsTableColumnStyle_setStyleBeforeHeaderInstantiation() { 1248 test_rt36715_columnHeaderPropertiesMirrorTableColumnProperties(false, false, true, true); 1249 } 1250 1251 @Test public void test_rt36715_columnHeaderStyleMirrorsTableColumnStyle_setStyleAfterHeaderInstantiation() { 1252 test_rt36715_columnHeaderPropertiesMirrorTableColumnProperties(false, false, true, false); 1253 } 1254 1255 private void test_rt36715_columnHeaderPropertiesMirrorTableColumnProperties( 1256 boolean setId, boolean setIdBeforeHeaderInstantiation, 1257 boolean setStyle, boolean setStyleBeforeHeaderInstantiation) { 1258 table.getColumns().add(column); 1259 1260 if (setId && setIdBeforeHeaderInstantiation) { 1261 column.setId("test-id"); 1262 } 1263 if (setStyle && setStyleBeforeHeaderInstantiation) { 1264 column.setStyle("-fx-border-color: red"); 1265 } 1266 1267 StageLoader sl = new StageLoader(table); 1268 TableColumnHeader header = VirtualFlowTestUtils.getTableColumnHeader(table, column); 1269 1270 if (setId && ! setIdBeforeHeaderInstantiation) { 1271 column.setId("test-id"); 1272 } 1273 if (setStyle && ! setStyleBeforeHeaderInstantiation) { 1274 column.setStyle("-fx-border-color: red"); 1275 } 1276 1277 if (setId) { 1278 assertEquals("test-id", header.getId()); 1279 } 1280 if (setStyle) { 1281 assertEquals("-fx-border-color: red", header.getStyle()); 1282 } 1283 1284 sl.dispose(); 1285 } 1286 }