Note that there are some explanatory texts on larger screens.

plurals
  1. POMockito Mocked Class returns Null
    primarykey
    data
    text
    <p>I am using Mockito to mock a class in my JUnit test class as follows:</p> <pre><code>@Before public void initialize(){ DescribeHiveTable mockObj = Mockito.mock(DescribeHiveTable.class); String tableName = "clslog_assessments"; String parentDirectoryPath ="src/test/resources/TEST18/RunFiles"; String[] mockFeaturesArray1 = {"user_id","event_id"}; ArrayList&lt;String&gt; mockFeaturesList1 = new ArrayList&lt;String&gt; (Arrays.asList(mockFeaturesArray1)); when(mockObj.describeTable(tableName, parentDirectoryPath)).thenReturn(mockFeaturesList1); </code></pre> <p>Then I have my Test method, which subsequently calls the <code>describeTable</code> method from within. I checked that the arguments: <code>tableName</code> and <code>parentDirectoryPath</code> when <code>describeTable</code> is being called are same as those I have defined in the initalize method. </p> <p>However, I still get a null return value. I don't understand this behavior. Maybe I'm not using Mockito correctly?</p> <p><strong>EDIT</strong></p> <p>My Test method is something like:</p> <pre><code>@Test public void testComplexFeaturesExistingRun() { String[] args = {masterConfigPath, runFilesPath, rootDir}; DriverClass driver = new DriverClass(); driver.main(args); } </code></pre> <p>So driver.main calls the describeTable method, whose behavior I'm trying to mock.</p> <p><strong>EDIT 2</strong></p> <p>My describe hive table class is :</p> <pre><code>public class DescribeHiveTable { public ArrayList&lt;String&gt; describeTable(String tableName, String parentDirectoryPath){ String hiveQuery = "'describe " + tableName + "';"; String bashScriptFile = parentDirectoryPath + "/describeTable.sh"; . . . final Process process = builder.start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while((line=br.readLine())!=null) { String[] output = line.split("\t"); columnList.add(output[0]); } return columnList; </code></pre> <p>This is how I'm calling describe table:</p> <pre><code>DescribeHiveTable describeTable; describeTable = new DescribeHiveTable(); ArrayList&lt;String&gt; columnList = describeTable.describeTable(tableName, runFile.getParent()); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload