From: Bon-Yong Lee Date: Thu, 25 Apr 2013 11:51:26 +0000 (+0900) Subject: [Title] Renewal preview X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eccfe1afd5f54148170772f1084ebcf72fc7320b;p=sdk%2Fide%2Fcommon-eplugin.git [Title] Renewal preview [Desc.] Add synchronization with editor and live-highlight [Issue] Redmine-37310 --- diff --git a/org.tizen.common/src/org/tizen/common/daemon/AbstractServer.java b/org.tizen.common/src/org/tizen/common/daemon/AbstractServer.java index 4ac93dc..df296e0 100755 --- a/org.tizen.common/src/org/tizen/common/daemon/AbstractServer.java +++ b/org.tizen.common/src/org/tizen/common/daemon/AbstractServer.java @@ -262,7 +262,10 @@ implements Server, Runnable * @see org.tizen.common.daemon.Server#boot() */ @Override - public void boot() throws Exception + public + void + boot() + throws ServerException { lock.lock(); try @@ -297,7 +300,7 @@ implements Server, Runnable public void down() - throws Exception + throws ServerException { lock.lock(); try diff --git a/org.tizen.common/src/org/tizen/common/daemon/Server.java b/org.tizen.common/src/org/tizen/common/daemon/Server.java index 7987ebf..d0aa687 100755 --- a/org.tizen.common/src/org/tizen/common/daemon/Server.java +++ b/org.tizen.common/src/org/tizen/common/daemon/Server.java @@ -40,14 +40,14 @@ Server /** * boot daemon up * - * @throws Exception If process is failed + * @throws ServerException If process is failed */ - void boot() throws Exception; + void boot() throws ServerException; /** * shut daemon down - * @throws Exception If process is failed + * @throws ServerException If process is failed */ - void down() throws Exception; + void down() throws ServerException; } diff --git a/org.tizen.common/src/org/tizen/common/daemon/ServerException.java b/org.tizen.common/src/org/tizen/common/daemon/ServerException.java new file mode 100755 index 0000000..0c2c6d4 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/daemon/ServerException.java @@ -0,0 +1,97 @@ +/* + * 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.daemon; + +/** + *

+ * ServerException + * + * Exception for server operation + * + *

+ * + * @author BonYong Lee{@literal } (S-Core) + */ +public class +ServerException +extends Exception +{ + + /** + * uuid for serialization + */ + private static final long serialVersionUID = 3662986092815719651L; + + /** + * Default constructor + */ + public + ServerException() + { + super(); + } + + /** + * Constructor with exception message + * + * @param msg exception message + */ + public + ServerException( + final String msg + ) + { + super( msg ); + } + + /** + * Constructor with cause + * + * @param cause cause of this exception + */ + public + ServerException( + final Throwable cause + ) + { + super( cause ); + } + + /** + * Constructor with exception message and cuase + * + * @param msg exception message + * @param cause cause of this exception + */ + public + ServerException( + final String msg, + final Throwable cause + ) + { + super( msg, cause ); + } + +} diff --git a/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java b/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java old mode 100644 new mode 100755 index c8b980a..0f6c0e9 --- a/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/CollectionUtil.java @@ -264,6 +264,8 @@ public class CollectionUtil * * use without null-check for collection * + * safe from modification of element + * * delegate error handling to runner * *

