demo.org.powermock.examples.tutorial.domainmocking.impl.withoutpowermock
Class SampleServiceWithoutPowerMockImpl

java.lang.Object
  extended by demo.org.powermock.examples.tutorial.domainmocking.impl.withoutpowermock.SampleServiceWithoutPowerMockImpl
All Implemented Interfaces:
SampleService

public class SampleServiceWithoutPowerMockImpl
extends Object
implements SampleService

This is a simple service that delegates calls to two stub services. The purpose of this service is to demonstrate that need to refactor the production code in order to make it unit-testable if PowerMock is not used. Note that there's no need to refactor the class if PowerMock had been used.


Constructor Summary
SampleServiceWithoutPowerMockImpl(PersonService personService, EventService eventService)
          Creates a new instance of the SampleServiceImpl with the following collaborators.
 
Method Summary
 boolean createPerson(String firstName, String lastName)
          Create a new person based on the following parameters and store it in the underlying persistence store.
protected  BusinessMessages getNewBusinessMessagesInstance()
          In order to test this class without PowerMock we need to create a new protected method whose only purpose is to create a new instance of a BusinessMessage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SampleServiceWithoutPowerMockImpl

public SampleServiceWithoutPowerMockImpl(PersonService personService,
                                         EventService eventService)
Creates a new instance of the SampleServiceImpl with the following collaborators.

Parameters:
personService - The person service to use.
eventService - The event service to use.
Method Detail

createPerson

public boolean createPerson(String firstName,
                            String lastName)
Create a new person based on the following parameters and store it in the underlying persistence store. The service will notify the result of the operation to an event service.

Specified by:
createPerson in interface SampleService
Parameters:
firstName - The first name of the person to create.
lastName - The last name of the person to create.
Returns:
true if the person was created successfully, false otherwise.

getNewBusinessMessagesInstance

protected BusinessMessages getNewBusinessMessagesInstance()
In order to test this class without PowerMock we need to create a new protected method whose only purpose is to create a new instance of a BusinessMessage. This means that we can utilize partial mocking to override this method in our test and have it return a mock.

Returns:
A new instance of a BusinessMessages object.


Copyright © 2007-2012. All Rights Reserved.