mocking - Testing Pull Subscription in Java EWS API using PowerMockito -


i have function processes events obtained pullsubscription microsoft exchange.

public void processevents(exchangeservice service, pullsubscription subscription)             throws exception {     geteventsresults events = subscription.getevents();     // loop through item-related events.     (itemevent itemevent : events.getitemevents()) {         if (itemevent.geteventtype() == eventtype.newmail) {             emailmessage message = emailmessage.bind(service, itemevent.getitemid());             emailparser emailparser = new emailparser();             emailparser.parse(message, service);         }     } } 

i trying test using powermockito because exchangeservice final class. have mocked exchangeservice , pullsubscription follows:

exchangeservice servicemock = powermockito.mock(exchangeservice.class); pullsubscription subscriptionmock = powermockito.mock(pullsubscription.class);  @test public void startpullnotification() throws exception {     processemails pr = new processemails("config.properties");     pr.startpullnotification(servicemock); } 

when i'm trying test using following code throws nullpointerexception because subscription.getevents() returns null (i.e. subscriptionmock has no events in it).

i tried stubbing mocking eventresults has returned:

when(subscriptionmock.getevents()).thenreturn(eventresultsmock); 

it doesn't work since getevents() not called in test function. wanted know how test function?

http://archive.msdn.microsoft.com/ewsjavaapi

solution:

i had mock every object being created in function. also, had add following above class declaration.

@runwith(powermockrunner.class) @preparefortest({ classbeingtested.class }) 


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -