Skip to content

Commit b9f2052

Browse files
committed
Unit test improvements
1 parent 8f481f3 commit b9f2052

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

instrumentation/jmx-metrics/library/src/test/java/io/opentelemetry/instrumentation/jmx/engine/unit/UnitConverterFactoryTest.java

+9-22
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
package io.opentelemetry.instrumentation.jmx.engine.unit;
77

8-
import static org.assertj.core.api.Assertions.assertThat;
8+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
99
import static org.junit.jupiter.api.Assertions.assertEquals;
1010
import static org.junit.jupiter.api.Assertions.assertFalse;
1111
import static org.junit.jupiter.api.Assertions.assertNull;
12-
import static org.junit.jupiter.api.Assertions.assertThrows;
1312
import static org.junit.jupiter.api.Assertions.assertTrue;
1413

1514
import org.junit.jupiter.api.Test;
@@ -48,7 +47,7 @@ void shouldSupportPredefined_to_s_Converters(
4847
}
4948

5049
@Test
51-
void shouldSupportCustomConverter() {
50+
void shouldRegisterConverter() {
5251
// Given
5352
String sourceUnit = "MB";
5453
String targetUnit = "By";
@@ -71,12 +70,8 @@ void shouldSupportCustomConverter() {
7170
"non-existing, s",
7271
})
7372
void shouldHandleNonExistingConverter(String sourceUnit, String targetUnit) {
74-
IllegalArgumentException exception =
75-
assertThrows(
76-
IllegalArgumentException.class,
77-
() -> UnitConverterFactory.getConverter(sourceUnit, targetUnit));
78-
assertEquals(
79-
"No [" + sourceUnit + "] to [" + targetUnit + "] unit converter", exception.getMessage());
73+
assertThatThrownBy(() -> UnitConverterFactory.getConverter(sourceUnit, targetUnit))
74+
.hasMessage("No [" + sourceUnit + "] to [" + targetUnit + "] unit converter");
8075
}
8176

8277
@ParameterizedTest
@@ -93,23 +88,15 @@ void shouldSkipConversionWhenSourceUnitNotSpecified(String sourceUnit, String ta
9388
@CsvSource({
9489
"'', By", "By, ''",
9590
})
96-
void shouldThrowExceptionWhenRegisteringConverterWithAnyUnitEmpty(
91+
void shouldNotAllowRegisteringConverterWithAnyUnitEmpty(
9792
String sourceUnit, String targetUnit) {
98-
IllegalArgumentException exception =
99-
assertThrows(
100-
IllegalArgumentException.class,
101-
() ->
102-
UnitConverterFactory.registerConverter(
103-
sourceUnit, targetUnit, (value) -> 0, false));
104-
assertThat(exception.getMessage()).matches("Non empty .+Unit must be provided");
93+
assertThatThrownBy(() -> UnitConverterFactory.registerConverter(sourceUnit, targetUnit, (value) -> 0, false))
94+
.hasMessageMatching("Non empty .+Unit must be provided");
10595
}
10696

10797
@Test
10898
void shouldNotAllowRegisteringAgainAlreadyExistingConverter() {
109-
IllegalArgumentException exception =
110-
assertThrows(
111-
IllegalArgumentException.class,
112-
() -> UnitConverterFactory.registerConverter("ms", "s", (v) -> 0, false));
113-
assertEquals("Converter from [ms] to [s] already registered", exception.getMessage());
99+
assertThatThrownBy(() -> UnitConverterFactory.registerConverter("ms", "s", (v) -> 0, false))
100+
.hasMessage("Converter from [ms] to [s] already registered");
114101
}
115102
}

0 commit comments

Comments
 (0)