package yukihane.gps.gui; import java.io.File; import org.fest.swing.core.BasicRobot; import org.fest.swing.core.Robot; import org.fest.swing.fixture.FrameFixture; import org.fest.swing.fixture.JFileChooserFixture; import org.fest.swing.fixture.JTableFixture; import org.junit.After; import org.junit.Before; import org.junit.Test; import static org.fest.assertions.Assertions.*; import static org.fest.swing.core.matcher.JButtonMatcher.withText; import static org.junit.Assert.*; public class MainWindowTest { private Robot robot; private FrameFixture window; private JTableFixture table; @Before public void setUp() { robot = BasicRobot.robotWithNewAwtHierarchy(); window = new FrameFixture(robot, new MainWindow()); window.show(); table = window.table(); } @After public void tearDown() { robot.cleanUp(); } @Test public void testOpen() { assertEquals(0, table.columnIndexFor("行")); assertEquals(1, table.columnIndexFor("保存")); assertEquals(2, table.columnIndexFor("日時")); assertEquals(3, table.columnIndexFor("緯度")); assertEquals(4, table.columnIndexFor("経度")); assertEquals(5, table.columnIndexFor("高度")); assertEquals("起動時のテーブルは空", 0, table.rowCount()); } @Test public void testOpenFile() { final File file = new File("testdata/ver112.trl").getAbsoluteFile(); window.button(withText("開く...")).click(); JFileChooserFixture chooser = new JFileChooserFixture(robot); chooser.selectFile(file); chooser.approve(); assertThat(table.rowCount()).as("ファイルの内容が表示される").isGreaterThan(0); } }