Remove major and minor code smells in dr-node
[dmaap/datarouter.git] / datarouter-node / src / test / java / org / onap / dmaap / datarouter / node / DeliveryQueueTest.java
index 9a3d82e..fa868b2 100644 (file)
@@ -45,20 +45,18 @@ public class DeliveryQueueTest {
     DeliveryQueueHelper deliveryQueueHelper;
 
     private String dirPath = "/tmp/dir001/";
-    private String FileName1 = "10000000000004.fileName.M";
+    private String fileName = "10000000000004.fileName.M";
 
     @Before
     public void setUp() {
-        when(destInfo.getSpool()).thenReturn("tmp");
+        when(destInfo.getSpool()).thenReturn(dirPath);
         deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
     }
 
     @Test
     public void Given_New_DeliveryQueue_Directory_Is_Created_As_Defined_By_DestInfo() {
-        when(destInfo.getSpool()).thenReturn("tmp");
-        File file = new File("tmp");
+        File file = new File("/tmp");
         assertTrue(file.exists());
-        deleteFile("tmp");
     }
 
     @Test
@@ -75,7 +73,7 @@ public class DeliveryQueueTest {
         deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
         DeliveryTask nt = deliveryQueue.getNext();
         assertEquals("10000000000004.fileName", nt.getPublishId());
-        deleteFile(dirPath + FileName1);
+        deleteFile(dirPath + fileName);
         deleteFile(dirPath);
     }
 
@@ -87,36 +85,17 @@ public class DeliveryQueueTest {
 
     private void prepareFiles() throws Exception {
         createFolder(dirPath);
-        createFile(FileName1, dirPath);
-        String[] files = new String[2];
-        files[0] = dirPath + FileName1;
+        createFile(fileName, dirPath);
     }
 
-    private void createFolder(String dirName) throws Exception {
-        String dirPath = dirName;
-
-        File newDirectory = new File(dirPath);
-        boolean isCreated = newDirectory.mkdirs();
-        if (isCreated) {
-            System.out.println("1. Successfully created directories, path: " + newDirectory.getCanonicalPath());
-        } else if (newDirectory.exists()) {
-            System.out.print("1. Directory path already exist, path: " + newDirectory.getCanonicalPath());
-        } else {
-            System.out.println("1. Unable to create directory");
-        }
+    private void createFolder(String dirName) {
+        File newDirectory = new File(dirName);
+        newDirectory.mkdirs();
     }
 
     private void createFile(String file, String dir) throws Exception {
-        String FileName = file;
-        String dirPath = dir;
-
-        File newFile = new File(dirPath + File.separator + FileName);
-        boolean isCreated = newFile.createNewFile();
-        if (isCreated) {
-            System.out.println("\n2. Successfully created new file, path: " + newFile.getCanonicalPath());
-        } else { //File may already exist
-            System.out.println("\n2. Unable to create new file: " + newFile.getCanonicalPath());
-        }
+        File newFile = new File(dir + File.separator + file);
+        newFile.createNewFile();
     }
 
     private void deleteFile(String fileName) {