### Question:
ElasticsearchUtils { public static boolean amIMasterNode(IConfiguration config, HttpModule httpModule) throws Exception { String URL = httpModule.findMasterNodeURL(); String response = SystemUtils.runHttpGetCommand(URL); if (config.isDebugEnabled()) { logger.debug("Calling {} returned: {}", URL, response); } response = StringUtils.trim(response); if (StringUtils.isEmpty(response)) { logger.error("Response from " + URL + " is empty"); return false; } if (response.equalsIgnoreCase(config.getHostIP()) || response.equalsIgnoreCase(config.getHostLocalIP())) { return true; } return false; }  @SuppressWarnings("unchecked") static JSONObject transformRaigadInstanceToJson(List<RaigadInstance> instances); static List<RaigadInstance> getRaigadInstancesFromJson(JSONObject instances); static boolean amIMasterNode(IConfiguration config, HttpModule httpModule); static List<String> getAvailableSnapshots(Client transportClient, String repositoryName); static String getS3RepositoryName(); static String formatDate(DateTime dateTime, String dateFormat);  }### Answer:
@Test public void TestAmIMasterNode(@Mocked IConfiguration config) throws Exception { String expectedIp = "100.0.0.1"; new Expectations() { { config.getHostIP(); result = expectedIp; times = 1; config.getHostLocalIP(); times = 0; } }; new MockUp<SystemUtils>() { @Mock String runHttpGetCommand(String url) { return expectedIp; } }; Assert.assertTrue(ElasticsearchUtils.amIMasterNode(config, new HttpModule(config))); }
@Test public void TestAmIMasterNodeWithWhitespace(@Mocked IConfiguration config) throws Exception { String expectedIp = "100.0.0.1"; new Expectations() { { config.getHostIP(); result = expectedIp; times = 1; config.getHostLocalIP(); times = 0; } }; new MockUp<SystemUtils>() { @Mock String runHttpGetCommand(String url) { return expectedIp + " \n "; } }; Assert.assertTrue(ElasticsearchUtils.amIMasterNode(config, new HttpModule(config))); }
@Test public void TestAmIMasterNodeExternalIp(@Mocked IConfiguration config) throws Exception { String expectedLocalIp = "100.0.0.1"; String expectedExternalIp = "54.0.0.1"; new Expectations() { { config.getHostIP(); result = expectedExternalIp; times = 1; config.getHostLocalIP(); result = expectedLocalIp; times = 1; } }; new MockUp<SystemUtils>() { @Mock String runHttpGetCommand(String url) { return expectedLocalIp; } }; Assert.assertTrue(ElasticsearchUtils.amIMasterNode(config, new HttpModule(config))); }
@Test public void TestAmIMasterNodeNegative(@Mocked IConfiguration config) throws Exception { String expectedIp = "100.0.0.1"; String returnedIp = "100.0.0.2"; new Expectations() { { config.getHostIP(); result = expectedIp; times = 1; config.getHostLocalIP(); result = expectedIp; times = 1; } }; new MockUp<SystemUtils>() { @Mock String runHttpGetCommand(String url) { return returnedIp; } }; Assert.assertFalse(ElasticsearchUtils.amIMasterNode(config, new HttpModule(config))); }
@Test public void TestAmIMasterNodeNegativeNull(@Mocked IConfiguration config) throws Exception { new Expectations() { { config.getHostIP(); times = 0; config.getHostLocalIP(); times = 0; } }; new MockUp<SystemUtils>() { @Mock String runHttpGetCommand(String url) { return null; } }; Assert.assertFalse(ElasticsearchUtils.amIMasterNode(config, new HttpModule(config))); }
@Test public void TestAmIMasterNodeNegativeEmpty(@Mocked IConfiguration config) throws Exception { new Expectations() { { config.getHostIP(); times = 0; config.getHostLocalIP(); times = 0; } }; new MockUp<SystemUtils>() { @Mock String runHttpGetCommand(String url) { return ""; } }; Assert.assertFalse(ElasticsearchUtils.amIMasterNode(config, new HttpModule(config))); }