use of java.util.OptionalInt in project android_frameworks_base by DirtyUnicorns.
the class NetdEventListenerServiceTest method verifyLoggedDnsEvents.
void verifyLoggedDnsEvents(int wait, DnsEvent... expectedEvents) {
verify(mLog, timeout(wait).times(expectedEvents.length)).log(mDnsEvCaptor.capture());
for (DnsEvent got : mDnsEvCaptor.getAllValues()) {
OptionalInt index = IntStream.range(0, expectedEvents.length).filter(i -> dnsEventsEqual(expectedEvents[i], got)).findFirst();
// Don't match same expected event more than once.
index.ifPresent(i -> expectedEvents[i] = null);
assertTrue(index.isPresent());
}
}
use of java.util.OptionalInt in project jdk8u_jdk by JetBrains.
the class BasicInt method testEmptyGet.
@Test(expectedExceptions = NoSuchElementException.class)
public void testEmptyGet() {
OptionalInt empty = OptionalInt.empty();
int got = empty.getAsInt();
}
use of java.util.OptionalInt in project jdk8u_jdk by JetBrains.
the class BasicInt method testEmpty.
@Test(groups = "unit")
public void testEmpty() {
OptionalInt empty = OptionalInt.empty();
OptionalInt present = OptionalInt.of(1);
// empty
assertTrue(empty.equals(empty));
assertTrue(empty.equals(OptionalInt.empty()));
assertTrue(!empty.equals(present));
assertTrue(0 == empty.hashCode());
assertTrue(!empty.toString().isEmpty());
assertTrue(!empty.isPresent());
empty.ifPresent(v -> {
fail();
});
assertEquals(2, empty.orElse(2));
assertEquals(2, empty.orElseGet(() -> 2));
}
use of java.util.OptionalInt in project jdk8u_jdk by JetBrains.
the class IntReduceTest method testOps.
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
public void testOps(String name, TestData.OfInt data) {
assertEquals(0, (int) exerciseTerminalOps(data, s -> s.filter(ipFalse), s -> s.reduce(0, irPlus)));
OptionalInt seedless = exerciseTerminalOps(data, s -> s.reduce(irPlus));
int folded = exerciseTerminalOps(data, s -> s.reduce(0, irPlus));
assertEquals(folded, seedless.orElse(0));
seedless = exerciseTerminalOps(data, s -> s.reduce(irMin));
folded = exerciseTerminalOps(data, s -> s.reduce(Integer.MAX_VALUE, irMin));
assertEquals(folded, seedless.orElse(Integer.MAX_VALUE));
seedless = exerciseTerminalOps(data, s -> s.reduce(irMax));
folded = exerciseTerminalOps(data, s -> s.reduce(Integer.MIN_VALUE, irMax));
assertEquals(folded, seedless.orElse(Integer.MIN_VALUE));
seedless = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(irPlus));
folded = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(0, irPlus));
assertEquals(folded, seedless.orElse(0));
seedless = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(irMin));
folded = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(Integer.MAX_VALUE, irMin));
assertEquals(folded, seedless.orElse(Integer.MAX_VALUE));
seedless = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(irMax));
folded = exerciseTerminalOps(data, s -> s.map(irDoubler), s -> s.reduce(Integer.MIN_VALUE, irMax));
assertEquals(folded, seedless.orElse(Integer.MIN_VALUE));
}
use of java.util.OptionalInt in project android_frameworks_base by ResurrectionRemix.
the class NetdEventListenerServiceTest method verifyLoggedDnsEvents.
void verifyLoggedDnsEvents(int wait, DnsEvent... expectedEvents) {
verify(mLog, timeout(wait).times(expectedEvents.length)).log(mDnsEvCaptor.capture());
for (DnsEvent got : mDnsEvCaptor.getAllValues()) {
OptionalInt index = IntStream.range(0, expectedEvents.length).filter(i -> dnsEventsEqual(expectedEvents[i], got)).findFirst();
// Don't match same expected event more than once.
index.ifPresent(i -> expectedEvents[i] = null);
assertTrue(index.isPresent());
}
}
Aggregations