1 package org.openecomp.core.utilities.file;
3 import org.testng.annotations.Test;
5 import java.io.IOException;
6 import java.util.Arrays;
7 import java.util.Optional;
9 import static org.testng.Assert.assertEquals;
10 import static org.testng.Assert.assertFalse;
11 import static org.testng.Assert.assertTrue;
17 public class FileContentHandlerTest {
19 private static final String FILE_NAME = "test-file.txt";
22 public void testProcessFileContent() throws Exception {
25 FileContentHandler contentHandler = new FileContentHandler();
26 final byte[] content = new byte[size];
27 Arrays.fill(content, (byte) 44);
28 contentHandler.addFile(FILE_NAME, content);
29 assertEquals(contentHandler.processFileContent(FILE_NAME, optional -> {
32 byte[] buffer = new byte[size];
33 assertTrue(optional.isPresent());
34 assertEquals(size, optional.get().read(buffer));
36 } catch (IOException e) {
37 throw new RuntimeException("Unexpected error", e);
44 public void testProcessEmptyFileContent() throws Exception {
45 FileContentHandler contentHandler = new FileContentHandler();
46 contentHandler.addFile(FILE_NAME, new byte[0]);
47 assertFalse(contentHandler.processFileContent(FILE_NAME, Optional::isPresent));
51 public void testProcessNoFileContent() throws Exception {
52 FileContentHandler contentHandler = new FileContentHandler();
53 assertFalse(contentHandler.processFileContent("filename", Optional::isPresent));