1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 12:02:05 +01:00

[core] Improve NumberUtil's exception message and fix javadoc

This commit is contained in:
Florian Schmaus 2020-05-24 13:02:01 +02:00
parent f045c0dd08
commit 9a8ee3c8e3
2 changed files with 8 additions and 9 deletions

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2015-2019 Florian Schmaus
* Copyright © 2015-2020 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,15 +33,15 @@ public class NumberUtil {
/**
* Checks if the given long is within the range of an unsigned 32-bit integer, the XML type "xs:unsignedInt".
*
* @param value TODO javadoc me please
* @param value the long to check.
* @return the input value.
*/
public static long requireUInt32(long value) {
if (value < 0) {
throw new IllegalArgumentException("unsigned 32-bit integers can't be negative");
throw new IllegalArgumentException("unsigned 32-bit integers can't be negative: " + value);
}
if (value > ((1L << 32) - 1)) {
throw new IllegalArgumentException("unsigned 32-bit integers can't be greater than 2^32 - 1");
throw new IllegalArgumentException("unsigned 32-bit integers can't be greater than 2^32 - 1: " + value);
}
return value;
}
@ -49,15 +49,15 @@ public class NumberUtil {
/**
* Checks if the given int is within the range of an unsigned 16-bit integer, the XML type "xs:unsignedShort".
*
* @param value TODO javadoc me please
* @param value the int to check.
* @return the input value.
*/
public static int requireUShort16(int value) {
if (value < 0) {
throw new IllegalArgumentException("unsigned 16-bit integers can't be negative");
throw new IllegalArgumentException("unsigned 16-bit integers can't be negative: " + value);
}
if (value > ((1 << 16) - 1)) {
throw new IllegalArgumentException("unsigned 16-bit integers can't be greater than 2^16 - 1");
throw new IllegalArgumentException("unsigned 16-bit integers can't be greater than 2^16 - 1: " + value);
}
return value;
}

View file

@ -44,9 +44,8 @@ public class DataValidationHelperTest {
() -> element.checkConsistency(field));
assertEquals("Field type 'jid-single' is not consistent with validation method 'basic'.", vce.getMessage());
IllegalArgumentException iae = assertThrows(IllegalArgumentException.class,
assertThrows(IllegalArgumentException.class,
() -> new ListRange(-1L, 1L));
assertEquals("unsigned 32-bit integers can't be negative", iae.getMessage());
element.setListRange(new ListRange(10L, 100L));
vce = assertThrows(ValidationConsistencyException.class, () -> element.checkConsistency(field));