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

  • Home
  • SEARCH
  • 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 4619768
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:28:09+00:00 2026-05-22T02:28:09+00:00

I have the following interface CatalogVersionService which exposes some services. As well I have

  • 0

I have the following interface CatalogVersionService which exposes some services. As well I have a unit test which mocks this interface by using Mockito like this:

CatalogVersionService catalogVersionService  = Mockito.mock(CatalogVersionService.class);

And injects the catalogVersionService in a resolver implementation named DefaultClassificationClassResolverService like this:

((DefaultClassificationClassResolverService) ccrservice).setCatalogVersionService(catalogVersionService);

// Assert that my resolver will find a single ClassificationClassModel object
ClassificationClassModel single = new ClassificationClassModel();
        assertTrue(ccrservice.resolve(single).contains(single)); //resolver

Up to that point everything works fine until I try to create an integration test and get rid of the Mocked CatalogVersionService interface. As far as I am aware Mockito.mock creates a mock object of given class or interface, in this case CatalogVersionService which is implemented by DefaultCatalogVersionService. So when I try to obtain the real object I do something like this:

catalogVersionService = new DefaultCatalogVersionService();
((DefaultClassificationClassResolverService) ccrservice).setCatalogVersionService(catalogVersionService);

However, after that point is where I get a null pointer exception and my resolver test of course fails. So what does Mockito.mock actually do?? Is it a good approach to assume:

CatalogVersionService catalogVersionService  = Mockito.mock(CatalogVersionService.class);
// IS EQUIVALENT TO:
catalogVersionService = new DefaultCatalogVersionService();

Any ideas why the assert is failing?

Thanks in advance

  • 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-22T02:28:09+00:00Added an answer on May 22, 2026 at 2:28 am

    No, it is incorrect to assume that Mockito.mock(...) is the same as instantiating an instance of your DefaultCatalogVersionService. This is not what mocks do.

    If you are getting a NullPointerException when using the concrete DefaultCatalogVersionService, this would suggest that something is null within the DefaultCatalogVersionService!

    Have you examined the stacktrace to see at what line the NullPointerException occurs, which would help you determine which property/field is null?

    It’s more than likely that your DefaultCatalogVersionService depends on other classes, which you are not wiring up in your test.

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

Sidebar

Related Questions

I have the following interface that returns the generic parameter of type T using
I have this following interface : public interface FruitDetails { public String getFruitName(); }
I have the following interface which I'm trying to make COM-visible. When I try
I'm using Google Guice for dependency injection. Suppose I have the following: public interface
I have the following interface method on which I am applying @PreAuthoriz e :
I'm using dependency injection and have the following interface: public interface IAchievement : IEquatable<IAchievement>
I have the following interface: interface MySortedCollection<T extends Comparable<T>> { boolean isElement(T t); void
I have the following interface defined to expose a .NET class to COM: [InterfaceType(ComInterfaceType.InterfaceIsDual)]
I have the following interface: public interface IPlateSubCategory<T> { T GetItem(int plateID); } And
I have the following interface declarations: interface IOrder<T> where T: IOrderItem { IList<T> Items

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.