@@ -308,7 +310,8 @@ public class CollectionUtil return ; } - for ( final T arg : collection ) + final Collection safe = new ArrayList( collection ); + for ( final T arg : safe ) { if ( null == arg && !bForceProcess ) { diff --git a/org.tizen.common/src/org/tizen/common/util/DefferedTaskManager.java b/org.tizen.common/src/org/tizen/common/util/DefferedTaskManager.java new file mode 100755 index 0000000..608f0d4 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/DefferedTaskManager.java @@ -0,0 +1,206 @@ +/* +* 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.util; + +import static org.tizen.common.util.Assert.notNull; + +import java.util.Timer; +import java.util.TimerTask; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * DefferedTaskManager. + * + * Object to manage a deffered task. + * + * When {@code #tick()} is called, it is scheduled. + * + * If no interaction during idle time, run task. + * + * @author BonYong Lee{@literal } (S-Core) + */ +public class +DefferedTaskManager +{ + /** + * Default value for idle time + * + * 3 seconds + */ + protected static final long DEFAULT_IDLE_TIME = 3 * 1000; + + /** + * Logger for this class + */ + protected final Logger logger = LoggerFactory.getLogger( getClass() ); + + /** + * Idle time + */ + protected long idleTime; + + /** + * last scheduled time + */ + protected long scheduledTime = DEFAULT_IDLE_TIME; + + /** + * timer for schedule + */ + protected Timer timer = null; + + /** + * Task + */ + protected final Runnable task; + + /** + * Constructor with task + * + * @param task task to run + * + * @see #DefferedTaskManager(Runnable, long) + */ + public + DefferedTaskManager( + final Runnable task + ) + { + this( task, DEFAULT_IDLE_TIME ); + } + + /** + * Constructor with task and ide time + * + * @param task taask to run + * @param idleTime time to waiting + * + * @see #setIdleTime(long) + */ + public + DefferedTaskManager( + final Runnable task, + final long idleTime + ) + { + // Fast-fail + notNull( task ); + this.task = task; + this.idleTime = idleTime; + logger.debug( "Idle time: {}", idleTime ); + } + + /** + * Return idle time for deffering + * + * @return idle time + */ + public + long + getIdleTime() + { + return this.idleTime; + } + + /** + * Set idle time for deffering + * + * @param idleTime time to wait + */ + synchronized public + void + setIdleTime( final long idleTime ) + { + this.idleTime = idleTime; + + if ( null != this.timer ) + { + schedule( this.idleTime + this.scheduledTime - System.currentTimeMillis() ); + } + + } + + /** + * Schedule to run task after {@code delay} + * + * @param delay delay time in milliseconds + */ + synchronized public + void + schedule( long delay ) + { + cancel(); + if ( 0 < delay ) + { + this.timer = new Timer(); + scheduledTime = System.currentTimeMillis(); + this.timer.schedule( new TimerTask() + { + + @Override + public void run() + { + task.run(); + logger.info( "{} was run", task ); + } + }, delay ); + logger.info( "{} will be run after {}", task, delay ); + } + else + { + task.run(); + logger.info( "{} was run", task ); + } + + } + + /** + * Notify any change + */ + public + void + tick() + { + schedule( this.idleTime ); + } + + /** + * Cancel scheduled task + */ + synchronized public + void + cancel() + { + if ( null != timer ) + { + timer.cancel(); + timer = null; + logger.info( "{} canceled", task ); + } + } + +} diff --git a/org.tizen.common/src/org/tizen/common/util/FileUtil.java b/org.tizen.common/src/org/tizen/common/util/FileUtil.java index fb12858..da3a212 100755 --- a/org.tizen.common/src/org/tizen/common/util/FileUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/FileUtil.java @@ -24,8 +24,9 @@ */ package org.tizen.common.util; -import static org.tizen.common.util.IOUtil.redirect; +import static org.tizen.common.util.IOUtil.getString; import static org.tizen.common.util.IOUtil.tryClose; +import static org.tizen.common.util.StringUtil.nvl; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -40,6 +41,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.io.Reader; import java.net.URL; import java.util.ArrayList; import java.util.Collections; @@ -47,13 +49,16 @@ import java.util.HashSet; import java.util.List; import java.util.Stack; -import org.tizen.common.util.log.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Changhyun Lee {@literal } (S-Core) */ public class FileUtil { private static final int BUFFER_SIZE = 8192; + + protected static final Logger logger = LoggerFactory.getLogger( FileUtil.class ); /** * Create directory. @@ -202,32 +207,41 @@ public class FileUtil { } /** - * Read text from given inputStream. + * Read text from given {@code input} + * + * must not null {@code input} * - * @param input - * @param encoding + * @param input input stream to read + * @param encoding encoding for convert byte to char * * @return content from input * - * @throws IOException + * @throws IOException If can't read from {@code input} * */ - public static String readTextStream(InputStream input, String encoding) throws IOException { - StringBuilder text = new StringBuilder(); - BufferedReader in = null; - - if (encoding == null) { // if encoding is not set then use default encoding - encoding = System.getProperty("file.encoding"); - } + public static + String + readTextStream( + final InputStream input, + String encoding + ) + throws IOException + { + Assert.notNull( input ); + Reader in = null; + + // if encoding is not set then use default encoding + encoding = nvl( encoding, System.getProperty("file.encoding") ); try { - in = new BufferedReader(new InputStreamReader(input, encoding), BUFFER_SIZE); - redirect( in, text ); + return getString( new BufferedReader( + in = new InputStreamReader( input, encoding ), + BUFFER_SIZE + ) ); } finally { tryClose( in ); } - return text.toString(); } /** @@ -420,7 +434,7 @@ public class FileUtil { File fromDir = new File(from); File toDir = new File(to); if (fromDir.exists() == false) { - Logger.error("Directory " + fromDir.getCanonicalPath() + " does not exist."); + logger.warn( "Directory {} does not exist.", fromDir.getCanonicalPath() ); return; } checkDirectory(fromDir, toDir); diff --git a/org.tizen.common/src/org/tizen/common/util/ObjectUtil.java b/org.tizen.common/src/org/tizen/common/util/ObjectUtil.java old mode 100644 new mode 100755 index 3c0f2f8..d880a8b --- a/org.tizen.common/src/org/tizen/common/util/ObjectUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/ObjectUtil.java @@ -234,7 +234,7 @@ public class ObjectUtil { { buffer.append( '0' ); } - buffer.append( str ); + buffer.append( str.subSequence( str.length() - Math.min( str.length(), length ), str.length() ) ); return buffer.toString(); } @@ -324,7 +324,7 @@ public class ObjectUtil { guid.append( hexFormat( node, 8 ) ); return guid.toString(); } - + /* Serialize / Deserialize */ /** * Serialize object diff --git a/org.tizen.common/src/org/tizen/common/util/ReflectionUtil.java b/org.tizen.common/src/org/tizen/common/util/ReflectionUtil.java index e4d911f..4f2b493 100755 --- a/org.tizen.common/src/org/tizen/common/util/ReflectionUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/ReflectionUtil.java @@ -27,38 +27,82 @@ package org.tizen.common.util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * ReflectionUtil. + * + * Helper related to java reflection + * + * @author BonYong Lee{@literal } (S-Core) + */ public class ReflectionUtil { + /** + * Logger for this class + */ protected static final Logger logger = LoggerFactory.getLogger( ReflectionUtil.class ); + /** + * Create instance whose class is {@code className} + * + * @param className class name + * + * @return instance of {@code className} + * + * @see #tryNewInstance(String, ClassLoader) + */ public static - Object + + T tryNewInstance( final String className ) { - return tryNewInstance( className, Thread.currentThread().getContextClassLoader() ); + final ClassLoader cl = Thread.currentThread().getContextClassLoader(); + return tryNewInstance( className, cl ); } + + /** + * Create instance whose class is {@code className} from {@code loader} + * + * using {@link Class#newInstance()}. + * + * return {@code null} if creation fails. + * + * @param className class name + * @param loader classloader + * + * @return instance of {@code className} + * + * @see Class#newInstance() + */ + @SuppressWarnings("unchecked") public static - Object + + T tryNewInstance( final String className, final ClassLoader loader ) { - try + try + { + final Class clazz = loader.loadClass( className ); + return (T) clazz.newInstance(); + } + catch ( final ClassNotFoundException e ) + { + logger.info( "Class not found:", e ); + } + catch ( final InstantiationException e ) { - final Class clazz = loader.loadClass( className ); - return clazz.newInstance(); + logger.info( "Fail to instantiate:", e ); } - catch ( Throwable e) + catch ( final IllegalAccessException e ) { - logger.info( "Exception occurred :", e ); - return null; + logger.info( "An access of constructor fail:", e ); } + return null; } - - } diff --git a/org.tizen.common/src/org/tizen/common/util/log/UserInteraction.java b/org.tizen.common/src/org/tizen/common/util/log/UserInteraction.java new file mode 100755 index 0000000..0d05eef --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/util/log/UserInteraction.java @@ -0,0 +1,84 @@ +/* + * 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.util.log; + +/** + *

+ * UserInteraction + * + * Declaration for user interaction + *

    + *
  • View to see
  • + *
  • Action to run
  • + *
+ * + * + * Rule to name for view and action + *
    + *
  • Use prefix 'CATE_', CATE_$(group) for category variable name
  • + *
  • Use group name and action, $(group)_$(action) for action variable name
  • + *
  • Use name hierachy with dot( '.' ) for action constants contents
  • + *
      + *

      + * + * @author BonYong Lee{@literal } (S-Core) + */ +public class +UserInteraction +{ + + /* Preview category */ + /** + * view and actions for Preview + */ + public static final String CATE_PREVIEW = "preview"; + + /** + * Action to open preview + */ + public static final String PREVIEW_OPEN = "preview.open"; + + /** + * Action to reload preview + */ + public static final String PREVIEW_RELOAD = "preview.reload"; + + /** + * Action to highlight on cursor + */ + public static final String PREVIEW_HIGHLIGHT = "preview.highlight"; + + /** + * Action to close preview + */ + public static final String PREVIEW_CLOSE = "preview.close"; + + + /** + * Preview preference page + */ + public static final String CATE_PREVIEW_SETTING = "preview.setting"; + +} diff --git a/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java b/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java index 1759ddb..a7816d5 100755 --- a/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java +++ b/org.tizen.common/test/src/org/tizen/common/util/CollectionUtilTest.java @@ -1020,8 +1020,7 @@ CollectionUtilTest List result = CollectionUtil.resolveSetAsList(set); for(int i=0; i + * + * 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.util; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.tizen.common.util.ThreadUtil.trySleep; + +import org.junit.Test; + +/** + * DefferedTaskManagerTest + * + * Test case for {@link DefferedTaskManager} + * + * @author BonYong Lee{@literal } (S-Core) + * + * @see DefferedTaskManager + */ +public class +DefferedTaskManagerTest +{ + + /** + * Test {@link DefferedTaskManager#tick()} + * + * @throws Exception in case of failure in test + * + * @see DefferedTaskManager#tick() + */ + @Test + public + void + test_tick() + { + final Runnable run = mock( Runnable.class ); + final DefferedTaskManager target = new DefferedTaskManager( run ); + target.setIdleTime( 100 ); + target.tick(); + verifyNoMoreInteractions( run ); + + trySleep( 100 ); + verify( run ).run(); + target.tick(); + trySleep( 50 ); + verifyNoMoreInteractions( run ); + target.setIdleTime( 50 ); + verify( run, times( 2 ) ).run(); + + target.tick(); + verifyNoMoreInteractions( run ); + target.setIdleTime( 100 ); + verifyNoMoreInteractions( run ); + trySleep( 50 ); + verifyNoMoreInteractions( run ); + target.setIdleTime( 150 ); + verifyNoMoreInteractions( run ); + trySleep( 50 ); + verifyNoMoreInteractions( run ); + target.setIdleTime( 200 ); + verifyNoMoreInteractions( run ); + trySleep( 200 ); + verify( run, times( 3 ) ).run(); + + } + + +} 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 old mode 100644 new mode 100755 index 54b6312..4adc5ee --- a/org.tizen.common/test/src/org/tizen/common/util/FileUtilTest.java +++ b/org.tizen.common/test/src/org/tizen/common/util/FileUtilTest.java @@ -24,7 +24,12 @@ */ package org.tizen.common.util; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +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.tizen.common.util.IOUtil.tryClose; import java.io.ByteArrayInputStream; import java.io.File; @@ -46,20 +51,33 @@ import org.junit.Test; * * @see FileUtil */ -public class FileUtilTest { +public class +FileUtilTest +{ + /** + * Target directory for test + */ public static final String TEST_RESOURCE_DEST = "test/_test_files"; + + /** + * Source directory for test + */ public static final String TEST_RESOURCE_SRC = "test/test_files"; /** - * Test {@link FileUtil#getFileExtension(String)} + * Test for {@link FileUtil#getFileExtension(String)} * * @throws Exception in case of failure in test * - * @see {@link FileUtil#getFileExtension(String)} + * @see FileUtil#getFileExtension(String) */ @Test - public void test_getFileExtension() throws Exception { + public + void + test_getFileExtension() + throws Exception + { final Object[][] TEST_CASES = new Object[][] { new Object[] { "aaaa.exe", "exe" }, new Object[] { "index.html", "html" }, @@ -84,65 +102,62 @@ public class FileUtilTest { } /** - * Test case for {@link FileUtil#getFileNameFromPath(String)} + * Test for {@link FileUtil#getFileNameFromPath(String)} * - * @throws Exception + * @throws Exception If test fails */ - public void test_getFileNameFromPath() throws Exception { - final String[][] testCases = { + public + void + test_getFileNameFromPath() + throws Exception + { + final String[][] TEST_CASES = { {"ASDFwew/jkl/wer23/gfdgfdg", "gfdgfdg"}, {"wekljf\\hgrfg\\wefwv1.aaa", "wefwv1.aaa"}, {null, null}, {"ggg.sss", "ggg.sss"} }; - for(String[] testCase: testCases) { - String result = FileUtil.getFileNameFromPath(testCase[0]); - assertEquals(testCase[1], result); + for( final String[] TEST_CASE: TEST_CASES ) + { + String result = FileUtil.getFileNameFromPath(TEST_CASE[0]); + assertEquals(TEST_CASE[1], result); } } /** - * Test {@link FileUtil#readTextStream(InputStream input, String encoding)} + * Test for {@link FileUtil#readTextStream(InputStream input, String encoding)} * * @throws Exception in case of failure in test * * @see {@link FileUtil#readTextStream(InputStream input, String encoding)} */ @Test - public void test_readTextStream() throws Exception { - String text = "Test Text 123"; - String unicodeText = "\uD55C\uAE00\uD14C\uC2A4\uD2B8"; + public + void + test_readTextStream() + throws Exception + { + final String text = "Test Text 123"; + final String unicodeText = "\uD55C\uAE00\uD14C\uC2A4\uD2B8"; try { FileUtil.readTextStream(null, null); fail( "readTextStream must throw exception" ); - } catch (Exception e) { + } catch ( final Exception e ) { } - InputStream input = new ByteArrayInputStream(text.getBytes()); - String content = FileUtil.readTextStream(input, null); + final InputStream input = new ByteArrayInputStream(text.getBytes()); + final String content = FileUtil.readTextStream(input, null); assertEquals(text, content); - InputStream unicodeInput = new ByteArrayInputStream(unicodeText.getBytes("UTF-8")); - String unicodeContent = FileUtil.readTextStream(unicodeInput, "UTF-8"); + final InputStream unicodeInput = new ByteArrayInputStream(unicodeText.getBytes("UTF-8")); + final String unicodeContent = FileUtil.readTextStream(unicodeInput, "UTF-8"); assertEquals(unicodeText, unicodeContent); - String isoContent = FileUtil.readTextStream(unicodeInput, "ISO-8859-1"); + final String isoContent = FileUtil.readTextStream(unicodeInput, "ISO-8859-1"); assertNotSame(unicodeText, isoContent); - - if (input != null) { - input.close(); - } - if (unicodeInput != null) { - unicodeInput.close(); - } - } - - @Test - public void test_findFiles() throws Exception{ - final Object [][] TEST_CASE = new Object[][] { - new Object[] {"",""}, - }; + + tryClose( input, unicodeContent ); } /** diff --git a/org.tizen.common/test/src/org/tizen/common/util/ObjectUtilTest.java b/org.tizen.common/test/src/org/tizen/common/util/ObjectUtilTest.java old mode 100644 new mode 100755 index 23c40ec..0db2549 --- a/org.tizen.common/test/src/org/tizen/common/util/ObjectUtilTest.java +++ b/org.tizen.common/test/src/org/tizen/common/util/ObjectUtilTest.java @@ -32,17 +32,26 @@ import org.junit.Test; /** * ObjectUtilTest. * - * Helper related to {@link ObjectUtil} + * Test case for {@link ObjectUtil} * * @author BonYong Lee{@literal } (S-Core) * @author TaeYoung Son{@literal } (S-Core) * * @see ObjectUtil - * */ -public class ObjectUtilTest { +public class +ObjectUtilTest +{ + /** + * Test for {@link ObjectUtil#nvl(Object...)} + * + * @throws Exception If test fails + */ @Test - public void test_nvl() throws Exception { + public + void + test_nvl() + { final Object[][] TEST_CASES = new Object[][] { new Object[] { null, null }, new Object[] { new Object[] { null }, null }, @@ -61,8 +70,16 @@ public class ObjectUtilTest { } } + /** + * Test for {@link ObjectUtil#equals(Object, Object)} + * + * @throws Exception If test fails + */ @Test - public void test_equals() { + public + void + test_equals() + { final Object[][] TEST_CASES = new Object[][] { new Object[] { null, null, true }, new Object[] { null, "a", false }, @@ -76,7 +93,8 @@ public class ObjectUtilTest { false } }; int nTestCase = 0; - for (final Object[] TEST_CASE : TEST_CASES) { + for (final Object[] TEST_CASE : TEST_CASES) + { nTestCase++; final Object input1 = (Object) TEST_CASE[0]; final Object input2 = (Object) TEST_CASE[1]; @@ -88,20 +106,29 @@ public class ObjectUtilTest { } } + /** + * Test for {@link ObjectUtil#hexFormat(int, int)} + * + * @throws Exception If test fails + */ @Test - public void test_hexFormat() { + public + void + test_hexFormat() + { final Object[][] TEST_CASES = new Object[][] { - new Object[] { 0, 0, "0" }, + new Object[] { 0, 0, "" }, new Object[] { 0, 2, "00" }, new Object[] { 15, 1, "f" }, new Object[] { 15, 3, "00f" }, new Object[] { 2147483647, 10, "007fffffff" }, new Object[] { -2147483647, 10, "0080000001" }, - new Object[] { -1, 1, "ffffffff" } + new Object[] { -1, 1, "f" } }; int nTestCase = 0; - for (final Object[] TEST_CASE : TEST_CASES) { + for ( final Object[] TEST_CASE : TEST_CASES ) + { nTestCase++; final Object input1 = TEST_CASE[0]; final Object input2 = TEST_CASE[1]; @@ -115,8 +142,16 @@ public class ObjectUtilTest { } + /** + * Test for {@link ObjectUtil#toString(Object)} + * + * @throws Exception If test fails + */ @Test - public void test_toString() { + public + void + test_toString() + { final Object[][] TEST_CASES = new Object[][] { new Object[] { null, "<>" }, new Object[] { "null", "String@C587" }, diff --git a/org.tizen.common/test/src/org/tizen/common/util/ReflectionUtilTest.java b/org.tizen.common/test/src/org/tizen/common/util/ReflectionUtilTest.java new file mode 100755 index 0000000..904ee29 --- /dev/null +++ b/org.tizen.common/test/src/org/tizen/common/util/ReflectionUtilTest.java @@ -0,0 +1,70 @@ +/* +* 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.util; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.tizen.common.util.Assert.fail; + +import org.junit.Test; + +/** + * ReflectionUtilTest + * + * Test case for {@link ReflectionUtil} + * + * @author BonYong Lee{@literal } (S-Core) + * + * @see ReflectionUtil + */ +public class +ReflectionUtilTest +{ + + /** + * Test for {@link ReflectionUtil#tryNewInstance(String)} and + * {@link ReflectionUtil#tryNewInstance(String, ClassLoader)} + */ + @Test + public + void + test_tryNewInstance() + { + assertNotNull( ReflectionUtil.tryNewInstance( "java.lang.Object" ) ); + assertNull( ReflectionUtil.tryNewInstance( "aaaa" ) ); + + assertNotNull( ReflectionUtil.tryNewInstance( "java.lang.Object", Thread.currentThread().getContextClassLoader() ) ); + assertNull( ReflectionUtil.tryNewInstance( "aaaa", Thread.currentThread().getContextClassLoader() ) ); + try + { + ReflectionUtil.tryNewInstance( "aaaa", null ); + fail( "Test must fail" ); + } + catch ( final NullPointerException e ) + { + } + } + +}