private void selectCorrespondingText(final String text) { double score = 0; WebElement optionToSelect = null; for (WebElement option : options) { String source = option.getText(); if (service.score(source, text) > score) { score = service.score(source, text); optionToSelect = option; } } if (optionToSelect != null) { setSelected(optionToSelect); } else { throw new NoSuchElementException("Cannot locate option with corresponding text " + text); } }
crowdinCommands.add(COMMAND_PULL); for (String cmd : crowdinCommands) { s = service.score(cmd, command); if (s > score) { score = s;
@ReplayOnError public void deselectByCorrespondingText(final String text) { if (!isMultiple()) { throw new UnsupportedOperationException("You may only deselect all options of a multi-select"); } try { findElement(); double score = 0; WebElement optionToSelect = null; for (WebElement option : options) { String source = option.getText(); if (service.score(source, text) > score) { score = service.score(source, text); optionToSelect = option; } } if (optionToSelect != null) { setDeselected(optionToSelect); } else { throw new NoSuchElementException("Cannot locate option with corresponding text " + text); } } finally { finalizeAction(); } }
@Test public void testScore() { SimilarityStrategy strategy = mock(SimilarityStrategy.class); String target = "McDonalds"; String c1 = "MacMahons"; String c2 = "McPherson"; String c3 = "McDonalds"; when(strategy.score(c1, target)).thenReturn(0.90); when(strategy.score(c2, target)).thenReturn(0.74); when(strategy.score(c3, target)).thenReturn(1.000); StringSimilarityService service = new StringSimilarityServiceImpl(strategy); double score = service.score(c1, target); verify(strategy).score(c1, target); assertEquals(0.90, score, 0.000); }