@Test
  public void testConnect() throws Exception {

    // Arrange
    ByteString sessionId = TrezorClients.newSessionId();

    BlockingTrezorClient testObject =
        TrezorClients.newBlockingSocketInstance("localhost", 3000, sessionId);

    TrezorEmulator emulator = TrezorEmulator.newDefaultTrezorEmulator();
    emulator.start();

    // Act
    testObject.connect();

    // Assert
    // Expect a result within a short time

    // Verify that the device connected
    TrezorEvent event1 = testObject.getTrezorEventQueue().poll(1, TimeUnit.SECONDS);
    assertThat(event1).isNotNull();
    assertThat(event1.protocolMessageType().isPresent()).isFalse();
    assertThat(event1.eventType()).isEqualTo(TrezorEventType.DEVICE_CONNECTED);

    // Verify that the data was read in correctly
    TrezorEvent event2 = testObject.getTrezorEventQueue().poll(1, TimeUnit.SECONDS);
    assertThat(event2).isNotNull();
    assertThat(event2.protocolMessageType().isPresent()).isTrue();
    assertThat(event2.protocolMessageType().get()).isEqualTo(MessageType.SUCCESS);

    testObject.close();
  }
  /**
   * Entry point to the example
   *
   * @param args No arguments
   * @throws Exception If something goes wrong
   */
  public static void main(String[] args) throws Exception {

    // Create the Trezor emulator and start serving
    TrezorEmulator emulator = TrezorEmulator.newDefaultTrezorEmulator();
    emulator.start();

    // Allow time for the emulator to start
    Thread.sleep(100);

    // Create the socket trezor
    BlockingTrezorClient client =
        TrezorClients.newBlockingSocketInstance("localhost", 3000, TrezorClients.newSessionId());
    client.connect();

    TrezorEvent event1 = client.getTrezorEventQueue().poll(1, TimeUnit.SECONDS);
    log.info("Received: {} ", event1.eventType());

    TrezorEvent event2 = client.ping();
    log.info("Received: {} {} ", event2.eventType(), event2.protocolMessageType().get());

    System.exit(0);
  }