5
5
6
6
package io .opentelemetry .instrumentation .jmx .engine .unit ;
7
7
8
- import static org .assertj .core .api .Assertions .assertThat ;
8
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
9
9
import static org .junit .jupiter .api .Assertions .assertEquals ;
10
10
import static org .junit .jupiter .api .Assertions .assertFalse ;
11
11
import static org .junit .jupiter .api .Assertions .assertNull ;
12
- import static org .junit .jupiter .api .Assertions .assertThrows ;
13
12
import static org .junit .jupiter .api .Assertions .assertTrue ;
14
13
15
14
import org .junit .jupiter .api .Test ;
@@ -48,7 +47,7 @@ void shouldSupportPredefined_to_s_Converters(
48
47
}
49
48
50
49
@ Test
51
- void shouldSupportCustomConverter () {
50
+ void shouldRegisterConverter () {
52
51
// Given
53
52
String sourceUnit = "MB" ;
54
53
String targetUnit = "By" ;
@@ -71,12 +70,8 @@ void shouldSupportCustomConverter() {
71
70
"non-existing, s" ,
72
71
})
73
72
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" );
80
75
}
81
76
82
77
@ ParameterizedTest
@@ -93,23 +88,15 @@ void shouldSkipConversionWhenSourceUnitNotSpecified(String sourceUnit, String ta
93
88
@ CsvSource ({
94
89
"'', By" , "By, ''" ,
95
90
})
96
- void shouldThrowExceptionWhenRegisteringConverterWithAnyUnitEmpty (
91
+ void shouldNotAllowRegisteringConverterWithAnyUnitEmpty (
97
92
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" );
105
95
}
106
96
107
97
@ Test
108
98
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" );
114
101
}
115
102
}
0 commit comments