### Question:
SiteToSiteSender { public TransactionCompletion sendFiles() throws IOException { Transaction transaction = siteToSiteClient.createTransaction(TransferDirection.SEND); try { DataPacketDto.getDataPacketStream(input).forEachOrdered(d -> { try { transaction.send(d); } catch (IOException e) { throw new RuntimeException(e); } }); } catch (RuntimeException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) { throw (IOException) cause; } throw new IOException(e.getMessage(), e); } transaction.confirm(); return transaction.complete(); } SiteToSiteSender(SiteToSiteClient siteToSiteClient, InputStream input); TransactionCompletion sendFiles();  }### Answer:
@Test public void testEmptyList() throws IOException { objectMapper.writeValue(data, Collections.emptyList()); assertEquals(transactionCompletion, senderSupplier.get().sendFiles()); verify(transaction, never()).send(any(DataPacket.class)); verify(transaction).complete(); verifyNoMoreInteractions(siteToSiteClient, transaction, transactionCompletion); }
@Test public void testSingleElement() throws IOException { DataPacketDto dataPacketDto = new DataPacketDto("test-data".getBytes(StandardCharsets.UTF_8)).putAttribute("key", "value"); objectMapper.writeValue(data, Arrays.stream(new DataPacketDto[]{dataPacketDto}).collect(Collectors.toList())); assertEquals(transactionCompletion, senderSupplier.get().sendFiles()); verify(transaction).send(dataPacketDto.toDataPacket()); verify(transaction).complete(); verifyNoMoreInteractions(siteToSiteClient, transaction, transactionCompletion); }
@Test public void testMultipleElements() throws IOException { DataPacketDto dataPacketDto = new DataPacketDto("test-data".getBytes(StandardCharsets.UTF_8)).putAttribute("key", "value"); DataPacketDto dataPacketDto2 = new DataPacketDto("test-data2".getBytes(StandardCharsets.UTF_8)).putAttribute("key2", "value2"); objectMapper.writeValue(data, Arrays.stream(new DataPacketDto[]{dataPacketDto, dataPacketDto2}).collect(Collectors.toList())); assertEquals(transactionCompletion, senderSupplier.get().sendFiles()); verify(transaction).send(dataPacketDto.toDataPacket()); verify(transaction).send(dataPacketDto2.toDataPacket()); verify(transaction).complete(); verifyNoMoreInteractions(siteToSiteClient, transaction, transactionCompletion); }
@Test(expected = IOException.class) public void testIOException() throws IOException { IOException test = new IOException("test"); DataPacketDto dataPacketDto = new DataPacketDto("test-data".getBytes(StandardCharsets.UTF_8)).putAttribute("key", "value"); objectMapper.writeValue(data, Arrays.stream(new DataPacketDto[]{dataPacketDto}).collect(Collectors.toList())); doThrow(test).when(transaction).send(any(DataPacket.class)); try { senderSupplier.get().sendFiles(); } catch (IOException e) { assertEquals(test, e); throw e; } }
@Test(expected = IOException.class) public void testRuntimeException() throws IOException { RuntimeException test = new RuntimeException("test"); DataPacketDto dataPacketDto = new DataPacketDto("test-data".getBytes(StandardCharsets.UTF_8)).putAttribute("key", "value"); objectMapper.writeValue(data, Arrays.stream(new DataPacketDto[]{dataPacketDto}).collect(Collectors.toList())); doThrow(test).when(transaction).send(any(DataPacket.class)); try { senderSupplier.get().sendFiles(); } catch (IOException e) { assertEquals(test, e.getCause()); throw e; } }