@Test public void testConnectSocketAddress() throws Exception { SocketAddress socketAddress = new InetSocketAddress(InetAddress.getLocalHost(), 123); sniffySocket.connect(socketAddress, 123); verifyPrivate(delegate).invoke("connect", socketAddress, 123); verifyNoMoreInteractions(delegate); }
@Test public void saveWrapperExceptionWhenSDKDisabled() throws JSONException { when(SharedPreferencesManager.getBoolean(CRASHES_ENABLED_KEY, true)).thenReturn(false); LogSerializer logSerializer = Mockito.mock(LogSerializer.class); Crashes.getInstance().setLogSerializer(logSerializer); WrapperSdkExceptionManager.saveWrapperException(Thread.currentThread(), null, new Exception(), new byte[]{'d'}); verify(logSerializer, never()).serializeLog(any(Log.class)); verifyNoMoreInteractions(ErrorLogHelper.class); } }
@Test public void testGetOutputStream() throws Exception { ByteArrayOutputStream expected = new ByteArrayOutputStream(); when(delegate, "getOutputStream").thenReturn(expected); OutputStream actual = sniffySocket.getOutputStream(); verifyPrivate(delegate).invoke("getOutputStream"); verifyNoMoreInteractions(delegate); assertEquals(SnifferOutputStream.class, actual.getClass()); actual.write(1); assertArrayEquals(new byte[]{1}, expected.toByteArray()); }
@Test public void testGetInputStream() throws Exception { InputStream expected = new ByteArrayInputStream(new byte[]{1,2,3}); when(delegate, "getInputStream").thenReturn(expected); InputStream actual = sniffySocket.getInputStream(); verifyPrivate(delegate).invoke("getInputStream"); verifyNoMoreInteractions(delegate); assertEquals(SnifferInputStream.class, actual.getClass()); assertEquals(1, actual.read()); }
@Test public void testConnectInetAddress() throws Exception { InetAddress inetAddress = InetAddress.getLoopbackAddress(); sniffySocket.connect(inetAddress, 123); verifyPrivate(delegate).invoke("connect", inetAddress, 123); verifyNoMoreInteractions(delegate); }
@Test public void testBindInetAddress() throws Exception { InetAddress inetAddress = InetAddress.getLoopbackAddress(); sniffySocket.bind(inetAddress, 123); verifyPrivate(delegate).invoke("bind", inetAddress, 123); verifyNoMoreInteractions(delegate); }
@Test public void testSetOption() throws Exception { int optId = 1; Object option = new Object(); sniffySocket.setOption(optId, option); verifyPrivate(delegate).invoke("setOption", optId, option); verifyNoMoreInteractions(delegate); }
@Test public void testToString() throws Exception { String expected = "expected"; when(delegate, "toString").thenReturn(expected); String actual = sniffySocket.toString(); verifyNoMoreInteractions(delegate); assertEquals(expected, actual); }
@Test public void testGetOption() throws Exception { Object expected = new Object(); when(delegate, "getOption", 1).thenReturn(expected); Object actual = sniffySocket.getOption(1); verifyPrivate(delegate).invoke("getOption", 1); verifyNoMoreInteractions(delegate); assertEquals(expected, actual); }
@Test public void testSendUrgentData() throws Exception { sniffySocket.sendUrgentData(1); // TODO: insert timeout here and to similar methods? verifyPrivate(delegate).invoke("sendUrgentData",1); verifyNoMoreInteractions(delegate); }
@Test public void testConnect() throws Exception { sniffySocket.connect("localhost", 123); verifyPrivate(delegate).invoke("connect", "localhost", 123); verifyNoMoreInteractions(delegate); }
@Test public void testListen() throws Exception { sniffySocket.listen(123); verifyPrivate(delegate).invoke("listen", 123); verifyNoMoreInteractions(delegate); }
@Test public void testSetPerformancePreferences() throws Exception { sniffySocket.setPerformancePreferences(1, 2, 3); verifyPrivate(delegate).invoke("setPerformancePreferences", 1, 2, 3); verifyNoMoreInteractions(delegate); }
@Test public void testShutdownInput() throws Exception { sniffySocket.shutdownInput(); verifyPrivate(delegate).invoke("shutdownInput"); verifyNoMoreInteractions(delegate); }
@Test public void testGetPort() throws Exception { int expected = 1; when(delegate, "getPort").thenReturn(expected); int actual = sniffySocket.getPort(); verifyPrivate(delegate).invoke("getPort"); verifyNoMoreInteractions(delegate); assertEquals(expected, actual); }
@Test public void testGetFileDescriptor() throws Exception { FileDescriptor expected = mock(FileDescriptor.class); when(delegate, "getFileDescriptor").thenReturn(expected); FileDescriptor actual = sniffySocket.getFileDescriptor(); verifyPrivate(delegate).invoke("getFileDescriptor"); verifyNoMoreInteractions(delegate); assertEquals(expected, actual); }
@Test public void testAccept() throws Exception { SocketImpl socketImpl = new SnifferSocketImpl(null); sniffySocket.accept(socketImpl); verifyPrivate(delegate).invoke("accept", socketImpl); verifyNoMoreInteractions(delegate); }
@Test public void testGetInetAddress() throws Exception { InetAddress expected = mock(InetAddress.class); when(delegate, "getInetAddress").thenReturn(expected); InetAddress actual = sniffySocket.getInetAddress(); verifyPrivate(delegate).invoke("getInetAddress"); verifyNoMoreInteractions(delegate); assertEquals(expected, actual); }
@Test @Features({"issues/219"}) public void testConnectWithDelay() throws Exception { ConnectionsRegistry.INSTANCE.setSocketAddressStatus("localhost", 123, 10); doNothing().when(SnifferSocketImpl.class, "sleepImpl", anyInt()); sniffySocket.connect("localhost", 123); verifyPrivate(SnifferSocketImpl.class).invoke("sleepImpl", eq(10)); verifyPrivate(delegate).invoke("connect", "localhost", 123); verifyNoMoreInteractions(delegate); }
@Test public void setEnabledWithoutContext() { Crashes crashes = Crashes.getInstance(); crashes.setUncaughtExceptionHandler(null); crashes.setInstanceEnabled(true); assertNull(crashes.getUncaughtExceptionHandler()); UncaughtExceptionHandler mockHandler = mock(UncaughtExceptionHandler.class); crashes.setUncaughtExceptionHandler(mockHandler); crashes.setInstanceEnabled(true); assertEquals(mockHandler, crashes.getUncaughtExceptionHandler()); verifyNoMoreInteractions(mockHandler); }