@Test public void two_arg_constructor_fails_with_IllegalArgumentException_if_metricRegistry_is_null() { // given SignalFxReporterFactory reporterFactoryMock = mock(SignalFxReporterFactory.class); wireUpReporterFactoryMockForConstructor(reporterFactoryMock, metricRegistryMock); // when Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(reporterFactoryMock, null)); // then assertThat(ex).isInstanceOf(IllegalArgumentException.class) .hasMessage("MetricRegistry cannot be null"); }
@Test public void three_arg_constructor_fails_with_IllegalArgumentException_if_reportingFrequency_is_null() { // given SignalFxReporter reporterMock = mock(SignalFxReporter.class); wireUpReporterForConstructor(reporterMock); // when Throwable ex = catchThrowable( () -> new SignalFxEndpointMetricsHandler(reporterMock, null, metricRegistryMock) ); // then assertThat(ex).isInstanceOf(IllegalArgumentException.class) .hasMessage("reportingFrequency cannot be null"); }
private Pair<Pair<SignalFxReporter, MetricMetadata>, Pair<Long, TimeUnit>> wireUpReporterFactoryMockForConstructor( SignalFxReporterFactory factoryMock, MetricRegistry expectedMetricRegistry ) { SignalFxReporter reporterMock = mock(SignalFxReporter.class); doReturn(reporterMock).when(factoryMock).getReporter(expectedMetricRegistry); MetricMetadata metricMetadataMock = wireUpReporterForConstructor(reporterMock); long reportingInterval = 42; TimeUnit reportingTimeUnit = TimeUnit.DAYS; doReturn(reportingInterval).when(factoryMock).getInterval(); doReturn(reportingTimeUnit).when(factoryMock).getTimeUnit(); return Pair.of(Pair.of(reporterMock, metricMetadataMock), Pair.of(reportingInterval, reportingTimeUnit)); }
@DataProvider(value = { "true | false", "false | true" }, splitBy = "\\|") @Test public void two_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null( boolean amountIsNull, boolean timeUnitIsNull ) { // given SignalFxReporterFactory reporterFactoryMock = mock(SignalFxReporterFactory.class); wireUpReporterFactoryMockForConstructor(reporterFactoryMock, metricRegistryMock); if (amountIsNull) doReturn(null).when(reporterFactoryMock).getInterval(); if (timeUnitIsNull) doReturn(null).when(reporterFactoryMock).getTimeUnit(); // when Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(reporterFactoryMock, metricRegistryMock)); // then if (amountIsNull) { assertThat(ex).isInstanceOf(IllegalArgumentException.class) .hasMessage("reportingFrequency amount cannot be null"); } if (timeUnitIsNull) { assertThat(ex).isInstanceOf(IllegalArgumentException.class) .hasMessage("reportingFrequency TimeUnit cannot be null"); } }
@Test public void three_arg_constructor_fails_with_IllegalArgumentException_if_metricRegistry_is_null() { // given SignalFxReporter reporterMock = mock(SignalFxReporter.class); wireUpReporterForConstructor(reporterMock); // when Throwable ex = catchThrowable( () -> new SignalFxEndpointMetricsHandler(reporterMock, Pair.of(42L, TimeUnit.DAYS), null) ); // then assertThat(ex).isInstanceOf(IllegalArgumentException.class) .hasMessage("metricRegistry cannot be null"); }
@Test public void two_arg_constructor_sets_fields_as_expected() { // given SignalFxReporterFactory reporterFactoryMock = mock(SignalFxReporterFactory.class); Pair<Pair<SignalFxReporter, MetricMetadata>, Pair<Long, TimeUnit>> wiredUpMocksAndData = wireUpReporterFactoryMockForConstructor(reporterFactoryMock, metricRegistryMock); MetricMetadata expectedMetricMetadata = wiredUpMocksAndData.getLeft().getRight(); long expectedReportingInterval = wiredUpMocksAndData.getRight().getLeft(); TimeUnit expectedReportingTimeUnit = wiredUpMocksAndData.getRight().getRight(); // when SignalFxEndpointMetricsHandler instance = new SignalFxEndpointMetricsHandler(reporterFactoryMock, metricRegistryMock); // then assertThat(instance.metricMetadata).isSameAs(expectedMetricMetadata); assertThat(instance.metricRegistry).isSameAs(metricRegistryMock); assertThat(instance.requestTimerBuilder).isInstanceOf(RollingWindowTimerBuilder.class); RollingWindowTimerBuilder rwtb = (RollingWindowTimerBuilder) instance.requestTimerBuilder; assertThat(rwtb.amount).isEqualTo(expectedReportingInterval); assertThat(rwtb.timeUnit).isEqualTo(expectedReportingTimeUnit); assertThat(instance.requestTimerDimensionConfigurator) .isSameAs(DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR); }
@DataProvider(value = { "true | false", "false | true" }, splitBy = "\\|") @Test public void three_arg_constructor_fails_with_IllegalArgumentException_if_reporting_frequency_args_are_null( boolean amountIsNull, boolean timeUnitIsNull ) { // given SignalFxReporter reporterMock = mock(SignalFxReporter.class); wireUpReporterForConstructor(reporterMock); Long amount = (amountIsNull) ? null : 42L; TimeUnit timeUnit = (timeUnitIsNull) ? null : TimeUnit.DAYS; // when Throwable ex = catchThrowable( () -> new SignalFxEndpointMetricsHandler(reporterMock, Pair.of(amount, timeUnit), metricRegistryMock) ); // then if (amountIsNull) { assertThat(ex).isInstanceOf(IllegalArgumentException.class) .hasMessage("reportingFrequency amount cannot be null"); } if (timeUnitIsNull) { assertThat(ex).isInstanceOf(IllegalArgumentException.class) .hasMessage("reportingFrequency TimeUnit cannot be null"); } }
@Test public void three_arg_constructor_sets_fields_as_expected() { // given SignalFxReporter reporterMock = mock(SignalFxReporter.class); MetricMetadata expectedMetricMetadata = wireUpReporterForConstructor(reporterMock); Pair<Long, TimeUnit> reportingFrequency = Pair.of(42L, TimeUnit.DAYS); // when SignalFxEndpointMetricsHandler instance = new SignalFxEndpointMetricsHandler(reporterMock, reportingFrequency, metricRegistryMock); // then assertThat(instance.metricMetadata).isSameAs(expectedMetricMetadata); assertThat(instance.metricRegistry).isSameAs(metricRegistryMock); assertThat(instance.requestTimerBuilder).isInstanceOf(RollingWindowTimerBuilder.class); RollingWindowTimerBuilder rwtb = (RollingWindowTimerBuilder) instance.requestTimerBuilder; assertThat(rwtb.amount).isEqualTo(reportingFrequency.getLeft()); assertThat(rwtb.timeUnit).isEqualTo(reportingFrequency.getRight()); assertThat(instance.requestTimerDimensionConfigurator) .isSameAs(DEFAULT_REQUEST_LATENCY_TIMER_DIMENSION_CONFIGURATOR); }