From: Bon-Yong Lee Date: Wed, 16 Oct 2013 00:52:37 +0000 (+0900) Subject: [Title] Fix test case X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F90%2F10990%2F1;p=sdk%2Fide%2Fcommon-eplugin.git [Title] Fix test case [Desc.] [Issue] --- diff --git a/org.tizen.common/src/org/tizen/common/core/command/sdb/PullSdbCommand.java b/org.tizen.common/src/org/tizen/common/core/command/sdb/PullSdbCommand.java old mode 100644 new mode 100755 diff --git a/org.tizen.common/test/src/org/tizen/common/ShellTest.java b/org.tizen.common/test/src/org/tizen/common/ShellTest.java deleted file mode 100755 index 100f6c0..0000000 --- a/org.tizen.common/test/src/org/tizen/common/ShellTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Common - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: - * BonYong Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Contributors: - * - S-Core Co., Ltd - * - */ -package org.tizen.common; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -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.Shell.run; - -import org.junit.Test; -import org.powermock.core.classloader.annotations.PrepareForTest; - -/** - * ShellTest - * - * Test case for {@link Shell} - * - * @author BonYong Lee{@literal } (S-Core) - * - * @see Shell - */ -@PrepareForTest( Shell.class ) -public class -ShellTest -{ - @Test - public - void - test_devices() throws Exception - { - class Result { - @Token( from = "emulator", to = "device" ) String range; - - @Pattern( pattern = "emulator{0}\t{1}\t{2}", index = 0 ) String pattern; - - @Token( from = "emulator", to = "device" ) String[] range2; - - @Pattern( pattern = "emulator{0}\t{1}\t{2}", index = 0 ) String[] pattern2; - - }; - - final Shell shell = mock( Shell.class ); - whenNew( Shell.class ).withAnyArguments().thenReturn( shell ); - Result mockResult = new Result(); - mockResult.range = "-26101"; - mockResult.pattern = "-26101"; - mockResult.range2 = new String[] { "-26101" }; - mockResult.pattern2 = new String[] { "-26101" }; - when( shell.expect( any() ) ).thenReturn( mockResult ); - - final Result r = run( "sdb devices" ).expect( new Result() ); - - assertEquals( r.range, r.pattern ); - - assertArrayEquals( r.range2, r.pattern2 ); - } -} diff --git a/org.tizen.common/test/src/org/tizen/common/core/command/sdb/PullSdbCommandTest.java b/org.tizen.common/test/src/org/tizen/common/core/command/sdb/PullSdbCommandTest.java index 66b186c..36dfaa2 100755 --- a/org.tizen.common/test/src/org/tizen/common/core/command/sdb/PullSdbCommandTest.java +++ b/org.tizen.common/test/src/org/tizen/common/core/command/sdb/PullSdbCommandTest.java @@ -25,6 +25,9 @@ */ package org.tizen.common.core.command.sdb; +import static java.lang.Boolean.TRUE; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.powermock.api.mockito.PowerMockito.mock; import static org.powermock.api.mockito.PowerMockito.when; @@ -39,6 +42,7 @@ import org.tizen.sdblib.IDevice; import org.tizen.sdblib.exception.SdbCommandRejectedException; import org.tizen.sdblib.exception.TimeoutException; import org.tizen.sdblib.service.FileEntry; +import org.tizen.sdblib.service.NullSyncProgressMonitor; import org.tizen.sdblib.service.SyncResult; import org.tizen.sdblib.service.SyncService; @@ -61,10 +65,9 @@ extends CommandTest public void test_execute() throws Exception { final IDevice mockDevice = mock( IDevice.class ); final SyncService mockService = mock( SyncService.class ); - final FileEntry file = mock( FileEntry.class ); SyncResult r = mock( SyncResult.class ); - when( mockService.pull( file, "localPath" ) ) - .thenReturn( r ); + when( mockService.pull( any( FileEntry[].class ) , eq( "localPath" ), eq( NullSyncProgressMonitor.getInstance() ) ) ).thenReturn( r ); + when( r.isOk() ).thenReturn( TRUE ); PullSdbCommand testCommand = new PullSdbCommand( "remotePath", "localPath" ) { @@ -78,8 +81,4 @@ extends CommandTest testCommand.run( null, context ); } - @Override - public String toString() { - return getClass().getSimpleName() + ":" + getClass().getClassLoader(); - } } diff --git a/org.tizen.common/test/src/org/tizen/common/core/command/sdb/PushSdbCommandTest.java b/org.tizen.common/test/src/org/tizen/common/core/command/sdb/PushSdbCommandTest.java old mode 100644 new mode 100755 index 8de7eef..2dc553a --- a/org.tizen.common/test/src/org/tizen/common/core/command/sdb/PushSdbCommandTest.java +++ b/org.tizen.common/test/src/org/tizen/common/core/command/sdb/PushSdbCommandTest.java @@ -25,16 +25,22 @@ */ package org.tizen.common.core.command.sdb; +import static java.lang.Boolean.TRUE; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; import java.io.IOException; -import java.lang.reflect.Constructor; import org.junit.Test; import org.tizen.common.core.command.CommandTest; import org.tizen.sdblib.IDevice; import org.tizen.sdblib.exception.SdbCommandRejectedException; import org.tizen.sdblib.exception.TimeoutException; +import org.tizen.sdblib.service.FileEntry; +import org.tizen.sdblib.service.NullSyncProgressMonitor; +import org.tizen.sdblib.service.SyncResult; import org.tizen.sdblib.service.SyncService; /** @@ -51,14 +57,18 @@ PushSdbCommandTest extends CommandTest { @Test - public void test_execute() throws Exception { - IDevice mockDevice = mock( IDevice.class ); - Class serviceClass = SyncService.class; - Constructor[] con = serviceClass.getDeclaredConstructors(); - con[0].setAccessible( true ); - final SyncService mockService = (SyncService) con[0].newInstance( null, null ); + public + void + test_execute() + throws Exception + { + final IDevice mockDevice = mock( IDevice.class ); + final SyncService mockService = mock( SyncService.class ); + final SyncResult result = mock( SyncResult.class ); + when( mockService.push( any( String[].class ), any( FileEntry.class ), eq( NullSyncProgressMonitor.getInstance() ) ) ).thenReturn( result ); + when( result.isOk() ).thenReturn( TRUE ); - PushSdbCommand testCommand = new PushSdbCommand( "sourcePath", "targetPath" ) { + final PushSdbCommand testCommand = new PushSdbCommand( "sourcePath", "targetPath" ) { @Override protected SyncService getSyncService() throws TimeoutException, SdbCommandRejectedException, IOException {