demo.org.powermock.examples.tutorial.partialmocking.service.impl.withoutpowermock
Class ProviderServiceWithoutPowerMockImpl

java.lang.Object
  extended by demo.org.powermock.examples.tutorial.partialmocking.service.impl.withoutpowermock.ProviderServiceWithoutPowerMockImpl
All Implemented Interfaces:
ProviderService

public class ProviderServiceWithoutPowerMockImpl
extends Object
implements ProviderService

We've slightly refactored the ProviderService to make the class easier to test without PowerMock. What we've done is to use constructor injection for the providerDao instead of field injection. We've also refactored the getAllServiceProducers() method to be protected instead of private.

Note no refactoring is actually needed to test this method without PowerMock, everything PowerMock does in this case can be done manually using reflection. It's however common to do this refactoring instead of using too much reflection in the test code.


Constructor Summary
ProviderServiceWithoutPowerMockImpl(ProviderDao providerDao)
           
 
Method Summary
protected  Set<ServiceProducer> getAllServiceProducers()
           
 Set<ServiceProducer> getAllServiceProviders()
          Get all service provider.
 ServiceProducer getServiceProvider(int id)
          Get a service provider.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProviderServiceWithoutPowerMockImpl

@Inject
public ProviderServiceWithoutPowerMockImpl(ProviderDao providerDao)
Method Detail

getAllServiceProviders

public Set<ServiceProducer> getAllServiceProviders()
Get all service provider.

Specified by:
getAllServiceProviders in interface ProviderService
Returns:
All service provider artifacts currently available or an empty set if no service providers are available.

getServiceProvider

public ServiceProducer getServiceProvider(int id)
Get a service provider.

Specified by:
getServiceProvider in interface ProviderService
Parameters:
id - The id of the service provider to get.
Returns:
The service artifact that represents the service provider or null if no Service Producer was found with that id.

getAllServiceProducers

protected Set<ServiceProducer> getAllServiceProducers()


Copyright © 2007-2012. All Rights Reserved.