### Question:
DecorationServiceImpl implements DecorationService { @Override public List<Decoration<?>> getDecorations(ProjectEntity entity) { Function<Decorator, Stream<Decoration<?>>> securedDecoratorFunction = securityService.runner( decorator -> getDecorations(entity, decorator).stream() ); return extensionManager.getExtensions(DecorationExtension.class) .stream() .filter(decorator -> decorator.getScope().contains(entity.getProjectEntityType())) .flatMap(securedDecoratorFunction) .collect(Collectors.toList()); } @Autowired  DecorationServiceImpl(ExtensionManager extensionManager, SecurityService securityService); @Override List<Decoration<?>> getDecorations(ProjectEntity entity);  }### Answer:
@Test public void error_decoration_generates_default_error_decoration() { ProjectEntity projectEntity = mock(ProjectEntity.class); DecorationExtension decorator = mock(DecorationExtension.class); when(decorator.getDecorations(any(ProjectEntity.class))).thenThrow(new RuntimeException("Error while generating the decoration")); ExtensionManager extensionManager = mock(ExtensionManager.class); when(extensionManager.getExtensions(DecorationExtension.class)).thenReturn( Collections.singletonList(decorator) ); SecurityService securityService = mock(SecurityService.class); DecorationServiceImpl service = new DecorationServiceImpl(extensionManager, securityService); @SuppressWarnings("unchecked") List<? extends Decoration> decorations = service.getDecorations(projectEntity, decorator); assertNotNull(decorations); assertEquals(1, decorations.size()); Decoration decoration = decorations.get(0); assertNull(decoration.getData()); assertEquals("Problem while getting decoration", decoration.getError()); }
@Test public void base_exception_decoration_generates_default_error_decoration() { ProjectEntity projectEntity = mock(ProjectEntity.class); DecorationExtension decorator = mock(DecorationExtension.class); when(decorator.getDecorations(any(ProjectEntity.class))).thenThrow(new TestBaseException()); ExtensionManager extensionManager = mock(ExtensionManager.class); when(extensionManager.getExtensions(DecorationExtension.class)).thenReturn( Collections.singletonList(decorator) ); SecurityService securityService = mock(SecurityService.class); DecorationServiceImpl service = new DecorationServiceImpl(extensionManager, securityService); @SuppressWarnings("unchecked") List<? extends Decoration> decorations = service.getDecorations(projectEntity, decorator); assertNotNull(decorations); assertEquals(1, decorations.size()); Decoration decoration = decorations.get(0); assertEquals("Known exception", decoration.getError()); assertNull(decoration.getData()); }