use of java.util.OptionalInt in project gerrit by GerritCodeReview.
the class PostReview method ensureSizeOfJsonInputIsWithinBounds.
private void ensureSizeOfJsonInputIsWithinBounds(RobotCommentInput robotCommentInput) throws BadRequestException {
OptionalInt robotCommentSizeLimit = getRobotCommentSizeLimit();
if (robotCommentSizeLimit.isPresent()) {
int sizeLimit = robotCommentSizeLimit.getAsInt();
byte[] robotCommentBytes = GSON.toJson(robotCommentInput).getBytes(StandardCharsets.UTF_8);
int robotCommentSize = robotCommentBytes.length;
if (robotCommentSize > sizeLimit) {
throw new BadRequestException(String.format("Size %d (bytes) of robot comment is greater than limit %d (bytes)", robotCommentSize, sizeLimit));
}
}
}
use of java.util.OptionalInt in project jdk8u_jdk by JetBrains.
the class BasicInt method testEmptyOrElseGetNull.
@Test(expectedExceptions = NullPointerException.class)
public void testEmptyOrElseGetNull() {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseGet(null);
}
use of java.util.OptionalInt in project jdk8u_jdk by JetBrains.
the class BasicInt method testEmptyOrElseThrowNull.
@Test(expectedExceptions = NullPointerException.class)
public void testEmptyOrElseThrowNull() throws Throwable {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(null);
}
use of java.util.OptionalInt in project jdk8u_jdk by JetBrains.
the class BasicInt method testEmptyOrElseThrow.
@Test(expectedExceptions = ObscureException.class)
public void testEmptyOrElseThrow() throws Exception {
OptionalInt empty = OptionalInt.empty();
int got = empty.orElseThrow(ObscureException::new);
}
use of java.util.OptionalInt in project jdk8u_jdk by JetBrains.
the class BasicInt method testPresent.
@Test(groups = "unit")
public void testPresent() {
OptionalInt empty = OptionalInt.empty();
OptionalInt present = OptionalInt.of(1);
// present
assertTrue(present.equals(present));
assertFalse(present.equals(OptionalInt.of(0)));
assertTrue(present.equals(OptionalInt.of(1)));
assertFalse(present.equals(empty));
assertTrue(Integer.hashCode(1) == present.hashCode());
assertFalse(present.toString().isEmpty());
assertTrue(-1 != present.toString().indexOf(Integer.toString(present.getAsInt()).toString()));
assertEquals(1, present.getAsInt());
try {
present.ifPresent(v -> {
throw new ObscureException();
});
fail();
} catch (ObscureException expected) {
}
assertEquals(1, present.orElse(2));
assertEquals(1, present.orElseGet(null));
assertEquals(1, present.orElseGet(() -> 2));
assertEquals(1, present.orElseGet(() -> 3));
assertEquals(1, present.<RuntimeException>orElseThrow(null));
assertEquals(1, present.<RuntimeException>orElseThrow(ObscureException::new));
}
Aggregations