* @see org.tizen.common.daemon.Server#boot()\r
*/\r
@Override\r
- public void boot() throws Exception\r
+ public\r
+ void\r
+ boot()\r
+ throws ServerException\r
{\r
lock.lock();\r
try\r
public\r
void\r
down()\r
- throws Exception\r
+ throws ServerException\r
{\r
lock.lock();\r
try\r
/**\r
* boot daemon up\r
* \r
- * @throws Exception If process is failed\r
+ * @throws ServerException If process is failed\r
*/\r
- void boot() throws Exception;\r
+ void boot() throws ServerException;\r
\r
/**\r
* shut daemon down\r
- * @throws Exception If process is failed\r
+ * @throws ServerException If process is failed\r
*/\r
- void down() throws Exception;\r
+ void down() throws ServerException;\r
\r
}\r
--- /dev/null
+/*\r
+ * Common\r
+ *\r
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Contact: \r
+ * BonYong Lee <bonyong.lee@samsung.com>\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * Contributors:\r
+ * - S-Core Co., Ltd\r
+ *\r
+ */\r
+package org.tizen.common.daemon;\r
+\r
+/**\r
+ * <p>\r
+ * ServerException\r
+ * \r
+ * Exception for server operation\r
+ *\r
+ * </p>\r
+ * \r
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
+ */\r
+public class\r
+ServerException\r
+extends Exception\r
+{\r
+\r
+ /**\r
+ * uuid for serialization\r
+ */\r
+ private static final long serialVersionUID = 3662986092815719651L;\r
+ \r
+ /**\r
+ * Default constructor\r
+ */\r
+ public\r
+ ServerException()\r
+ {\r
+ super();\r
+ }\r
+\r
+ /**\r
+ * Constructor with exception message\r
+ * \r
+ * @param msg exception message\r
+ */\r
+ public\r
+ ServerException(\r
+ final String msg\r
+ )\r
+ {\r
+ super( msg );\r
+ }\r
+ \r
+ /**\r
+ * Constructor with cause\r
+ * \r
+ * @param cause cause of this exception\r
+ */\r
+ public\r
+ ServerException(\r
+ final Throwable cause\r
+ )\r
+ {\r
+ super( cause );\r
+ }\r
+ \r
+ /**\r
+ * Constructor with exception message and cuase\r
+ * \r
+ * @param msg exception message\r
+ * @param cause cause of this exception\r
+ */\r
+ public\r
+ ServerException(\r
+ final String msg,\r
+ final Throwable cause\r
+ )\r
+ {\r
+ super( msg, cause );\r
+ }\r
+ \r
+}\r
*
* use without null-check for <code>collection</code>
*
+ * safe from modification of element
+ *
* delegate error handling to <code>runner</code>
*
* </p>
return ;
}
- for ( final T arg : collection )
+ final Collection<T> safe = new ArrayList<T>( collection );
+ for ( final T arg : safe )
{
if ( null == arg && !bForceProcess )
{
--- /dev/null
+/*\r
+* Common\r
+*\r
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+*\r
+* Contact: \r
+* BonYong Lee <bonyong.lee@samsung.com>\r
+* \r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*\r
+* Contributors:\r
+* - S-Core Co., Ltd\r
+*\r
+*/\r
+package org.tizen.common.util;\r
+\r
+import static org.tizen.common.util.Assert.notNull;\r
+\r
+import java.util.Timer;\r
+import java.util.TimerTask;\r
+\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * DefferedTaskManager.\r
+ * \r
+ * Object to manage a deffered task.\r
+ * \r
+ * When {@code #tick()} is called, it is scheduled.\r
+ * \r
+ * If no interaction during idle time, run task.\r
+ * \r
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
+ */\r
+public class\r
+DefferedTaskManager\r
+{\r
+ /**\r
+ * Default value for idle time\r
+ * \r
+ * 3 seconds\r
+ */\r
+ protected static final long DEFAULT_IDLE_TIME = 3 * 1000;\r
+ \r
+ /**\r
+ * Logger for this class\r
+ */\r
+ protected final Logger logger = LoggerFactory.getLogger( getClass() );\r
+ \r
+ /**\r
+ * Idle time\r
+ */\r
+ protected long idleTime;\r
+ \r
+ /**\r
+ * last scheduled time\r
+ */\r
+ protected long scheduledTime = DEFAULT_IDLE_TIME;\r
+ \r
+ /**\r
+ * timer for schedule\r
+ */\r
+ protected Timer timer = null;\r
+ \r
+ /**\r
+ * Task\r
+ */\r
+ protected final Runnable task;\r
+ \r
+ /**\r
+ * Constructor with task\r
+ * \r
+ * @param task task to run\r
+ * \r
+ * @see #DefferedTaskManager(Runnable, long)\r
+ */\r
+ public\r
+ DefferedTaskManager(\r
+ final Runnable task\r
+ )\r
+ {\r
+ this( task, DEFAULT_IDLE_TIME );\r
+ }\r
+ \r
+ /**\r
+ * Constructor with task and ide time\r
+ * \r
+ * @param task taask to run\r
+ * @param idleTime time to waiting\r
+ * \r
+ * @see #setIdleTime(long)\r
+ */\r
+ public\r
+ DefferedTaskManager(\r
+ final Runnable task,\r
+ final long idleTime\r
+ )\r
+ {\r
+ // Fast-fail\r
+ notNull( task );\r
+ this.task = task;\r
+ this.idleTime = idleTime;\r
+ logger.debug( "Idle time: {}", idleTime );\r
+ }\r
+ \r
+ /**\r
+ * Return idle time for deffering\r
+ * \r
+ * @return idle time\r
+ */\r
+ public\r
+ long\r
+ getIdleTime()\r
+ {\r
+ return this.idleTime;\r
+ }\r
+\r
+ /**\r
+ * Set idle time for deffering\r
+ * \r
+ * @param idleTime time to wait\r
+ */\r
+ synchronized public\r
+ void\r
+ setIdleTime( final long idleTime )\r
+ {\r
+ this.idleTime = idleTime;\r
+ \r
+ if ( null != this.timer )\r
+ {\r
+ schedule( this.idleTime + this.scheduledTime - System.currentTimeMillis() );\r
+ }\r
+ \r
+ }\r
+ \r
+ /**\r
+ * Schedule to run task after {@code delay}\r
+ * \r
+ * @param delay delay time in milliseconds\r
+ */\r
+ synchronized public\r
+ void\r
+ schedule( long delay )\r
+ {\r
+ cancel();\r
+ if ( 0 < delay )\r
+ {\r
+ this.timer = new Timer();\r
+ scheduledTime = System.currentTimeMillis();\r
+ this.timer.schedule( new TimerTask()\r
+ {\r
+ \r
+ @Override\r
+ public void run()\r
+ {\r
+ task.run();\r
+ logger.info( "{} was run", task );\r
+ }\r
+ }, delay );\r
+ logger.info( "{} will be run after {}", task, delay );\r
+ }\r
+ else\r
+ {\r
+ task.run();\r
+ logger.info( "{} was run", task );\r
+ }\r
+ \r
+ }\r
+ \r
+ /**\r
+ * Notify any change\r
+ */\r
+ public\r
+ void\r
+ tick()\r
+ {\r
+ schedule( this.idleTime );\r
+ }\r
+ \r
+ /**\r
+ * Cancel scheduled task\r
+ */\r
+ synchronized public\r
+ void\r
+ cancel()\r
+ {\r
+ if ( null != timer )\r
+ {\r
+ timer.cancel();\r
+ timer = null;\r
+ logger.info( "{} canceled", task );\r
+ }\r
+ }\r
+\r
+}\r
*/
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;
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;
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 <changhyun1.lee@samsung.com>} (S-Core)
*/
public class FileUtil {
private static final int BUFFER_SIZE = 8192;
+
+ protected static final Logger logger = LoggerFactory.getLogger( FileUtil.class );
/**
* Create directory.
}
/**
- * 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();
}
/**
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);
{
buffer.append( '0' );
}
- buffer.append( str );
+ buffer.append( str.subSequence( str.length() - Math.min( str.length(), length ), str.length() ) );
return buffer.toString();
}
guid.append( hexFormat( node, 8 ) );
return guid.toString();
}
-
+
/* Serialize / Deserialize */
/**
* Serialize object
import org.slf4j.Logger;\r
import org.slf4j.LoggerFactory;\r
\r
+/**\r
+ * ReflectionUtil.\r
+ * \r
+ * Helper related to java reflection\r
+ * \r
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
+ */\r
public class\r
ReflectionUtil\r
{\r
+ /**\r
+ * Logger for this class\r
+ */\r
protected static final Logger logger = LoggerFactory.getLogger( ReflectionUtil.class );\r
\r
+ /**\r
+ * Create instance whose class is {@code className}\r
+ * \r
+ * @param className class name\r
+ * \r
+ * @return instance of {@code className}\r
+ * \r
+ * @see #tryNewInstance(String, ClassLoader)\r
+ */\r
public static\r
- Object\r
+ <T>\r
+ T\r
tryNewInstance(\r
final String className\r
)\r
{\r
- return tryNewInstance( className, Thread.currentThread().getContextClassLoader() );\r
+ final ClassLoader cl = Thread.currentThread().getContextClassLoader();\r
+ return tryNewInstance( className, cl );\r
}\r
+ \r
+ /**\r
+ * Create instance whose class is {@code className} from {@code loader}\r
+ * \r
+ * using {@link Class#newInstance()}.\r
+ * \r
+ * return {@code null} if creation fails.\r
+ * \r
+ * @param className class name\r
+ * @param loader classloader\r
+ * \r
+ * @return instance of {@code className}\r
+ * \r
+ * @see Class#newInstance()\r
+ */\r
+ @SuppressWarnings("unchecked")\r
public static\r
- Object\r
+ <T>\r
+ T\r
tryNewInstance(\r
final String className,\r
final ClassLoader loader\r
)\r
{\r
- try\r
+ try\r
+ {\r
+ final Class<?> clazz = loader.loadClass( className );\r
+ return (T) clazz.newInstance();\r
+ }\r
+ catch ( final ClassNotFoundException e )\r
+ {\r
+ logger.info( "Class not found:", e );\r
+ }\r
+ catch ( final InstantiationException e )\r
{\r
- final Class<?> clazz = loader.loadClass( className );\r
- return clazz.newInstance();\r
+ logger.info( "Fail to instantiate:", e );\r
}\r
- catch ( Throwable e)\r
+ catch ( final IllegalAccessException e )\r
{\r
- logger.info( "Exception occurred :", e );\r
- return null;\r
+ logger.info( "An access of constructor fail:", e );\r
}\r
+ return null;\r
\r
}\r
- \r
-\r
}\r
--- /dev/null
+/*\r
+ * Common\r
+ *\r
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Contact: \r
+ * BonYong Lee <bonyong.lee@samsung.com>\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * Contributors:\r
+ * - S-Core Co., Ltd\r
+ *\r
+ */\r
+package org.tizen.common.util.log;\r
+\r
+/**\r
+ * <p>\r
+ * UserInteraction\r
+ * \r
+ * Declaration for user interaction\r
+ * <ul>\r
+ * <li>View to see</li>\r
+ * <li>Action to run</li>\r
+ * </ul>\r
+ * \r
+ * \r
+ * Rule to name for view and action\r
+ * <ul>\r
+ * <li>Use prefix 'CATE_', CATE_$(group) for category variable name</li>\r
+ * <li>Use group name and action, $(group)_$(action) for action variable name</li>\r
+ * <li>Use name hierachy with dot( '.' ) for action constants contents</li>\r
+ * <ul>\r
+ * </p>\r
+ * \r
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
+ */\r
+public class\r
+UserInteraction\r
+{\r
+\r
+ /* Preview category */\r
+ /**\r
+ * view and actions for Preview\r
+ */\r
+ public static final String CATE_PREVIEW = "preview";\r
+ \r
+ /**\r
+ * Action to open preview\r
+ */\r
+ public static final String PREVIEW_OPEN = "preview.open";\r
+ \r
+ /**\r
+ * Action to reload preview\r
+ */\r
+ public static final String PREVIEW_RELOAD = "preview.reload";\r
+ \r
+ /**\r
+ * Action to highlight on cursor\r
+ */\r
+ public static final String PREVIEW_HIGHLIGHT = "preview.highlight";\r
+ \r
+ /**\r
+ * Action to close preview\r
+ */\r
+ public static final String PREVIEW_CLOSE = "preview.close";\r
+ \r
+ \r
+ /**\r
+ * Preview preference page\r
+ */\r
+ public static final String CATE_PREVIEW_SETTING = "preview.setting";\r
+ \r
+}\r
List<String> result = CollectionUtil.resolveSetAsList(set);
for(int i=0; i<stringArray.length; i++) {
- System.out.println(i);
- assertTrue(result.get(i).equals(stringArray[i]));
+ assertTrue( (i+1) + "th test case: input - " + stringArray[i] , result.get(i).equals(stringArray[i]));
}
}
}
--- /dev/null
+/*\r
+ * Common\r
+ *\r
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Contact: \r
+ * BonYong Lee <bonyong.lee@samsung.com>\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ * Contributors:\r
+ * - S-Core Co., Ltd\r
+ *\r
+ */\r
+package org.tizen.common.util;\r
+\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.times;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.verifyNoMoreInteractions;\r
+import static org.tizen.common.util.ThreadUtil.trySleep;\r
+\r
+import org.junit.Test;\r
+\r
+/**\r
+ * DefferedTaskManagerTest\r
+ *\r
+ * Test case for {@link DefferedTaskManager}\r
+ * \r
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
+ * \r
+ * @see DefferedTaskManager\r
+ */\r
+public class\r
+DefferedTaskManagerTest\r
+{\r
+\r
+ /**\r
+ * Test {@link DefferedTaskManager#tick()}\r
+ * \r
+ * @throws Exception in case of failure in test\r
+ * \r
+ * @see DefferedTaskManager#tick()\r
+ */\r
+ @Test\r
+ public\r
+ void\r
+ test_tick()\r
+ {\r
+ final Runnable run = mock( Runnable.class );\r
+ final DefferedTaskManager target = new DefferedTaskManager( run );\r
+ target.setIdleTime( 100 );\r
+ target.tick();\r
+ verifyNoMoreInteractions( run );\r
+ \r
+ trySleep( 100 );\r
+ verify( run ).run();\r
+ target.tick();\r
+ trySleep( 50 );\r
+ verifyNoMoreInteractions( run );\r
+ target.setIdleTime( 50 );\r
+ verify( run, times( 2 ) ).run();\r
+ \r
+ target.tick();\r
+ verifyNoMoreInteractions( run );\r
+ target.setIdleTime( 100 );\r
+ verifyNoMoreInteractions( run );\r
+ trySleep( 50 );\r
+ verifyNoMoreInteractions( run );\r
+ target.setIdleTime( 150 );\r
+ verifyNoMoreInteractions( run );\r
+ trySleep( 50 );\r
+ verifyNoMoreInteractions( run );\r
+ target.setIdleTime( 200 );\r
+ verifyNoMoreInteractions( run );\r
+ trySleep( 200 );\r
+ verify( run, times( 3 ) ).run();\r
+ \r
+ }\r
+ \r
+\r
+}\r
*/
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;
*
* @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" },
}
/**
- * 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 );
}
/**
/**\r
* ObjectUtilTest.\r
* \r
- * Helper related to {@link ObjectUtil}\r
+ * Test case for {@link ObjectUtil}\r
* \r
* @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
* @author TaeYoung Son{@literal <taeyoung2.son@samsung.com>} (S-Core)\r
* \r
* @see ObjectUtil\r
- * \r
*/\r
-public class ObjectUtilTest {\r
+public class\r
+ObjectUtilTest\r
+{\r
+ /**\r
+ * Test for {@link ObjectUtil#nvl(Object...)}\r
+ * \r
+ * @throws Exception If test fails\r
+ */\r
@Test\r
- public void test_nvl() throws Exception {\r
+ public\r
+ void\r
+ test_nvl()\r
+ {\r
final Object[][] TEST_CASES = new Object[][] {\r
new Object[] { null, null },\r
new Object[] { new Object[] { null }, null },\r
}\r
}\r
\r
+ /**\r
+ * Test for {@link ObjectUtil#equals(Object, Object)}\r
+ * \r
+ * @throws Exception If test fails\r
+ */\r
@Test\r
- public void test_equals() {\r
+ public\r
+ void\r
+ test_equals()\r
+ {\r
final Object[][] TEST_CASES = new Object[][] {\r
new Object[] { null, null, true },\r
new Object[] { null, "a", false },\r
false } };\r
\r
int nTestCase = 0;\r
- for (final Object[] TEST_CASE : TEST_CASES) {\r
+ for (final Object[] TEST_CASE : TEST_CASES)\r
+ {\r
nTestCase++;\r
final Object input1 = (Object) TEST_CASE[0];\r
final Object input2 = (Object) TEST_CASE[1];\r
}\r
}\r
\r
+ /**\r
+ * Test for {@link ObjectUtil#hexFormat(int, int)}\r
+ * \r
+ * @throws Exception If test fails\r
+ */\r
@Test\r
- public void test_hexFormat() {\r
+ public\r
+ void\r
+ test_hexFormat()\r
+ {\r
final Object[][] TEST_CASES = new Object[][] {\r
- new Object[] { 0, 0, "0" },\r
+ new Object[] { 0, 0, "" },\r
new Object[] { 0, 2, "00" },\r
new Object[] { 15, 1, "f" },\r
new Object[] { 15, 3, "00f" },\r
new Object[] { 2147483647, 10, "007fffffff" },\r
new Object[] { -2147483647, 10, "0080000001" },\r
- new Object[] { -1, 1, "ffffffff" }\r
+ new Object[] { -1, 1, "f" }\r
};\r
\r
int nTestCase = 0;\r
- for (final Object[] TEST_CASE : TEST_CASES) {\r
+ for ( final Object[] TEST_CASE : TEST_CASES )\r
+ {\r
nTestCase++;\r
final Object input1 = TEST_CASE[0];\r
final Object input2 = TEST_CASE[1];\r
\r
}\r
\r
+ /**\r
+ * Test for {@link ObjectUtil#toString(Object)}\r
+ * \r
+ * @throws Exception If test fails\r
+ */\r
@Test\r
- public void test_toString() {\r
+ public\r
+ void\r
+ test_toString()\r
+ {\r
final Object[][] TEST_CASES = new Object[][] {\r
new Object[] { null, "<<null>>" },\r
new Object[] { "null", "String@C587" },\r
--- /dev/null
+/*\r
+* Common\r
+*\r
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
+*\r
+* Contact: \r
+* BonYong Lee <bonyong.lee@samsung.com>\r
+* \r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*\r
+* Contributors:\r
+* - S-Core Co., Ltd\r
+*\r
+*/\r
+package org.tizen.common.util;\r
+\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertNull;\r
+import static org.tizen.common.util.Assert.fail;\r
+\r
+import org.junit.Test;\r
+\r
+/**\r
+ * ReflectionUtilTest\r
+ * \r
+ * Test case for {@link ReflectionUtil}\r
+ * \r
+ * @author BonYong Lee{@literal <bonyong.lee@samsung.com>} (S-Core)\r
+ * \r
+ * @see ReflectionUtil\r
+ */\r
+public class\r
+ReflectionUtilTest\r
+{\r
+\r
+ /**\r
+ * Test for {@link ReflectionUtil#tryNewInstance(String)} and\r
+ * {@link ReflectionUtil#tryNewInstance(String, ClassLoader)}\r
+ */\r
+ @Test\r
+ public\r
+ void\r
+ test_tryNewInstance()\r
+ {\r
+ assertNotNull( ReflectionUtil.tryNewInstance( "java.lang.Object" ) );\r
+ assertNull( ReflectionUtil.tryNewInstance( "aaaa" ) );\r
+ \r
+ assertNotNull( ReflectionUtil.tryNewInstance( "java.lang.Object", Thread.currentThread().getContextClassLoader() ) );\r
+ assertNull( ReflectionUtil.tryNewInstance( "aaaa", Thread.currentThread().getContextClassLoader() ) );\r
+ try\r
+ {\r
+ ReflectionUtil.tryNewInstance( "aaaa", null );\r
+ fail( "Test must fail" );\r
+ }\r
+ catch ( final NullPointerException e )\r
+ {\r
+ }\r
+ }\r
+\r
+}\r