home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (TableModelTest.groovy)

This example Groovy source code file (TableModelTest.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

antigua, antigua, atlanta, defaulttablecolumn, defaulttablecolumn, defaulttablemodel, groovytestcase, james, location, location, london, name, name, tablemodeltest

The Groovy TableModelTest.groovy source code

package 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:

new blog posts


Copyright 1998-2016 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.