JCRSChooser { public static CoordinateReferenceSystem showDialog() { return showDialog(null); } private  JCRSChooser(); static CoordinateReferenceSystem showDialog(); static CoordinateReferenceSystem showDialog(final String title); static CoordinateReferenceSystem showDialog(final String title, 
            final String initialCode); static CoordinateReferenceSystem showDialog(final String title, 
            final String initialCode, 
            final String authority); static final String DEFAULT_AUTHORITY; static final String DEFAULT_TITLE; }
@Test public void checkDefaultDialogIsSetupCorrectly() throws Exception { showDialog(); ((DialogFixture) windowFixture).requireModal(); assertEquals(JCRSChooser.DEFAULT_TITLE, windowFixture.component().getTitle()); JTextComponentFixture textBox = windowFixture.textBox(); assertNotNull(textBox); textBox.requireEditable(); textBox.requireText(""); JListFixture list = windowFixture.list(); assertNotNull(list); list.requireItemCount(CODES.size()); }
@Test public void customTitle() throws Exception { final String TITLE = "Custom title"; showDialog(TITLE); assertEquals(TITLE, windowFixture.component().getTitle()); }
@Test public void cancellingDialogReturnsNull() throws Exception { Future<CoordinateReferenceSystem> future = showDialog(); JButtonFixture button = getButton("Cancel"); button.click(); CoordinateReferenceSystem crs = retrieveCRS(future); assertNull(crs); }
@Test public void okButtonDisabledInitially() throws Exception { showDialog(); windowFixture.list().requireNoSelection(); getButton("OK").requireDisabled(); }
@Test public void okButtonEnabledWhenListHasSelection() throws Exception { showDialog(); windowFixture.list().clickItem(0); windowFixture.robot.waitForIdle(); getButton("OK").requireEnabled(); }
@Test public void okButtonStateWithListSize() throws Exception { showDialog(); JButtonFixture button = getButton("OK"); JTextComponentFixture textBox = windowFixture.textBox(); textBox.enterText(UNIQUE_FILTER_STRING); windowFixture.robot.waitForIdle(); button.requireEnabled(); textBox.deleteText(); windowFixture.robot.waitForIdle(); windowFixture.list().requireNoSelection(); button.requireDisabled(); }
@Test public void okButtonDisabledWhenListSelectionIsCleared() throws Exception { showDialog(); JListFixture list = windowFixture.list(); list.clickItem(0); windowFixture.robot.waitForIdle(); list.clearSelection(); windowFixture.robot.waitForIdle(); getButton("OK").requireDisabled(); }
@Test public void unmatchedFilterTextEmptiesListAndDisablesOKButton() throws Exception { showDialog(); windowFixture.textBox().enterText("FooBar"); windowFixture.robot.waitForIdle(); windowFixture.list().requireItemCount(0); getButton("OK").requireDisabled(); }
@Test public void filterByCode() throws Exception { showDialog(); JListFixture list = windowFixture.list(); final String code = getRandomCode().toLowerCase(); windowFixture.textBox().enterText(code); windowFixture.robot.waitForIdle(); String[] items = list.contents(); for (String item : items) { assertTrue(item.toLowerCase().contains(code)); } }
@Test public void filterByNameFragment() throws Exception { showDialog(); JListFixture list = windowFixture.list(); final int FILTER_STRING_LEN = 5; String filterStr = null; while (filterStr == null) { String code = getRandomCode(); String desc = FACTORY.getDescriptionText( JCRSChooser.DEFAULT_AUTHORITY + ":" + code).toString(); if (desc != null && desc.length() >= FILTER_STRING_LEN) { filterStr = desc.substring(0, FILTER_STRING_LEN).toLowerCase(); } } windowFixture.textBox().enterText(filterStr); windowFixture.robot.waitForIdle(); for (String item : list.contents()) { assertTrue(item.toLowerCase().contains(filterStr)); } }
@Test public void selectInListAndClickOKButton() throws Exception { Future<CoordinateReferenceSystem> future = showDialog(); final int index = rand.nextInt(CODES.size()); windowFixture.list().clickItem(index); windowFixture.robot.waitForIdle(); getButton("OK").click(); windowFixture.robot.waitForIdle(); CoordinateReferenceSystem crs = retrieveCRS(future); assertNotNull(crs); CoordinateReferenceSystem expected = FACTORY.createCoordinateReferenceSystem( JCRSChooser.DEFAULT_AUTHORITY + ":" + CODES.get(index)); assertTrue(CRS.equalsIgnoreMetadata(expected, crs)); }