From: Dmitriy Nikiforov Date: Thu, 28 Apr 2016 17:45:56 +0000 (+0300) Subject: SRADA-374: Fixed errors in Dynamic Analyzer unit tests sources. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d0a7d5a1b81965ee5424ff5dd7c0c69b7e24b912;p=sdk%2Ftools%2Fdynamic-analyzer.git SRADA-374: Fixed errors in Dynamic Analyzer unit tests sources. 1) Added @Ignore annotation to AnalyzerUtil tests. These test now all fail as tested functionality is not yet implemented so they must be ignored. 2) Fixed org.tizen.dynamicanalyzer.ui.file.data tests Changed hardcoded pathes to Tizen-SDK to current directory with following deletion of all created files in cleanup. For that purpose Apache Commons IO library was added to 'test/lib' (same version as in org.tizen.common). Added calls of SqlConnectionManager.releaseResultSet() to FileApiDBTest. Without it test hung on SqlConnectionManager.closeConnection(). 3) Fixed FileChartBoardTest from org.tizen.dynamicanalyzer.ui.file Injected FileDataMaker mock object into FileChartBoard object to avoid NullPointerException. Marked test with @Ignore as it does not test anything now. 4) Fixed ExecutionCallbackManagerTest This test relied on tests execution order which was changed in later JUnit versions. Tests verified number of executions of methods from the same objects. This resulted in doubled numbers in the second test. 5) Fixed FileDataMakerTest Changed database path to relative to current directory with cleanup after all tests. Change-Id: I0ffb803f1e12fdd799aa7494a99335dd27d4970c --- diff --git a/org.tizen.dynamicanalyzer.common/test/src/org/tizen/dynamicanalyzer/common/ExecutionCallbackManagerTest.java b/org.tizen.dynamicanalyzer.common/test/src/org/tizen/dynamicanalyzer/common/ExecutionCallbackManagerTest.java index acf6175..b6d0789 100644 --- a/org.tizen.dynamicanalyzer.common/test/src/org/tizen/dynamicanalyzer/common/ExecutionCallbackManagerTest.java +++ b/org.tizen.dynamicanalyzer.common/test/src/org/tizen/dynamicanalyzer/common/ExecutionCallbackManagerTest.java @@ -25,7 +25,6 @@ package org.tizen.dynamicanalyzer.common; - import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeastOnce; @@ -34,49 +33,56 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.tizen.dynamicanalyzer.callback.ExecutionCallbackManager; import org.tizen.dynamicanalyzer.callback.IExecutionCallback; import org.tizen.dynamicanalyzer.unittest.UnitTestUtil; - public class ExecutionCallbackManagerTest { public class PostWindowOpenCallback implements IExecutionCallback { public void execute() { } - + public void execute(String[] msg) { execute(); } } - - public static final String TEST_CALLBACK_NAME1 = "Test.CallBack"; - public static final String TEST_CALLBACK_NAME3 = "Test.CallBack3"; - private static IExecutionCallback exeCallback1 = mock(IExecutionCallback.class); - private static IExecutionCallback exeCallback2 = mock(PostWindowOpenCallback.class); - private static IExecutionCallback exeCallback3 = mock(IExecutionCallback.class); - - public ExecutionCallbackManagerTest() { + public static final String TEST_CALLBACK_NAME1 = "Test.CallBack"; + public static final String TEST_CALLBACK_NAME2 = "Test.CallBack2"; + + public static IExecutionCallback exeCallback1; + public static IExecutionCallback exeCallback2; + public static IExecutionCallback exeCallback3; + + @Before + public void setUp() { + exeCallback1 = mock(IExecutionCallback.class); + exeCallback2 = mock(PostWindowOpenCallback.class); + exeCallback3 = mock(IExecutionCallback.class); + ExecutionCallbackManager.createCallbackList(TEST_CALLBACK_NAME1); - ExecutionCallbackManager.createCallbackList(TEST_CALLBACK_NAME3); + ExecutionCallbackManager.createCallbackList(TEST_CALLBACK_NAME2); + ExecutionCallbackManager.registerCallback(TEST_CALLBACK_NAME1, exeCallback1); ExecutionCallbackManager.registerCallback(TEST_CALLBACK_NAME1, exeCallback2); - ExecutionCallbackManager.registerCallback(TEST_CALLBACK_NAME3, exeCallback2); - ExecutionCallbackManager.registerCallback(TEST_CALLBACK_NAME3, exeCallback3); - boolean failed = ExecutionCallbackManager.registerCallback("UNKNOWN", exeCallback3); + ExecutionCallbackManager.registerCallback(TEST_CALLBACK_NAME2, exeCallback2); + ExecutionCallbackManager.registerCallback(TEST_CALLBACK_NAME2, exeCallback3); + ExecutionCallbackManager.registerCallback("UNKNOWN", exeCallback3); } - + @Test public void testExecuteCallbackString() { ExecutionCallbackManager.executeCallback(TEST_CALLBACK_NAME1); - ExecutionCallbackManager.executeCallback(TEST_CALLBACK_NAME3); + ExecutionCallbackManager.executeCallback(TEST_CALLBACK_NAME2); ExecutionCallbackManager.executeCallback("UNKNOWN"); - verify(exeCallback1, atLeastOnce()).execute(); + verify(exeCallback1, times(1)).execute(); verify(exeCallback2, times(2)).execute(); - verify(exeCallback3, atLeast(1)).execute(); + verify(exeCallback3, times(1)).execute(); } @Test @@ -87,12 +93,12 @@ public class ExecutionCallbackManagerTest { testArrayString[2] = anyString(); ExecutionCallbackManager.executeCallback(TEST_CALLBACK_NAME1, testArrayString); - ExecutionCallbackManager.executeCallback(TEST_CALLBACK_NAME3, testArrayString); + ExecutionCallbackManager.executeCallback(TEST_CALLBACK_NAME2, testArrayString); ExecutionCallbackManager.executeCallback("UNKNOWN", testArrayString); - verify(exeCallback1, times(2)).execute(testArrayString); - verify(exeCallback2, times(4)).execute(testArrayString); - verify(exeCallback3, atMost(3)).execute(testArrayString); + verify(exeCallback1, times(1)).execute(testArrayString); + verify(exeCallback2, times(2)).execute(testArrayString); + verify(exeCallback3, times(1)).execute(testArrayString); } } diff --git a/org.tizen.dynamicanalyzer/test/lib/commons-io-2.4.jar b/org.tizen.dynamicanalyzer/test/lib/commons-io-2.4.jar new file mode 100644 index 0000000..90035a4 Binary files /dev/null and b/org.tizen.dynamicanalyzer/test/lib/commons-io-2.4.jar differ diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/FileChartBoardTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/FileChartBoardTest.java index 9f31e99..6c278a5 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/FileChartBoardTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/FileChartBoardTest.java @@ -2,17 +2,24 @@ package org.tizen.dynamicanalyzer.ui.file; import static org.mockito.Mockito.mock; +import org.junit.Ignore; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; import org.powermock.reflect.Whitebox; +import org.tizen.dynamicanalyzer.ui.file.manager.FileDataMaker; +@Ignore("Not implemented") +@RunWith(MockitoJUnitRunner.class) public class FileChartBoardTest { + @Mock private FileDataMaker dataMake; + @InjectMocks private FileChartBoard chartBoard = mock(FileChartBoard.class); + @Test public void testAddNewFileChartRows() throws Exception { - FileChartBoard chartBoard = mock(org.tizen.dynamicanalyzer.ui.file.FileChartBoard.class); Whitebox.invokeMethod(chartBoard,"addNewFileChartRows"); } - - - } diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessDBTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessDBTest.java index 01e5056..86bd879 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessDBTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessDBTest.java @@ -9,6 +9,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.commons.io.FileUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -20,13 +21,13 @@ import org.tizen.dynamicanalyzer.ui.file.model.FileAccess; public class FileAccessDBTest { static FileAccessDB accessDB = null; static FileAccess access = null; + static String path = null; @BeforeClass public static void initDB() throws Exception { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("_yyyy-MM-dd-HH-mm-ss"); - String path = "/home/kim/tizen-sdk-data/dynamic-analyzer/temp/app" - + format.format(date); + path = "app" + format.format(date); SqlConnectionManager.establishConnection(path + File.separator + AnalyzerConstants.DATABASE_NAME); @@ -54,6 +55,7 @@ public class FileAccessDBTest { @AfterClass public static void done() throws Exception { SqlConnectionManager.closeConnection(); + FileUtils.deleteDirectory(new File(path)); } } diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessorDBTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessorDBTest.java index 6ed5e03..e0038b5 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessorDBTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileAccessorDBTest.java @@ -9,6 +9,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.commons.io.FileUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -20,13 +21,13 @@ import org.tizen.dynamicanalyzer.ui.file.model.FileAccessor; public class FileAccessorDBTest { static FileAccessorDB accessorDB = null; static FileAccessor accessor = null; + static String path = null; @BeforeClass public static void initDB() throws Exception { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("_yyyy-MM-dd-HH-mm-ss"); - String path = "/home/kim/tizen-sdk-data/dynamic-analyzer/temp/app" - + format.format(date); + path = "app" + format.format(date); SqlConnectionManager.establishConnection(path + File.separator + AnalyzerConstants.DATABASE_NAME); @@ -52,5 +53,6 @@ public class FileAccessorDBTest { @AfterClass public static void done() throws Exception { SqlConnectionManager.closeConnection(); + FileUtils.deleteDirectory(new File(path)); } } diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileApiDBTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileApiDBTest.java index 561dcfa..c0e0fbe 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileApiDBTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileApiDBTest.java @@ -12,6 +12,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.commons.io.FileUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -27,14 +28,14 @@ public class FileApiDBTest { static FileEvent event = null; static FileAccessorDB accessorDB = null; static FileAccessor accessor = null; + static String path = null; ArrayList> fileApiList = new ArrayList>(); @BeforeClass public static void initDB() throws Exception { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("_yyyy-MM-dd-HH-mm-ss"); - String path = "/home/kim/tizen-sdk-data/dynamic-analyzer/temp/app" - + format.format(date); + path = "app" + format.format(date); SqlConnectionManager.establishConnection(path + File.separator + AnalyzerConstants.DATABASE_NAME); @@ -52,7 +53,7 @@ public class FileApiDBTest { new Long(27), new Long(6), null, null, 0 ); } - + @Test public final void testSelectAPI() { ArrayList> fileApiList = new ArrayList>(); @@ -81,6 +82,8 @@ public class FileApiDBTest { } } catch (SQLException e) { Logger.exception(e); + } finally { + SqlConnectionManager.releaseResultSet(rs); } } } @@ -95,13 +98,16 @@ public class FileApiDBTest { } } catch (SQLException e) { Logger.exception(e); - } + } finally { + SqlConnectionManager.releaseResultSet(rs); + } } } - + @AfterClass public static void done() throws Exception { SqlConnectionManager.closeConnection(); + FileUtils.deleteDirectory(new File(path)); } } diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileStatusDBTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileStatusDBTest.java index b867082..62130b3 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileStatusDBTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/data/FileStatusDBTest.java @@ -9,6 +9,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.commons.io.FileUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -21,13 +22,13 @@ public class FileStatusDBTest { static FileStatusDB statusDB = null; static FileStatus status = null; + static String path = null; @BeforeClass public static void initDB() throws Exception { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("_yyyy-MM-dd-HH-mm-ss"); - String path = "/home/kim/tizen-sdk-data/dynamic-analyzer/temp/app" - + format.format(date); + path = "app" + format.format(date); SqlConnectionManager.establishConnection(path + File.separator + AnalyzerConstants.DATABASE_NAME); @@ -52,6 +53,7 @@ public class FileStatusDBTest { @AfterClass public static void done() throws Exception { SqlConnectionManager.closeConnection(); + FileUtils.deleteDirectory(new File(path)); } } diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/manager/FileDataMakerTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/manager/FileDataMakerTest.java index 906c411..4e76201 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/manager/FileDataMakerTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/ui/file/manager/FileDataMakerTest.java @@ -10,6 +10,9 @@ import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Random; + +import org.apache.commons.io.FileUtils; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,6 +32,7 @@ public class FileDataMakerTest { static FileDataManager fileManager = FileDataManager.getInstance();; static FileDataMaker dataMaker = new FileDataMaker(); static String filePath = "/tmp/test1.txt"; + static String path; @BeforeClass public static void setUp() throws Exception { @@ -37,7 +41,7 @@ public class FileDataMakerTest { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("_yyyy-MM-dd-HH-mm-ss"); - String path = "/home/kim/tizen-sdk-data/dynamic-analyzer/temp/app" + format.format(date); + path = "app" + format.format(date); SqlConnectionManager.closeConnection(); SqlConnectionManager.establishConnection(path + File.separator @@ -47,7 +51,11 @@ public class FileDataMakerTest { makeRandomObjects(); } - + + @AfterClass + public static void tearDown() throws Exception { + FileUtils.deleteDirectory(new File(path)); + } public FileDataMakerTest(FileEvent event1, FileEvent event2, FileEvent event3, FileEvent event4, FileEvent event5, FileEvent event6, FileEvent event7, FileEvent event8, FileEvent event9, diff --git a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/utils/AnalyzerUtilTest.java b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/utils/AnalyzerUtilTest.java index 461e2ec..6838487 100644 --- a/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/utils/AnalyzerUtilTest.java +++ b/org.tizen.dynamicanalyzer/test/src/org/tizen/dynamicanalyzer/utils/AnalyzerUtilTest.java @@ -29,150 +29,180 @@ package org.tizen.dynamicanalyzer.utils; import static org.junit.Assert.fail; +import org.junit.Ignore; import org.junit.Test; public class AnalyzerUtilTest { + @Ignore @Test public void testGetTimelineComposite() { fail("Not yet implemented"); } + @Ignore @Test public void testSetTimelineComposite() { fail("Not yet implemented"); } + @Ignore @Test public void testCopyFile() { fail("Not yet implemented"); } + @Ignore @Test public void testCopyDirectory() { fail("Not yet implemented"); } + @Ignore @Test public void testExecuteCommand() { fail("Not yet implemented"); } + @Ignore @Test public void testGetDirs() { fail("Not yet implemented"); } + @Ignore @Test public void testGetFilesString() { fail("Not yet implemented"); } + @Ignore @Test public void testGetFilesStringString() { fail("Not yet implemented"); } + @Ignore @Test public void testSaveTraceImage() { fail("Not yet implemented"); } + @Ignore @Test public void testSetFontSize() { fail("Not yet implemented"); } + @Ignore @Test public void testDeleteFile() { fail("Not yet implemented"); } + @Ignore @Test public void testSetCenterShell() { fail("Not yet implemented"); } + @Ignore @Test public void testSetCenterShellShell() { fail("Not yet implemented"); } + @Ignore @Test public void testChangePage() { fail("Not yet implemented"); } + @Ignore @Test public void testGetTabPage() { fail("Not yet implemented"); } + @Ignore @Test public void testGetMainTab() { fail("Not yet implemented"); } + @Ignore @Test public void testGetView() { fail("Not yet implemented"); } + @Ignore @Test public void testCheckLogs() { fail("Not yet implemented"); } + @Ignore @Test public void testAddrToLong() { fail("Not yet implemented"); } + @Ignore @Test public void testPrintHexdecimal() { fail("Not yet implemented"); } + @Ignore @Test public void testToHexdecimal() { fail("Not yet implemented"); } + @Ignore @Test public void testGetProcessLocalBinaryPath() { fail("Not yet implemented"); } + @Ignore @Test public void testGetBinarySourcePath() { fail("Not yet implemented"); } + @Ignore @Test public void testIsPieBuild() { fail("Not yet implemented"); } + @Ignore @Test public void testGetTargetPathKey() { fail("Not yet implemented"); } + @Ignore @Test public void testTranslateSecToMicroSec() { fail("Not yet implemented"); } + @Ignore @Test public void testGetProcessName() { fail("Not yet implemented"); } + @Ignore @Test public void testIsInteger() { fail("Not yet implemented"); } + @Ignore @Test public void testIsLong() { fail("Not yet implemented");