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

org.tizen.common/test/src/org/tizen/common/util/FileUtilTest.java

index 3704673..524c685 100755 (executable)
@@ -29,6 +29,9 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.powermock.api.mockito.PowerMockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
 import static org.tizen.common.util.IOUtil.tryClose;
 
 import java.io.ByteArrayInputStream;
@@ -41,6 +44,9 @@ import java.util.List;
 import java.util.Stack;
 
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
 /**
  * FileUtilTest
@@ -51,6 +57,8 @@ import org.junit.Test;
  * 
  * @see FileUtil
  */
+@RunWith( PowerMockRunner.class )
+@PrepareForTest( FileUtil.class )
 public class
 FileUtilTest
 {
@@ -418,6 +426,17 @@ FileUtilTest
     {
         assertFalse( FileUtil.isExist( null ) );
         assertFalse( FileUtil.isExist( "" ) );
+
+        final File textAbc = mock( File.class );
+        when( textAbc.exists() ).thenReturn( Boolean.FALSE );
+        final File resource = mock( File.class );
+        when( resource.exists() ).thenReturn( Boolean.TRUE );
+        final File textTxt = mock( File.class );
+        when( textTxt.exists() ).thenReturn( Boolean.TRUE );
+        whenNew( File.class ).withArguments( "test/test_files/resource/text.abc" ).thenReturn( textAbc );
+        whenNew( File.class ).withArguments( "test/test_files/resource" ).thenReturn( resource );
+        whenNew( File.class ).withArguments( "test/test_files/resource/" ).thenReturn( resource );
+        whenNew( File.class ).withArguments( "test/test_files/resource/text.txt" ).thenReturn( textTxt );
         assertFalse( FileUtil.isExist( "test/test_files/resource/text.abc" ) );
         assertTrue( FileUtil.isExist( "test/test_files/resource" ) );
         assertTrue( FileUtil.isExist( "test/test_files/resource/" ) );