0

I am new to Unit testing and using Mockito framework.

I have a Java class and have the main() method in it. In my Main() method I have several other methods that I need to Unit test.

This is my class to test

public class client{
  public static void main(String[] args) {
         Ip ip  =  createIpEvent();
   .
   .
   .
   }
   private static Ip createIpEvent(){
    Ip ip = new Ip();
    ip.setters(); // various setters
    return ip;
    }
 }

This is my Test class that I am making.

public class clientTest{
  
 client clientMock = mock(client.class);
 
 @Test
 public void testCreateIpEvent(){
  Ip ip = new Ip();

  //setters....
  try(MockedStatic<client> utils = Mockito.mockStatic(client.class)){
        utils.when(() -> client.main()....)
    //here I am only able to access the main() method and not the method createIpEvent()

 }


}

Please some one help me out on this.

1 Answers1

0

Your createIpEvent() method is private. Check out this question to get a better understanding of access specifiers.

Lais Bento
  • 13
  • 4
  • actually I have found something that by using powermock we can mock the static and private methods, but I am not able to get it. – aakash gilotra Jan 02 '22 at 19:31
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 03 '22 at 02:06