### Question:
HadoopConfUtil { public static String getUserNameInConf(Configuration jobConf) throws IllegalArgumentException { String userName = jobConf.get(Constants.USER_CONF_KEY_HADOOP2); if (StringUtils.isBlank(userName)) { userName = jobConf.get(Constants.USER_CONF_KEY); if (StringUtils.isBlank(userName)) { throw new IllegalArgumentException(" Found neither " + Constants.USER_CONF_KEY + " nor " + Constants.USER_CONF_KEY_HADOOP2); } } return userName; }  static String getUserNameInConf(Configuration jobConf); static boolean contains(Configuration jobConf, String name); static String getQueueName(Configuration jobConf);  }### Answer:
@Test public void testGetUserNameInConf() throws FileNotFoundException { final String JOB_CONF_FILE_NAME = "src/test/resources/job_1329348432655_0001_conf.xml"; Configuration jobConf = new Configuration(); jobConf.addResource(new FileInputStream(JOB_CONF_FILE_NAME)); String userName = HadoopConfUtil.getUserNameInConf(jobConf); assertEquals(userName, "user"); }
@Test(expected=IllegalArgumentException.class) public void checkUserNameAlwaysSet() throws FileNotFoundException { final String JOB_CONF_FILE_NAME = "src/test/resources/job_1329348432655_0001_conf.xml"; Configuration jobConf = new Configuration(); jobConf.addResource(new FileInputStream(JOB_CONF_FILE_NAME)); jobConf.set(Constants.USER_CONF_KEY_HADOOP2, ""); jobConf.set(Constants.USER_CONF_KEY, ""); String hRavenUserName = HadoopConfUtil.getUserNameInConf(jobConf); assertNull(hRavenUserName); }