[Title] In-container test -> Out-of-container test 62/10862/1
authorBon-Yong Lee <bonyong.lee@samsung.com>
Mon, 14 Oct 2013 11:51:31 +0000 (20:51 +0900)
committerBon-Yong Lee <bonyong.lee@samsung.com>
Mon, 14 Oct 2013 12:05:04 +0000 (21:05 +0900)
[Desc.]
[Issue]

org.tizen.common/test/src/org/tizen/common/util/ZipUtilTest.java [changed mode: 0644->0755]
org.tizen.common/test/test_files/resource/test.zip [deleted file]

old mode 100644 (file)
new mode 100755 (executable)
index bba2a7b..e49f32a
 */
 package org.tizen.common.util;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
 
-import java.io.File;
+import java.io.ByteArrayInputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
 
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
 /**
  * ZipUtilTest
@@ -39,7 +49,11 @@ import org.junit.Test;
  * 
  * @see ZipUtil
  */
-public class ZipUtilTest {
+@RunWith( PowerMockRunner.class )
+@PrepareForTest( { ZipUtil.class, FilenameUtil.class } )
+public class
+ZipUtilTest
+{
 
     /**
      * Test {@link ZipUtil#getContent(String, String)}
@@ -53,6 +67,14 @@ public class ZipUtilTest {
     test_getContent()
     throws Exception
     {
+        final ZipFile zipFile = mock( ZipFile.class );
+        final ZipEntry zipEntry = mock( ZipEntry.class );
+        
+        mockStatic( FilenameUtil.class );
+        when( FilenameUtil.getCanonicalPath( "test/test_files/resource/test.zip" ) ).thenReturn( "/mock/test/test_files/resource/test.zip" );
+        whenNew( ZipFile.class ).withArguments( "/mock/test/test_files/resource/test.zip" ).thenReturn( zipFile );
+        when( zipFile.getEntry( "config.xml" ) ).thenReturn( zipEntry );
+        when( zipFile.getInputStream( zipEntry ) ).thenReturn( new ByteArrayInputStream( "Hello".getBytes() ) );
         assertNull( ZipUtil.getContent( null, null ) );
         assertNull( ZipUtil.getContent( null, "text.text" ) );
         assertNull( ZipUtil.getContent( "test/test_files/resource/test.zip", null ) );
@@ -60,9 +82,5 @@ public class ZipUtilTest {
         assertNull( ZipUtil.getContent( "test/test_files/resource/test.zip", "config.t" ) );
         assertNull( ZipUtil.getContent( "test/test_files/resource/test.zip", "config.text" ) );
         assertNotNull( ZipUtil.getContent( "test/test_files/resource/test.zip", "config.xml" ) );
-
-        File file = new File("test/test_files/resource/test.zip");
-        String path = file.getCanonicalFile().getCanonicalPath();
-        assertNotNull( ZipUtil.getContent( path, "config.xml" ) );
     }
 }
diff --git a/org.tizen.common/test/test_files/resource/test.zip b/org.tizen.common/test/test_files/resource/test.zip
deleted file mode 100644 (file)
index fff7bff..0000000
Binary files a/org.tizen.common/test/test_files/resource/test.zip and /dev/null differ