DDMDataProviderInvokerImpl implements DDMDataProviderInvoker { protected Optional<DDMDataProviderInstance> fetchDDMDataProviderInstanceOptional( String ddmDataProviderInstanceId) throws PortalException { DDMDataProviderInstance ddmDataProviderInstance = ddmDataProviderInstanceService.fetchDataProviderInstanceByUuid( ddmDataProviderInstanceId); if ((ddmDataProviderInstance == null) && Validator.isNumber(ddmDataProviderInstanceId)) { ddmDataProviderInstance = ddmDataProviderInstanceService.fetchDataProviderInstance( Long.valueOf(ddmDataProviderInstanceId)); } return Optional.ofNullable(ddmDataProviderInstance); }  @Override DDMDataProviderResponse invoke(
		DDMDataProviderRequest ddmDataProviderRequest);  }
@Test public void testFetchDataProviderNotFound() throws Exception { DDMDataProviderInvokerImpl ddmDataProviderInvokerImpl = new DDMDataProviderInvokerImpl(); DDMDataProviderInstanceService ddmDataProviderInstanceService = mock( DDMDataProviderInstanceService.class); ddmDataProviderInvokerImpl.ddmDataProviderInstanceService = ddmDataProviderInstanceService; when( ddmDataProviderInstanceService.fetchDataProviderInstanceByUuid( "test") ).thenReturn( null ); Optional<DDMDataProviderInstance> optional = ddmDataProviderInvokerImpl.fetchDDMDataProviderInstanceOptional( "test"); Assert.assertFalse(optional.isPresent()); }
@Test public void testFetchDDMDataProviderInstance1() throws Exception { DDMDataProviderInvokerImpl ddmDataProviderInvokerImpl = new DDMDataProviderInvokerImpl(); DDMDataProviderInstanceService ddmDataProviderInstanceService = mock( DDMDataProviderInstanceService.class); ddmDataProviderInvokerImpl.ddmDataProviderInstanceService = ddmDataProviderInstanceService; Optional<DDMDataProviderInstance> optional = ddmDataProviderInvokerImpl.fetchDDMDataProviderInstanceOptional( "1"); Assert.assertFalse(optional.isPresent()); Mockito.verify( ddmDataProviderInstanceService, Mockito.times(1) ).fetchDataProviderInstanceByUuid( "1" ); Mockito.verify( ddmDataProviderInstanceService, Mockito.times(1) ).fetchDataProviderInstance( 1 ); }
@Test public void testFetchDDMDataProviderInstance2() throws Exception { DDMDataProviderInvokerImpl ddmDataProviderInvokerImpl = new DDMDataProviderInvokerImpl(); DDMDataProviderInstanceService ddmDataProviderInstanceService = mock( DDMDataProviderInstanceService.class); ddmDataProviderInvokerImpl.ddmDataProviderInstanceService = ddmDataProviderInstanceService; DDMDataProviderInstance ddmDataProviderInstance = mock( DDMDataProviderInstance.class); when( ddmDataProviderInstanceService.fetchDataProviderInstance(1) ).thenReturn( ddmDataProviderInstance ); Optional<DDMDataProviderInstance> optional = ddmDataProviderInvokerImpl.fetchDDMDataProviderInstanceOptional( "1"); Assert.assertTrue(optional.isPresent()); Mockito.verify( ddmDataProviderInstanceService, Mockito.times(1) ).fetchDataProviderInstanceByUuid( "1" ); Mockito.verify( ddmDataProviderInstanceService, Mockito.times(1) ).fetchDataProviderInstance( 1 ); }