@Override public void saveMenuItem(String groupName, MenuItemDescription item) throws MenuServiceException { Map<String, List<MenuItemDescription>> items = listMenuItems(); addToMap(groupName, item, items); writeMenuItems(items); }
@Override public void saveMenuItem(String groupName, MenuItemDescription item) throws MenuServiceException { Map<String, List<MenuItemDescription>> items = listMenuItems(); addToMap(groupName, item, items); writeMenuItems(items); }
@Override public void deleteMenuItem(String groupName, MenuItemDescription item) throws MenuServiceException { Map<String, List<MenuItemDescription>> items = listMenuItems(); removeFromMap(groupName, item, items); writeMenuItems(items); }
@Override public void deleteMenuItem(String groupName, MenuItemDescription item) throws MenuServiceException { Map<String, List<MenuItemDescription>> items = listMenuItems(); removeFromMap(groupName, item, items); writeMenuItems(items); }
@Test public void testListItemsOK() throws Exception { FSMenuService service = new FSMenuService(); Map<String, List<MenuItemDescription>> items = service.listMenuItems(); assertNotNull("items shouldn't be null", items); assertFalse("items shouldn't be empty", items.isEmpty()); for (String key : items.keySet()) { assertNotNull("items of key " + key + " shouldn't be null", items.get(key)); assertFalse("items of key " + key + " shouldn't be empty", items.get(key).isEmpty()); } } @Test
@Test public void testListItemsOK() throws Exception { FSMenuService service = new FSMenuService(); Map<String, List<MenuItemDescription>> items = service.listMenuItems(); assertNotNull("items shouldn't be null", items); assertFalse("items shouldn't be empty", items.isEmpty()); for (String key : items.keySet()) { assertNotNull("items of key " + key + " shouldn't be null", items.get(key)); assertFalse("items of key " + key + " shouldn't be empty", items.get(key).isEmpty()); } } @Test
private void abstractTestListItemsProblem(final Class<?> exceptionType) throws Exception { FSMenuService service = createMockedService(exceptionType); try { service.listMenuItems(); fail("listOptions shouldn't succeed"); } catch (MenuServiceException e) { assertNotNull("e shouldn't be null", e); Throwable cause = e.getCause(); assertNotNull("cause shouldn't be null", cause); assertTrue("cause should be a " + exceptionType.getName(), cause.getClass().equals(exceptionType)); } } @Test
private void abstractTestListItemsProblem(final Class<?> exceptionType) throws Exception { FSMenuService service = createMockedService(exceptionType); try { service.listMenuItems(); fail("listOptions shouldn't succeed"); } catch (MenuServiceException e) { assertNotNull("e shouldn't be null", e); Throwable cause = e.getCause(); assertNotNull("cause shouldn't be null", cause); assertTrue("cause should be a " + exceptionType.getName(), cause.getClass().equals(exceptionType)); } } @Test
@Test public void testListItemsEncodingProblem() throws Exception { FSMenuService service = createMockedService(null); FormRepresentationDecoder decoder = EasyMock.createMock(FormRepresentationDecoder.class); FormEncodingFactory.register(FormEncodingFactory.getEncoder(), decoder); FormEncodingException exception = new FormEncodingException("Something going wrong"); EasyMock.expect(decoder.decodeMenuItemsMap(EasyMock.anyObject(String.class))).andThrow(exception).once(); EasyMock.replay(decoder); try { service.listMenuItems(); fail("listOptions shouldn't succeed"); } catch (MenuServiceException e) { assertNotNull("e shouldn't be null", e); Throwable cause = e.getCause(); assertNotNull("cause shouldn't be null", cause); assertTrue("cause should be a FormEncodingException", cause instanceof FormEncodingException); } EasyMock.verify(decoder); } @Test
@Test public void testListItemsEncodingProblem() throws Exception { FSMenuService service = createMockedService(null); FormRepresentationDecoder decoder = EasyMock.createMock(FormRepresentationDecoder.class); FormEncodingFactory.register(FormEncodingFactory.getEncoder(), decoder); FormEncodingException exception = new FormEncodingException("Something going wrong"); EasyMock.expect(decoder.decodeMenuItemsMap(EasyMock.anyObject(String.class))).andThrow(exception).once(); EasyMock.replay(decoder); try { service.listMenuItems(); fail("listOptions shouldn't succeed"); } catch (MenuServiceException e) { assertNotNull("e shouldn't be null", e); Throwable cause = e.getCause(); assertNotNull("cause shouldn't be null", cause); assertTrue("cause should be a FormEncodingException", cause instanceof FormEncodingException); } EasyMock.verify(decoder); } @Test