fix: handle Null Dereference in UnitsConverter (#5460)

This commit is contained in:
Piotr Idzik
2024-09-22 11:20:23 +02:00
committed by GitHub
parent 3fe1de0092
commit b849cbb602
3 changed files with 11 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import static java.util.Map.entry;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Map;
import java.util.NoSuchElementException;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Test;
@ -15,4 +16,12 @@ public class UnitsConverterTest {
assertThrows(IllegalArgumentException.class, () -> someConverter.convert("A", "A", 20.0));
assertThrows(IllegalArgumentException.class, () -> someConverter.convert("B", "B", 20.0));
}
@Test
void testConvertThrowsForUnknownUnits() {
final UnitsConverter someConverter = new UnitsConverter(Map.ofEntries(entry(Pair.of("A", "B"), new AffineConverter(10.0, -20.0))));
assertThrows(NoSuchElementException.class, () -> someConverter.convert("A", "X", 20.0));
assertThrows(NoSuchElementException.class, () -> someConverter.convert("X", "A", 20.0));
assertThrows(NoSuchElementException.class, () -> someConverter.convert("X", "Y", 20.0));
}
}