Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,12 @@ class UnitConverter {
* @param sourceUnit a source unit supported by requested converter
* @param targetUnit a target unit supported by requested converter
* @return an instance of converter, or {@literal null} if {@code sourceUnit} is {@literal null}
* or empty, which means that there is no conversion needed.
* @throws IllegalArgumentException if {@code targetUnit} is empty, or matching converter was not
* found for provided units.
* or empty or if {@code targetUnit} is empty, which means that there is no conversion needed.
* @throws IllegalArgumentException if matching converter was not found for provided units.
*/
@Nullable
public static UnitConverter getInstance(@Nullable String sourceUnit, String targetUnit) {
if (targetUnit.isEmpty()) {
throw new IllegalArgumentException("Non empty targetUnit must be provided");
}

if (sourceUnit == null || sourceUnit.isEmpty()) {
if (sourceUnit == null || sourceUnit.isEmpty() || targetUnit.isEmpty()) {
// No conversion is needed
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

package io.opentelemetry.instrumentation.jmx.engine;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -58,10 +58,11 @@ void shouldHandleUnsupportedConversion(String sourceUnit, String targetUnit) {
@CsvSource({
", s", // null -> "s"
"'', s", // "" -> "s"
"1, ''", // empty target unit
})
void shouldSkipConversionWhenSourceUnitNotSpecified(String sourceUnit, String targetUnit) {
UnitConverter converter = UnitConverter.getInstance(sourceUnit, targetUnit);
assertNull(converter);
assertThat(converter).isNull();
}

@Test
Expand Down
Loading