From e51756014aa4a567baf0721d872bb31ff76516f7 Mon Sep 17 00:00:00 2001 From: Bon-Yong Lee Date: Mon, 14 Oct 2013 20:57:56 +0900 Subject: [PATCH] [Title] In-container test -> Out-of-container test [Desc.] [Issue] --- .../test/src/org/tizen/common/util/FileUtilTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/org.tizen.common/test/src/org/tizen/common/util/FileUtilTest.java b/org.tizen.common/test/src/org/tizen/common/util/FileUtilTest.java index 3704673..524c685 100755 --- a/org.tizen.common/test/src/org/tizen/common/util/FileUtilTest.java +++ b/org.tizen.common/test/src/org/tizen/common/util/FileUtilTest.java @@ -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/" ) ); -- 2.7.4