Search in sources :

Example 16 with OptionalInt

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());
    }
}
Also used : IntStream(java.util.stream.IntStream) NetworkCallback(android.net.ConnectivityManager.NetworkCallback) Arrays(java.util.Arrays) IpConnectivityEvent(com.android.server.connectivity.metrics.IpConnectivityLogClass.IpConnectivityEvent) SmallTest(android.test.suitebuilder.annotation.SmallTest) Mock(org.mockito.Mock) DnsEvent(android.net.metrics.DnsEvent) RemoteException(android.os.RemoteException) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.timeout(org.mockito.Mockito.timeout) IpConnectivityLog(android.net.metrics.IpConnectivityLog) ArgumentCaptor(org.mockito.ArgumentCaptor) INetdEventListener(android.net.metrics.INetdEventListener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) TestCase(junit.framework.TestCase) Before(org.junit.Before) ConnectivityManager(android.net.ConnectivityManager) PrintWriter(java.io.PrintWriter) OsConstants(android.system.OsConstants) FileOutputStream(java.io.FileOutputStream) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Network(android.net.Network) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) List(java.util.List) Mockito.anyInt(org.mockito.Mockito.anyInt) Comparator(java.util.Comparator) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) OptionalInt(java.util.OptionalInt) DnsEvent(android.net.metrics.DnsEvent)

Example 17 with OptionalInt

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();
}
Also used : OptionalInt(java.util.OptionalInt) Test(org.testng.annotations.Test)

Example 18 with OptionalInt

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));
}
Also used : OptionalInt(java.util.OptionalInt) Test(org.testng.annotations.Test)

Example 19 with OptionalInt

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));
}
Also used : IntStream(java.util.stream.IntStream) IntStreamTestDataProvider(java.util.stream.IntStreamTestDataProvider) Arrays(java.util.Arrays) OpTestCase(java.util.stream.OpTestCase) LambdaTestHelpers(java.util.stream.LambdaTestHelpers) TestData(java.util.stream.TestData) Test(org.testng.annotations.Test) OptionalInt(java.util.OptionalInt) OptionalInt(java.util.OptionalInt) Test(org.testng.annotations.Test)

Example 20 with OptionalInt

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());
    }
}
Also used : IntStream(java.util.stream.IntStream) NetworkCallback(android.net.ConnectivityManager.NetworkCallback) Arrays(java.util.Arrays) IpConnectivityEvent(com.android.server.connectivity.metrics.IpConnectivityLogClass.IpConnectivityEvent) SmallTest(android.test.suitebuilder.annotation.SmallTest) Mock(org.mockito.Mock) DnsEvent(android.net.metrics.DnsEvent) RemoteException(android.os.RemoteException) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.timeout(org.mockito.Mockito.timeout) IpConnectivityLog(android.net.metrics.IpConnectivityLog) ArgumentCaptor(org.mockito.ArgumentCaptor) INetdEventListener(android.net.metrics.INetdEventListener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) TestCase(junit.framework.TestCase) Before(org.junit.Before) ConnectivityManager(android.net.ConnectivityManager) PrintWriter(java.io.PrintWriter) OsConstants(android.system.OsConstants) FileOutputStream(java.io.FileOutputStream) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Network(android.net.Network) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) List(java.util.List) Mockito.anyInt(org.mockito.Mockito.anyInt) Comparator(java.util.Comparator) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) OptionalInt(java.util.OptionalInt) DnsEvent(android.net.metrics.DnsEvent)

Aggregations

OptionalInt (java.util.OptionalInt)38 Test (org.testng.annotations.Test)11 List (java.util.List)8 UUID (java.util.UUID)7 Arrays (java.util.Arrays)6 IntStream (java.util.stream.IntStream)6 Optional (java.util.Optional)5 Test (org.junit.Test)5 ConnectivityManager (android.net.ConnectivityManager)4 NetworkCallback (android.net.ConnectivityManager.NetworkCallback)4 Network (android.net.Network)4 DnsEvent (android.net.metrics.DnsEvent)4 INetdEventListener (android.net.metrics.INetdEventListener)4 IpConnectivityLog (android.net.metrics.IpConnectivityLog)4 RemoteException (android.os.RemoteException)4 SmallTest (android.test.suitebuilder.annotation.SmallTest)4 PrestoException (com.facebook.presto.spi.PrestoException)4 Type (com.facebook.presto.spi.type.Type)4 FileOutputStream (java.io.FileOutputStream)4 PrintWriter (java.io.PrintWriter)4