@Test
public void testAESDemo() {

  int noPlayers = 2;
  List<Integer> ports = NetworkUtil.getFreePorts(noPlayers);
  Map<Integer, NetworkConfiguration> netConf =
      NetworkUtil.getNetworkConfigurations(ports);
  Map<Integer, TestThreadConfiguration<ResourcePoolImpl, ProtocolBuilderBinary>> conf =
      new HashMap<>();
  for (int playerId : netConf.keySet()) {
    ProtocolSuite<ResourcePoolImpl, ProtocolBuilderBinary> suite =
        new DummyBooleanProtocolSuite();
    ProtocolEvaluator<ResourcePoolImpl> evaluator =
        new BatchedProtocolEvaluator<>(new SequentialStrategy<>(), suite);
    SecureComputationEngine<ResourcePoolImpl, ProtocolBuilderBinary> sce =
        new SecureComputationEngineImpl<>(suite, evaluator);
    TestThreadConfiguration<ResourcePoolImpl, ProtocolBuilderBinary> ttc =
        new TestThreadConfiguration<>(
            sce,
            () -> new ResourcePoolImpl(playerId, noPlayers),
            () -> new SocketNetwork(netConf.get(playerId)));
    conf.put(playerId, ttc);
  }
  TestThreadFactory<ResourcePoolImpl, ProtocolBuilderBinary> f =
      new TestThreadFactory<ResourcePoolImpl, ProtocolBuilderBinary>() {
        @Override
        public TestThread<ResourcePoolImpl, ProtocolBuilderBinary> next() {
          return new TestThread<ResourcePoolImpl, ProtocolBuilderBinary>() {
            @Override
            public void test() throws Exception {
              Boolean[] input = null;
              if (conf.getMyId() == 2) {
                // 128-bit AES plaintext block
                input = ByteAndBitConverter.toBoolean("00112233445566778899aabbccddeeff");
              } else if (conf.getMyId() == 1) {
                // 128-bit key
                input = ByteAndBitConverter.toBoolean("000102030405060708090a0b0c0d0e0f");
              }
              AesDemo app = new AesDemo(conf.getMyId(), input);
              List<Boolean> aesResult = runApplication(app);
              // Verify output state.
              String expected = "69c4e0d86a7b0430d8cdb78070b4c55a"; // expected cipher
              boolean[] actualBoolean = new boolean[aesResult.size()];
              int i = 0;
              for (Boolean b : aesResult) {
                actualBoolean[i++] = b;
              }
              String actual = ByteAndBitConverter.toHex(actualBoolean);
              Assert.assertEquals(expected, actual);
            }
          };
        }
      };
  TestThreadRunner.run(f, conf);
}