use of jakarta.servlet.ServletConfig in project metrics by dropwizard.
the class MetricsServletTest method constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig.
@Test
public void constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig() throws Exception {
final MetricRegistry metricRegistry = mock(MetricRegistry.class);
final ServletContext servletContext = mock(ServletContext.class);
final ServletConfig servletConfig = mock(ServletConfig.class);
when(servletConfig.getServletContext()).thenReturn(servletContext);
final io.dropwizard.metrics.servlets.MetricsServlet metricsServlet = new io.dropwizard.metrics.servlets.MetricsServlet(metricRegistry);
metricsServlet.init(servletConfig);
verify(servletConfig, times(1)).getServletContext();
verify(servletContext, never()).getAttribute(eq(io.dropwizard.metrics.servlets.MetricsServlet.METRICS_REGISTRY));
}
use of jakarta.servlet.ServletConfig in project metrics by dropwizard.
the class MetricsServletTest method constructorWithRegistryAsArgumentUsesServletConfigWhenNull.
@Test
public void constructorWithRegistryAsArgumentUsesServletConfigWhenNull() throws Exception {
final MetricRegistry metricRegistry = mock(MetricRegistry.class);
final ServletContext servletContext = mock(ServletContext.class);
final ServletConfig servletConfig = mock(ServletConfig.class);
when(servletConfig.getServletContext()).thenReturn(servletContext);
when(servletContext.getAttribute(eq(io.dropwizard.metrics.servlets.MetricsServlet.METRICS_REGISTRY))).thenReturn(metricRegistry);
final io.dropwizard.metrics.servlets.MetricsServlet metricsServlet = new io.dropwizard.metrics.servlets.MetricsServlet(null);
metricsServlet.init(servletConfig);
verify(servletConfig, times(1)).getServletContext();
verify(servletContext, times(1)).getAttribute(eq(io.dropwizard.metrics.servlets.MetricsServlet.METRICS_REGISTRY));
}
Aggregations