Source:
<code>public void testDefaultSelectionWithOnlyOneResult() throws Exception { final IBlockingCondition bc = Jobs.getJobManager().createBlockingCondition("loadProposals", true); PropertyChangeListener bcListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (IContentAssistFieldLookupRowFetcher.PROP_SEARCH_RESULT.equals(evt.getPropertyName())) { bc.setBlocking(false); } } }; <START> m_form.getStyleField().getLookupRowFetcher().addPropertyChangeListener(bcListener); <END> m_form.getStyleField().getUIFacade().openProposalChooserFromUI("*", false); bc.waitFor(); assertTrue(m_form.getStyleField().isProposalChooserRegistered()); bc.setBlocking(true); m_form.getStyleField().getLookupRowFetcher().addPropertyChangeListener(bcListener); m_form.getStyleField().getUIFacade().proposalTypedFromUI("Y"); bc.waitFor(); assertTrue(m_form.getStyleField().isProposalChooserRegistered()); TableProposalChooser<?> tableProposalChooser = (TableProposalChooser<?>) m_form.getStyleField().getProposalChooser(); IContentAssistFieldTable<?> resultTable = tableProposalChooser.getModel(); assertEquals(1, resultTable.getSelectedRowCount()); assertEquals(1, resultTable.getRowCount()); ILookupRow<?> expectedLookupRow = resultTable.getSelectedLookupRow(); tableProposalChooser.execResultTableRowClicked(resultTable.getRow(0)); assertEquals("Yellow", m_form.getStyleField().getDisplayText()); assertEquals(Long.valueOf(20L), m_form.getStyleField().getValue()); assertNotNull(m_form.getStyleField().getCurrentLookupRow()); assertEquals(expectedLookupRow, m_form.getStyleField().getCurrentLookupRow()); }</code><technical_language>Please avoid duplicate code in test. E.g. extract method PropertyChangeListener getUnblockOnSearchResultListener(final IBlockingCondition bc) in test</technical_language>

Target:
public void testDefaultSelectionWithOnlyOneResult() throws Exception { IBlockingCondition bc = Jobs.getJobManager().createBlockingCondition("loadProposals", true); PropertyChangeListener bcListener = getUnblockOnSearchResultListener(bc); m_form.getStyleField().getLookupRowFetcher().addPropertyChangeListener(bcListener); m_form.getStyleField().getUIFacade().openProposalChooserFromUI("*", false); bc.waitFor(); bc.setBlocking(true); m_form.getStyleField().getLookupRowFetcher().addPropertyChangeListener(bcListener); m_form.getStyleField().getUIFacade().proposalTypedFromUI("Y"); bc.waitFor(); assertTrue(m_form.getStyleField().isProposalChooserRegistered()); TableProposalChooser<?> tableProposalChooser = (TableProposalChooser<?>) m_form.getStyleField().getProposalChooser(); IContentAssistFieldTable<?> resultTable = tableProposalChooser.getModel(); assertEquals(1, resultTable.getSelectedRowCount()); assertEquals(1, resultTable.getRowCount()); ILookupRow<?> expectedLookupRow = resultTable.getSelectedLookupRow(); tableProposalChooser.execResultTableRowClicked(resultTable.getRow(0)); assertEquals("Yellow", m_form.getStyleField().getDisplayText()); assertEquals(Long.valueOf(20L), m_form.getStyleField().getValue()); assertNotNull(m_form.getStyleField().getCurrentLookupRow()); assertEquals(expectedLookupRow, m_form.getStyleField().getCurrentLookupRow()); }