Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
assertj/assertj-swing#117 Provide a valid example.
- Loading branch information
Christian Rösch
authored and
Christian Rösch
committed
Jun 22, 2015
1 parent
b82eddc
commit d465a8e
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
assertj-swing-aut/src/main/java/org/assertj/swing/aut/code/data/TableFrame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" } | ||
}; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
assertj-swing-aut/src/main/java/org/assertj/swing/aut/util/swing/TableUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...c/test/java/org/assertj/swing/junit/examples/code/data/TableCellInRowByValue_Example.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |