Posts

Null pointer exception when stubbing a method

/#-----------Null pointer exception when stubbing a method. check the syntax of your stub //# for me it was  doReturn(responseEntity).when(rhpp.invokeDownStreamService(apiRequestService, traceId)); // this variable needs some other values to be set like url and good status ....use reflection api to set this field variables. Follow this link to understand partial Mocking. https://stackoverflow.com/questions/14970516/use-mockito-to-mock-some-methods-but-not-others Also understand difference between doReturn.when vs When.thenReturn. To directly answer your question, yes, you can mock some methods without mocking others. This is called a partial mock. See the Mockito documentation on partial mocks for more information. For your example, you can do something like the following, in your test: Stock stock = mock(Stock.class); when(stock.getPrice()).thenReturn(100.00);    // Mock implementation when(stock.getQuantity()).thenReturn(200);    // Mock implementation when(st...

Maven Command line

  C:\locationOfMave\apache-maven-3.3.9\bin\mvn -e --settings C:\apache-maven-3.6.2-bin\apache-maven-3.6.2\conf\settings.xml clean install -Dcheckstyle.skip=true -e flag is for debug -Dchekstyle is to skip syntax check. If run into maven issues try changing Maven local repository path to a new directory and retry.

the project cannot be built until its prerequisite is built - Eclipse

Identify the prerequisite project that needs to be rebuilt. if Clean and Build all option doesn't work  try below.... 1. Close the Project 2. Open the Project 3. Build the Project.

Java - how to make log4j to write to the console as well

Your log4j File should look something like below. Read comments at the beginning of each key-value pair for more details. # Define the types of logger and level of logging log4j . rootLogger = DEBUG , console , FILE # Define the File appender log4j . appender . FILE = org . apache . log4j . FileAppender # Define Console Appender log4j . appender . console = org . apache . log4j . ConsoleAppender # Define the layout for console appender . If you do not # define it , you will get an error log4j . appender . console . layout = org . apache . log4j . PatternLayout # Set the name of the file log4j . appender . FILE . File = log . out # Set the immediate flush to true ( default ) log4j . appender . FILE . ImmediateFlush = true # Set the threshold to debug mode log4j . appender . FILE . Threshold = debug # Set the append to false , overwrite log4j . appender . FILE . Append = false # Define t...