@Test public void one_arg_constructor_sets_up_instance_as_expected() { // given Supplier<Timer> timerSupplier = mock(Supplier.class); // when EndpointMetricsHandlerDefaultImpl newImpl = new EndpointMetricsHandlerDefaultImpl(timerSupplier); // then assertThat(newImpl.requestTimerGenerator).isSameAs(timerSupplier); }
endpointMetricsHandler = new EndpointMetricsHandlerDefaultImpl();
@Test public void default_constructor_sets_up_instance_as_expected() { // when EndpointMetricsHandlerDefaultImpl newImpl = new EndpointMetricsHandlerDefaultImpl(); // then assertThat(newImpl.requestTimerGenerator) .isSameAs(EndpointMetricsHandlerDefaultImpl.DEFAULT_REQUEST_TIMER_GENERATOR); }
@Test public void setupEndpointsMetrics_throws_IllegalArgumentException_if_metricRegistry_is_null() { // given EndpointMetricsHandlerDefaultImpl newImpl = new EndpointMetricsHandlerDefaultImpl(); // when Throwable ex = catchThrowable(() -> newImpl.setupEndpointsMetrics(serverConfig, null)); // then assertThat(ex) .isInstanceOf(IllegalArgumentException.class) .hasMessage("MetricRegistry cannot be null"); }
@Test public void setupEndpointsMetrics_throws_IllegalArgumentException_if_serverConfig_is_null() { // given EndpointMetricsHandlerDefaultImpl newImpl = new EndpointMetricsHandlerDefaultImpl(); // when Throwable ex = catchThrowable(() -> newImpl.setupEndpointsMetrics(null, metricRegistryMock)); // then assertThat(ex) .isInstanceOf(IllegalArgumentException.class) .hasMessage("ServerConfig cannot be null"); }
@Test public void createAndRegisterRequestTimer_should_use_requestTimerGenerator() { // given Timer timerMock = mock(Timer.class); Supplier<Timer> timerSupplier = () -> timerMock; EndpointMetricsHandlerDefaultImpl newImpl = new EndpointMetricsHandlerDefaultImpl(timerSupplier); // when Timer result = newImpl.createAndRegisterRequestTimer("foo", metricRegistryMock); // then assertThat(result).isSameAs(timerMock); }
public void setupEndpointsMetrics_sets_up_metrics_as_expected(boolean customizeTimerCreation) { EndpointMetricsHandlerDefaultImpl newImpl = spy(new EndpointMetricsHandlerDefaultImpl()); String expectedTimerPrefix = customizeTimerCreation ? UUID.randomUUID().toString() + newImpl.prefix
@Before public void beforeMethod() { instance = spy(new EndpointMetricsHandlerDefaultImpl());