mardi 31 mars 2020

Issue in writing junit test case for NullPointerException for private methods

The function template is

private static void processTextFile(String iFile, String tmpDirLoc, String tmpDrive, String iMode)

I want to test for NullPointerException in case when iFile is null. Since the original method processTextFile is Private in nature, so I am using reflection in my test case to access the method but I can't write the test case for AssertThrows condition. please help me writing this.

this is my code

    @Test()
    public void TC1_processTextFileTest() {
    Method method = crashParser.class.getDeclaredMethod("left",String.class,int.class);
    method.setAccessible(true);
    crashParser cp = new crashParser();
    String ifile=null;
    //cp.processTextFile(ifile,null,null,null);
    //NullPointerException ex= assertThrows(NullPointerException.class,()-> 
   //cp.processTextFile(ifile,null,null,null));
    //assertEquals("Array can't be null",ex.getMessage());
   }




Aucun commentaire:

Enregistrer un commentaire