mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
fix: handle Null Dereference in UnitsConverter
(#5460)
This commit is contained in:
@ -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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user