Skip to content

Commit

Permalink
assertj/assertj-swing#117 Provide a valid example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Rösch authored and Christian Rösch committed Jun 22, 2015
1 parent b82eddc commit d465a8e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
@@ -0,0 +1,38 @@
package org.assertj.swing.aut.code.data;

import static org.assertj.swing.aut.util.swing.TableUtil.newTable;

import javax.swing.JTable;

import net.miginfocom.layout.AC;
import net.miginfocom.layout.LC;

import org.assertj.swing.aut.components.SampleFrame;

public class TableFrame extends SampleFrame {
private static final long serialVersionUID = 1L;

public TableFrame() {
setMiglayout(new LC().wrapAfter(1), new AC(), new AC());

final JTable table = newTable("records", data(), columns());

add(table);

pack();
}

private Object[] columns() {
return new Object[] { "First Name", "Last Name", "Sport" };
}

private Object[][] data() {
return new Object[][] {
{ "Kathy", "Smith", "Snowboarding" },
{ "John", "Doe", "Rowing" },
{ "Sue", "Black", "Knitting" },
{ "Jane", "White", "Speed reading" },
{ "Joe", "Brown", "Pool" }
};
}
}
@@ -0,0 +1,17 @@
package org.assertj.swing.aut.util.swing;

import javax.swing.JTable;

public class TableUtil {
public static JTable newTable(String name) {
JTable table = new JTable();
table.setName(name);
return table;
}

public static JTable newTable(String name, Object[][] rowData, Object[] columnNames) {
JTable table = new JTable(rowData, columnNames);
table.setName(name);
return table;
}
}
@@ -0,0 +1,36 @@
package org.assertj.swing.junit.examples.code.data;

import static org.assertj.swing.data.TableCellInRowByValue.rowWithValue;

import javax.swing.JFrame;

import org.assertj.swing.aut.code.data.TableFrame;
import org.assertj.swing.edt.GuiActionRunner;
import org.assertj.swing.edt.GuiQuery;
import org.assertj.swing.fixture.FrameFixture;
import org.assertj.swing.fixture.JTableCellFixture;
import org.assertj.swing.junit.SwingJUnitExamples;
import org.junit.Test;

public class TableCellInRowByValue_Example extends SwingJUnitExamples {

private FrameFixture window;

@Override
protected void onSetUp() {
JFrame frame = GuiActionRunner.execute(new GuiQuery<JFrame>() {
@Override
protected JFrame executeInEDT() {
return new TableFrame();
}
});
window = new FrameFixture(robot(), frame);
window.show();
}

@SuppressWarnings("unused")
@Test
public void example() {
JTableCellFixture cell = window.table("records").cell(rowWithValue("Sue", "Black", "Knitting").column(2));
}
}

0 comments on commit d465a8e

Please sign in to comment.