diff options
author | Shireesh Anjal <shireesh@gluster.com> | 2011-10-07 12:45:20 +0530 |
---|---|---|
committer | Shireesh Anjal <shireesh@gluster.com> | 2011-10-07 12:45:20 +0530 |
commit | a0327dce2fd70eac192f27ab296dfd319db049ca (patch) | |
tree | 75104503eccd1aa4b07eff552e99bec27430efdb | |
parent | 60a95ec6d794655bdd33d5f0f846a17f6dd6cc89 (diff) |
Deleted redundant file TestFileUtil.java, introduced constants TEST_FILE_PATH and TEST_FILE_CONTENT in FileUtilTest.java
2 files changed, 10 insertions, 84 deletions
diff --git a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/FileUtilTest.java b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/FileUtilTest.java index 4ac55f01..9302619e 100644 --- a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/FileUtilTest.java +++ b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/FileUtilTest.java @@ -1,10 +1,6 @@ package com.gluster.storage.management.core.utils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.io.BufferedWriter; import java.io.File; @@ -29,7 +25,8 @@ import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; public class FileUtilTest { - private String filePath = FileUtil.getTempDirName() + "/test.txt"; + private static final String TEST_FILE_PATH = FileUtil.getTempDirName() + "/test.txt"; + private static final String TEST_FILE_CONTENT = "Welcome to Gluster Storage Management console."; /** @@ -160,11 +157,12 @@ public class FileUtilTest { @Test public void testReadFileAsByteArray_2() throws Exception { - File file = new File(filePath); + File file = new File(TEST_FILE_PATH); byte[] result = FileUtil.readFileAsByteArray(file); assertNotNull(result); assertTrue(result instanceof byte[]); + assertTrue(TEST_FILE_CONTENT.equals(new String(result))); } @@ -181,7 +179,7 @@ public class FileUtilTest { throws Exception { File file = new File(""); - String result = FileUtil.readFileAsString(file); + FileUtil.readFileAsString(file); } @@ -195,11 +193,12 @@ public class FileUtilTest { @Test public void testReadFileAsString_2() throws Exception { - File file = new File(filePath); + File file = new File(TEST_FILE_PATH); String result = FileUtil.readFileAsString(file); assertNotNull(result); assertTrue(result instanceof String); + assertTrue(result.equals(TEST_FILE_CONTENT)); } /** @@ -363,7 +362,7 @@ public class FileUtilTest { throws Exception { // testReadFileAsByteArray_2() - if (!writeToFile(filePath, "Welcome to Gluster Storage Management console.")) { + if (!writeToFile(TEST_FILE_PATH, TEST_FILE_CONTENT)) { fail("Setup: Text file creation error!"); } @@ -398,7 +397,7 @@ public class FileUtilTest { @After public void tearDown() throws Exception { - File file = new File(filePath); + File file = new File(TEST_FILE_PATH); file.delete(); file = new File(FileUtil.getTempDirName() + "/rd/b/c/d"); if (file.exists()) { diff --git a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java b/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java deleted file mode 100644 index f562a53c..00000000 --- a/src/com.gluster.storage.management.core/junit/com/gluster/storage/management/core/utils/TestFileUtil.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * TestFileUtil.java - * - * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - */ -package com.gluster.storage.management.core.utils; - -import static org.junit.Assert.assertTrue; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class TestFileUtil { - private String testFileName; - private String fileContent; - private FileUtil fileUtil; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - testFileName = "testFileUtil.txt"; - fileContent = "Testing FileUtil class."; - fileUtil = new FileUtil(); - - BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(testFileName)); - OutputStreamWriter writer = new OutputStreamWriter(outStream); - writer.write(fileContent); - writer.close(); - outStream.close(); - } - - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - File testFile = new File(testFileName); - testFile.delete(); - } - - /** - * Test method for {@link com.gluster.storage.management.core.utils.FileUtil#readFileAsString(java.io.File)}. - */ - @Test - public final void testReadFileAsString() { - String readContent = fileUtil.readFileAsString(new File(testFileName)); - assertTrue("File contents expected [" + fileContent + "], actual [" + readContent + "]", - readContent.equals(fileContent)); - } -} |