Categories { public Category getCategoryByName(String name) { for (Category category : getCategories()) { if (category.getName().equalsIgnoreCase(name.trim())) { return category; } } return null; } Categories();  Categories(List<Category> categories); List<Category> getCategories(); Category getCategoryByName(String name);  }
@Test public void foo() { Category category1 = new Category("a"); Category category2 = new Category("b"); Categories categories = new Categories(ImmutableList.of(category1, category2)); assertNull(categories.getCategoryByName("nope")); assertEquals(category1, categories.getCategoryByName("a")); assertEquals(category1, categories.getCategoryByName("A")); }