NamedQueryManager { public void addNamedQuery(String name, String query) { Objects.requireNonNull(name); Objects.requireNonNull(query); if (queryMap.containsKey(name)) { throw new IllegalArgumentException("Query with name " + name + " already exists in this persistence unit."); } queryMap.put(name, query); }  void addNamedQuery(String name, String query); String getQuery(String name);  }
@Test public void addingQueryWithExistingNameThrowsIllegalArgument() { final String name = "selectAll"; thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Query with name " + name + " already exists in this persistence unit."); queryManager.addNamedQuery(name, QUERY); queryManager.addNamedQuery(name, "TEST"); }