MetricsService { public List<MetricsHistogram> getClientRequestLatencies(Node host) throws ReaperException { return clusterFacade.getClientRequestLatencies(host); } private  MetricsService(AppContext context, Supplier<ClusterFacade> clusterFacadeSupplier); static MetricsService create(AppContext context); List<ThreadPoolStat> getTpStats(Node host); List<DroppedMessages> getDroppedMessages(Node host); List<MetricsHistogram> getClientRequestLatencies(Node host); List<GenericMetric> convertToGenericMetrics(Map<String, List<JmxStat>> jmxStats, Node node);  }
@Test public void testGetClientRequestLatencies() throws InterruptedException, ReaperException, JMException, IOException, ClassNotFoundException { AppContext cxt = new AppContext(); ClusterFacade clusterFacadeMock = Mockito.mock(ClusterFacade.class); Mockito.when(clusterFacadeMock.getClientRequestLatencies(any())).thenReturn(Collections.EMPTY_LIST); cxt.config = new ReaperApplicationConfiguration(); cxt.config.setJmxConnectionTimeoutInSeconds(10); cxt.jmxConnectionFactory = mock(JmxConnectionFactory.class); JmxProxy jmx = (JmxProxy) mock(Class.forName("io.cassandrareaper.jmx.JmxProxyImpl")); when(cxt.jmxConnectionFactory.connectAny(any(Collection.class))).thenReturn(jmx); MBeanServerConnection serverConn = mock(MBeanServerConnection.class); JmxProxyTest.mockGetMBeanServerConnection(jmx, serverConn); when(serverConn.queryNames(Mockito.any(ObjectName.class), Mockito.isNull())).thenReturn(Collections.emptySet()); Node node = Node.builder().withHostname("127.0.0.1").build(); MetricsService.create(cxt, () -> clusterFacadeMock).getClientRequestLatencies(node); Mockito.verify(clusterFacadeMock, Mockito.times(1)).getClientRequestLatencies(Mockito.any()); }