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 7831577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:47:28+00:00 2026-06-02T11:47:28+00:00

I have a couple of classes: StateProcessor and State . I want to write

  • 0

I have a couple of classes: StateProcessor and State.
I want to write a test for the method StateProcessor.process(State).
The logic of this method is pretty simple, but it contains a lot of logging messages.

logger.info(state.getSourse().toString());
if (state.getTarget() == Target.A) {
 logger.info(state.getCreationTime());
 service.doSmth(state);
} else {
 logger.info(state.getTagret().getName());
 service.doOtherStff(state);
}

I don’t want to pass the real State instance to the process method because this class is really complicated and it takes a lot of lines of code to build it. So, I want to pass mock object created with Mockito. According to the main logic, I need to mock only getTarget() method. But the execution will fail with NPE at state.getTagret().getName() and at state.getSourse().toString(). But I don’t like the idea of mocking all of these methods! They used only for logging. Also I don’t want to fix my tests every time when I add some logging messages.

Logging is really useful there, so I don’t want to remove it at all. But mocking the methods only for logging looks strange.

How I can solve this issue?

  • 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-06-02T11:47:30+00:00Added an answer on June 2, 2026 at 11:47 am

    Consider Mocking DEEP. This will result in each method call returning a mock instead of null and prevent the NPEs.

     Foo mock = mock(Foo.class, RETURNS_DEEP_STUBS);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ok I have couple of .NET classes that I want to use in VBA.
I have a couple of classes (for this example anyway) that use code first
If I have a couple of classes like this ; public class Employee {
I have a couple classes that look like this public class ParentClass { public
I have a couple Java classes which have blackbox test cases that just exercise
I have couple of helper methods added to the existing classes, and i want
I have a couple of classes that want to pass each other some information
I have a couple of packages I have trouble naming. This package contains classes
I have a couple of questions relating to nested classes within Java. How do
I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code

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.