SearchHandler { public Category compareMatches(Category setting, Category group, Category category, int settingMatch, int groupMatch, int categoryMatch) { LOGGER.trace(String.format("compareMatches: settingMatch: %s, groupMatch: %s, " + "categoryMatch: %s", settingMatch, groupMatch, categoryMatch)); if (settingMatch == 0 && groupMatch == 0 && categoryMatch == 0) { return null; } else if (settingMatch == groupMatch && settingMatch == categoryMatch) { return setting; } else if (settingMatch == 1) { return setting; } else if (groupMatch == 1) { return group; } else if (categoryMatch == 1) { return category; } else if (settingMatch != 0 && groupMatch == 0 && categoryMatch == 0) { return setting; } else if (settingMatch == 0 && groupMatch != 0 && categoryMatch == 0) { return group; } else if (settingMatch == 0 && groupMatch == 0 && categoryMatch != 0) { return category; } else if (settingMatch == 0) { if (categoryMatch < groupMatch) { return category; } else { return group; } } else if (groupMatch == 0) { if (settingMatch <= categoryMatch) { return setting; } else { return category; } } else if (categoryMatch == 0) { if (groupMatch < settingMatch) { return group; } else { return setting; } } else if (settingMatch <= groupMatch && settingMatch <= categoryMatch) { return setting; } else if (groupMatch <= categoryMatch) { return group; } return category; }  void init(
      PreferencesFxModel model,
      StringProperty searchText,
      ObjectProperty<Predicate<Category>> predicateProperty
  ); void initializeSearchText(StringProperty searchText); void bindFilterPredicate(ObjectProperty<Predicate<Category>> predicateProperty); void updateSearch(String searchText); Category compareMatches(Category setting, Category group, Category category,
                                 int settingMatch, int groupMatch, int categoryMatch); Category getCategoryMatch(); ReadOnlyObjectProperty<Category> categoryMatchProperty();  }
@Test public void compareMatches() { Category setting = mock(Category.class); Category group = mock(Category.class); Category category = mock(Category.class); int[] matches1 = {0, 0, 0, 0, 0, 0, 2, 2, 2, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3}; int[] matches2 = {0, 2, 3, 0, 3, 0, 0, 2, 3, 0, 2, 3, 0, 3, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 2, 0, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 2, 3, 0, 2, 3, 0, 2, 3, 0, 3, 0, 3}; int[] matches3 = {1, 1, 1, 2, 2, 3, 1, 1, 1, 1, 1, 1, 2, 2, 0, 0, 0, 1, 2, 2, 3, 3, 3, 0, 1, 2, 3, 0, 0, 1, 2, 2, 3, 3, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 0, 0, 0, 2, 2, 2, 3, 3, 3, 0, 0, 3, 3}; Object[] expected = {category, category, category, category, category, category, category, category, category, category, category, category, category, category, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, group, null, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting, setting}; for (int i = 0; i < matches1.length; i++) { assertSame( "match1: " + matches1[i] + ", match2: " + matches2[i] + ", match3: " + matches3[i], expected[i], searchHandler.compareMatches(setting, group, category, matches1[i], matches2[i], matches3[i]) ); } }