|
Groovy example source code file (TableModelTest.groovy)
The Groovy TableModelTest.groovy source codepackage groovy.model class TableModelTest extends GroovyTestCase { void testTableModel() { def list = [ ['name':'James', 'location':'London'], ['name':'Bob', 'location':'Atlanta']] def listModel = new ValueHolder(list) def model = new DefaultTableModel(listModel) model.addColumn(new DefaultTableColumn("Name", new PropertyModel(model.rowModel, "name"))) model.addColumn(new DefaultTableColumn("Location", new PropertyModel(model.rowModel, "location"))) assert model.rowCount == 2 assert model.columnCount == 2 assertValueAt(model, 0, 0, 'James') assertValueAt(model, 0, 1, 'London') assertValueAt(model, 1, 0, 'Bob') assertValueAt(model, 1, 1, 'Atlanta') assert model.getColumnName(0) == 'Name' assert model.getColumnName(1) == 'Location' // let's set some values model.setValueAt('Antigua', 0, 1) assertValueAt(model, 0, 1, 'Antigua') // let's check the real model changed too def james = list.get(0) assert james.location == 'Antigua' } protected void assertValueAt(model, row, col, expected) { def value = model.getValueAt(row, col) assert value == expected , "for row " + row + " col " + col } } Other Groovy examples (source code examples)Here is a short list of links related to this Groovy TableModelTest.groovy source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.