*/
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
*
* @see ZipUtil
*/
-public class ZipUtilTest {
+@RunWith( PowerMockRunner.class )
+@PrepareForTest( { ZipUtil.class, FilenameUtil.class } )
+public class
+ZipUtilTest
+{
/**
* Test {@link ZipUtil#getContent(String, String)}
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 ) );
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" ) );
}
}