junit5: JsonConverterTest test annotation exceptions refactoring

This commit is contained in:
Oleksandra Matviienko 2023-03-06 10:49:57 +01:00
parent d0e1418318
commit ea2e87e73e

View File

@ -18,6 +18,7 @@ import com.google.gson.JsonSyntaxException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.thingsboard.server.common.transport.adaptor.JsonConverter;
@ -88,15 +89,19 @@ public class JsonConverterTest {
Assert.assertEquals("10000000000000000000", result.get(0L).get(0).getStrValue().get());
}
@Test(expected = JsonSyntaxException.class)
@Test
public void testParseBigDecimalOutOfLongRangeWithoutParsing() {
JsonConverter.setTypeCastEnabled(false);
JsonConverter.convertToTelemetry(JSON_PARSER.parse("{\"meterReadingDelta\": 89701010051400054084}"), 0L);
Assertions.assertThrows(JsonSyntaxException.class, () -> {
JsonConverter.convertToTelemetry(JSON_PARSER.parse("{\"meterReadingDelta\": 89701010051400054084}"), 0L);
});
}
@Test(expected = JsonSyntaxException.class)
@Test
public void testParseBigDecimalOutOfLongRangeWithoutParsing2() {
JsonConverter.setTypeCastEnabled(false);
JsonConverter.convertToTelemetry(JSON_PARSER.parse("{\"meterReadingDelta\": 9.9701010061400066E19}"), 0L);
Assertions.assertThrows(JsonSyntaxException.class, () -> {
JsonConverter.convertToTelemetry(JSON_PARSER.parse("{\"meterReadingDelta\": 9.9701010061400066E19}"), 0L);
});
}
}