DefaultFacade implements Facade<RESOURCE, RESOURCELIST, KEY> { @Override public RESOURCE createResource(final RESOURCE resource) { LOG.info("Creating resource: {}", resource); ENTITY entity = resourceConverter.convert(resource); insertConverter.convert(resource, entity); service.createEntity(entity); return entityConverter.convert(entity); }  @Override RESOURCE createResource(final RESOURCE resource); @Override RESOURCE getResource(final KEY id); @Override void removeResource(final KEY id); @Override void updateResource(final KEY id, final RESOURCE resource); @Override PagedResultResource<RESOURCE> getResources(final PagedRequest<RESOURCELIST> request); @Required void setService(final SERVICE service); @Required void setResourceConverter(final Converter<RESOURCE, ENTITY> resourceConverter); @Required void setEntityConverter(final Converter<ENTITY, RESOURCE> entityConverter); @Required void setPagedRequestConverter(final Converter<PagedRequest<RESOURCELIST>, MultiplePagedSearch<ENTITYLIST>> pagedRequestConverter); @Required void setPagedResultConverter(final Converter<PagedResult<ENTITY>, PagedResultResource<RESOURCE>> pagedResultConverter); @Required void setInsertConverter(final Converter<RESOURCE, ENTITY> insertConverter); @Required void setEntityDetailsConverter(final Converter<ENTITY, RESOURCE> entityDetailsConverter); SERVICE getService(); Converter<ENTITY, RESOURCE> getEntityDetailsConverter(); void setUpdateConverter(final Converter<RESOURCE, ENTITY> updateConverter); Converter<RESOURCE, ENTITY> getResourceConverter(); Converter<ENTITY, RESOURCE> getEntityConverter(); Converter<PagedRequest<RESOURCELIST>, MultiplePagedSearch<ENTITYLIST>> getPagedRequestConverter(); Converter<PagedResult<ENTITY>, PagedResultResource<RESOURCE>> getPagedResultConverter(); Converter<RESOURCE, ENTITY> getInsertConverter(); Converter<RESOURCE, ENTITY> getUpdateConverter(); Converter<RESOURCELIST, ENTITYLIST> getResourceListConverter(); void setResourceListConverter(final Converter<RESOURCELIST, ENTITYLIST> resourceListConverter);  }
@Test public void testCreateEntity() throws Exception { String name = "LightMan"; Long personTypeId = 25L; PersonResource expected = new PersonResource(); expected.setBegDate(new Date()); expected.setEndDate(new Date()); expected.setName(name); expected.setPersonTypeId(personTypeId); PersonType personType = new PersonType(); Person person = new Person(); person.setBegDate(new Date()); person.setEndDate(new Date()); person.setName(name); person.setPersonType(personType); when(resourceConverter.convert(any(PersonResource.class))).thenReturn(person); when(entityConverter.convert(any(Person.class))).thenReturn(expected); PersonResource actual = unit.createResource(expected); verify(resourceConverter).convert(expected); verify(service).createEntity(person); verify(insertConverter).convert(expected, person); assertEquals(expected, actual); }