Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7622073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:21:38+00:00 2026-05-31T04:21:38+00:00

I am trying to mock a class like so (thank’s google for code design

  • 0

I am trying to mock a class like so (thank’s google for code design that’s difficult to use in a test environment):

GoogleAuthorizationCodeGrant googleAuthorizationCodeGrant = EasyMock.createMock(GoogleAuthorizationCodeGrant.class);

Then I am setting up a mock method call like this:

AccessTokenResponse accessTokenResponse = new AccessTokenResponse();
EasyMock.expect(googleAuthorizationCodeGrant.execute()).andReturn(accessTokenResponse);

Yet it spews an exception, because during googleAuthorizationCodeGrant.execute() it tries to run the actual code in GoogleAuthorizationCodeGrant.execute(). Am I missing something here? I would expect the cglib proxy to wrap this class and override it’s methods to do nothing, as I don’t want their implementation when mocking. There should be no need for any of the business logic to remain, as I am defining the behaviour of the various method calls.

Edit

Note – I think there is some confusion here. The exception is thrown on:

EasyMock.expect(googleAuthorizationCodeGrant.execute()).andReturn(accessTokenResponse)

Not when I put the mock in replay mode, as I never actually reach that code. The reason the exception is thrown is because a member of GoogleAuthorizationCodeGrant is null, and a method is invoked on it on .execute(). The member would not be null had I instantiated GoogleAuthorizationCodeGrant with the new operator. However I do not understand why EasyMock would work like this on a class because I would expect it to create a proxy which wraps the implementation to do nothing.

Here is a stack trace:

java.lang.NullPointerException
at com.google.api.client.auth.oauth2.draft10.AccessTokenRequest.executeUnparsed(AccessTokenRequest.java:451)
at com.google.api.client.auth.oauth2.draft10.AccessTokenRequest.execute(AccessTokenRequest.java:475)
at uk.co.domain.service.google.GmailContactPollerTest.testDoPoll(GmailContactPollerTest.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:21:39+00:00Added an answer on May 31, 2026 at 4:21 am

    I am not sure whether you replayed back that mocked instance. If you have already done that and still getting the exception please put the stack trace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use mock to verify that an index property has been set.
I'm trying to use the MoqAutoMocker class that comes with StructureMap and I can't
Im trying to mock a method that is ineherited from a parent class that
I'm trying to use FakeItEasy to mock an object that is a member of
I'm trying to use groovy's MockFor and proxyDelegateInstance to mock a java class with
I am trying to mock java.awt.Toolkit.beep() using JMockit Expectations. I have the following code
I am trying to Mock an object that is being passed into another object,
I'm trying to create a mock HttpContextBase for unit test. var fakePrinciple = new
I am trying to use Rhino Mocks to mock the following lambda, but keep
I'm trying to use Rhinomocks 3.5 and the new lambda notation to mock some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.