CategoriesService extends ConfigurationService<Categories> { public void addRuleByName(String name, MatchRule matchRule) { Categories categories = retrieve(); Category category = findCategoryByName(categories, name); List<Category> values = new ArrayList<>(categories.getCategories()); int indexOf = values.indexOf(category); values.set(indexOf, category.withMatchRule(matchRule)); update(new Categories(values)); } @Inject  CategoriesService(CategoriesPersistenceService persistenceService, EntityEventSupport eventSupport); void create(Category category); void deleteByName(String name); void addRuleByName(String name, MatchRule matchRule);  }
@Test public void addRuleByNameNotFound() { thrown.expect(ValidationException.class); thrown.expectMessage("Category name must be specified."); categoriesService.addRuleByName(" ", MatchRule.withPattern("yo")); }
@Test public void addRuleByName() { MatchRule matchRule = MatchRule.withPattern("yo"); categoriesService.addRuleByName("a", matchRule); Category category = savedCategories.getCategoryByName("a"); assertEquals(ImmutableList.of(matchRule), category.getMatchRules()); }