java - Testing Twitter4J with PowerMock -
i'm trying mock following code using powermock
twitter twitter = twitterfactory.getsingleton(); requesttoken requesttoken = twitter.getoauthrequesttoken();
here start of unit test
@runwith(powermockrunner.class) @preparefortest(twitterfactory.class) public class authorisationhelpertest { @test public void testmain() throws twitterexception { // arrange powermockito.mockstatic(twitterfactory.class); twitter mocktwitter = new twitter(); mockito.when(twitterfactory.getsingleton()).thenreturn(mocktwitter);
however error saying cannot instantiate type twitter. figure must thinking wrong way. tips?
here's how declare , instantiate new instance of twitter
object:
twitter twitter = twitterfactory.getsingleton();
if cannot instantiate twitter
class, likelihood has non-visible constructor, , ever possible via factory.
what want supply mock of twitter
instead.
twitter twitter = mock(twitter.class);
Comments
Post a Comment