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.*;
15 public class FileContentHandlerTest {
17 private static final String FILE_NAME = "test-file.txt";
20 public void testProcessFileContent() throws Exception {
23 FileContentHandler contentHandler = new FileContentHandler();
24 final byte[] content = new byte[size];
25 Arrays.fill(content, (byte) 44);
26 contentHandler.addFile(FILE_NAME, content);
27 assertEquals(contentHandler.processFileContent(FILE_NAME, optional -> {
30 byte[] buffer = new byte[size];
31 assertTrue(optional.isPresent());
32 assertEquals(size, optional.get().read(buffer));
34 } catch (IOException e) {
35 throw new RuntimeException("Unexpected error", e);
42 public void testProcessEmptyFileContent() throws Exception {
43 FileContentHandler contentHandler = new FileContentHandler();
44 contentHandler.addFile(FILE_NAME, new byte[0]);
45 assertFalse(contentHandler.processFileContent(FILE_NAME, Optional::isPresent));
49 public void testProcessNoFileContent() throws Exception {
50 FileContentHandler contentHandler = new FileContentHandler();
51 assertFalse(contentHandler.processFileContent("filename", Optional::isPresent));