Source:
public void testSuccessRangerDumpMetrics() throws Exception { Logger logger = Mockito.mock(Logger.class); Whitebox.setInternalState(ReplState.class, logger); RangerExportPolicyList rangerPolicyList = new RangerExportPolicyList(); rangerPolicyList.setPolicies(new ArrayList<RangerPolicy>()); Mockito.when(mockClient.exportRangerPolicies(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(rangerPolicyList); Mockito.when(conf.getVar(REPL_AUTHORIZATION_PROVIDER_SERVICE_ENDPOINT)).thenReturn("rangerEndpoint"); Mockito.when(conf.getVar(REPL_RANGER_SERVICE_NAME)).thenReturn("cm_hive"); Mockito.when(work.getDbName()).thenReturn("testdb"); Mockito.when(work.getCurrentDumpPath()).thenReturn(new Path("/tmp")); int status = task.execute(); Assert.assertEquals(0, status); ArgumentCaptor<String> replStateCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<Object> eventCaptor = ArgumentCaptor.forClass(Object.class); ArgumentCaptor<Object> eventDetailsCaptor = ArgumentCaptor.forClass(Object.class); Mockito.verify(logger, Mockito.times(2)).info(replStateCaptor.capture(), eventCaptor.capture(), eventDetailsCaptor.capture()); Assert.assertEquals("REPL::{}: {}", replStateCaptor.getAllValues().get(0)); Assert.assertEquals("RANGER_DUMP_START", eventCaptor.getAllValues().get(0)); Assert.assertEquals("RANGER_DUMP_END", eventCaptor.getAllValues().get(1)); Assert.assertTrue(eventDetailsCaptor.getAllValues().get(0) .toString().contains("{\"dbName\":\"testdb\",\"dumpStartTime")); Assert.assertTrue(eventDetailsCaptor .getAllValues().get(1).toString().contains("{\"dbName\":\"testdb\",\"actualNumPolicies\":0,\"dumpEndTime\"")); }

Target:
public void testSuccessRangerDumpMetrics() throws Exception { Logger logger = Mockito.mock(Logger.class); Whitebox.setInternalState(ReplState.class, logger); RangerExportPolicyList rangerPolicyList = new RangerExportPolicyList(); rangerPolicyList.setPolicies(new ArrayList<RangerPolicy>()); Mockito.when(mockClient.exportRangerPolicies(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(rangerPolicyList); Mockito.when(conf.getVar(REPL_AUTHORIZATION_PROVIDER_SERVICE_ENDPOINT)).thenReturn("rangerEndpoint"); Mockito.when(conf.getVar(REPL_RANGER_SERVICE_NAME)).thenReturn("hive"); Mockito.when(work.getDbName()).thenReturn("testdb"); Mockito.when(work.getCurrentDumpPath()).thenReturn(new Path("/tmp")); int status = task.execute(); Assert.assertEquals(0, status); ArgumentCaptor<String> replStateCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<Object> eventCaptor = ArgumentCaptor.forClass(Object.class); ArgumentCaptor<Object> eventDetailsCaptor = ArgumentCaptor.forClass(Object.class); Mockito.verify(logger, Mockito.times(2)).info(replStateCaptor.capture(), eventCaptor.capture(), eventDetailsCaptor.capture()); Assert.assertEquals("REPL::{}: {}", replStateCaptor.getAllValues().get(0)); Assert.assertEquals("RANGER_DUMP_START", eventCaptor.getAllValues().get(0)); Assert.assertEquals("RANGER_DUMP_END", eventCaptor.getAllValues().get(1)); Assert.assertTrue(eventDetailsCaptor.getAllValues().get(0) .toString().contains("{\"dbName\":\"testdb\",\"dumpStartTime")); Assert.assertTrue(eventDetailsCaptor .getAllValues().get(1).toString().contains("{\"dbName\":\"testdb\",\"actualNumPolicies\":0,\"dumpEndTime\"")); }