@Test public void testTweetNotWorks() throws Exception { reset(blockingIOProcessor); clientPair.hardwareClient.send("tweet"); verify(clientPair.hardwareClient.responseMock, timeout(500)) .channelRead(any(), eq(new ResponseMessage(1, NOTIFICATION_INVALID_BODY_EXCEPTION))); clientPair.hardwareClient.send("tweet "); verify(clientPair.hardwareClient.responseMock, timeout(500)) .channelRead(any(), eq(new ResponseMessage(2, NOTIFICATION_INVALID_BODY_EXCEPTION))); StringBuilder a = new StringBuilder(); for (int i = 0; i < 141; i++) { a.append("a"); } clientPair.hardwareClient.send("tweet " + a); verify(clientPair.hardwareClient.responseMock, timeout(500)) .channelRead(any(), eq(new ResponseMessage(3, NOTIFICATION_INVALID_BODY_EXCEPTION))); clientPair.appClient.send("deactivate 1"); verify(clientPair.appClient.responseMock, timeout(500)) .channelRead(any(), eq(new ResponseMessage(1, OK))); clientPair.hardwareClient.send("tweet yo"); verify(clientPair.hardwareClient.responseMock, timeout(500)) .channelRead(any(), eq(new ResponseMessage(4, NOTIFICATION_NOT_AUTHORIZED_EXCEPTION))); }
private CLI runCliWithInput(String... inputLines) { StringBuilder builder = new StringBuilder(); for (String line : inputLines) { builder.append(line).append(System.getProperty("line.separator")); } ByteArrayInputStream in = new ByteArrayInputStream(builder.toString().getBytes()); CLI cli = new CLI(in, testOut); cli.startEventLoop(); return cli; }
public void assertObjectExistenceInSQLIteMasterTable( final String name, final String type, boolean exists, final ConnectionManager connectionManager) { Connection connection = null; PreparedStatement statement = null; try { connection = connectionManager.getConnection(null); statement = connection.prepareStatement("SELECT name FROM sqlite_master WHERE type=?"); statement.setString(1, type); java.sql.ResultSet indices = statement.executeQuery(); boolean found = false; StringBuilder objectsFound = new StringBuilder(); String next; while (indices.next()) { next = indices.getString(1); objectsFound.append("'").append(next).append("' "); if (name.equals(next)) { found = true; } } if (exists) Assert.assertTrue( "Object '" + name + "' must exists in 'sqlite_master' but it doesn't. found: " + found + ". Objects found: " + objectsFound, found); else Assert.assertFalse( "Object '" + name + "' must NOT exists in 'sqlite_master' but it does. found: " + found + " Objects found: " + objectsFound, found); } catch (Exception e) { throw new IllegalStateException( "Unable to verify existence of the object '" + name + "' in the 'sqlite_master' table", e); } finally { DBUtils.closeQuietly(connection); DBUtils.closeQuietly(statement); } }