MapStructAbstractGateway implements Gateway<DE, AP> { public DE add(AP payload) { Preconditions.checkNotNull(payload); HE hibernateEntity = domainAddPayloadToHibernateEntityConverter.convert(payload); dao.create(hibernateEntity); return hibernateEntityToDomainEntityConverter.convert(hibernateEntity); } protected  MapStructAbstractGateway(
            Converter<AP, HE> domainAddPayloadToHibernateEntityConverter,
            Merger<DE, HE> domainEntityToHibernateEntityMerger,
            Converter<HE, DE> hibernateEntityToDomainEntityConverter,
            Converter<List<HE>, List<DE>> hibernateEntitiesToDomainEntitiesConverter,
            D dao
    ); DE add(AP payload); @Override List<DE> getAll(); @Override DE findById(String id); @Override DE save(String id, DE entity);  }
@Test public void whenAdd() { TestDomainAddPayload domainAddPayload = mock(TestDomainAddPayload.class); TestHibernateEntity hibernateEntity = mock(TestHibernateEntity.class); when(domainAddPayloadToHibernateEntityConverter.convert(domainAddPayload)).thenReturn(hibernateEntity); TestDomainEntity domainEntity = mock(TestDomainEntity.class); when(hibernateEntityToDomainEntityConverter.convert(hibernateEntity)).thenReturn(domainEntity); TestDomainEntity actual = gateway.add(domainAddPayload); verify(dao).create(hibernateEntity); verifyNoMoreInteractions(dao); assertThat(actual).isSameAs(domainEntity); }
@Test public void whenAddNullPayload() throws Exception { try { gateway.add(null); failBecauseExceptionWasNotThrown(NullPointerException.class); } catch (NullPointerException npe) { verifyZeroInteractions(dao); } }