diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:03:55 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:03:55 -0800 |
commit | dd828f42a5c83b4270d4fbf6fce2da1878f1e84a (patch) | |
tree | fdd4b68fa1020f2b6426034c94823419a7236200 /logging | |
parent | fdb2704414a9ed92394ada0d1395e4db86889465 (diff) | |
download | libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.zip libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.tar.gz libcore-dd828f42a5c83b4270d4fbf6fce2da1878f1e84a.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'logging')
41 files changed, 5415 insertions, 1283 deletions
diff --git a/logging/src/main/java/java/util/logging/ConsoleHandler.java b/logging/src/main/java/java/util/logging/ConsoleHandler.java index 9cea60f..a88cf0c 100644 --- a/logging/src/main/java/java/util/logging/ConsoleHandler.java +++ b/logging/src/main/java/java/util/logging/ConsoleHandler.java @@ -19,43 +19,47 @@ package java.util.logging; /** * A handler that writes log messages to the standard output stream - * <code>System.err</code>. + * {@code System.err}. * <p> * This handler reads the following properties from the log manager to * initialize itself: * <ul> * <li>java.util.logging.ConsoleHandler.level specifies the logging level, - * defaults to <code>Level.INFO</code> if this property is not found or has an - * invalid value; + * defaults to {@code Level.INFO} if this property is not found or has an + * invalid value. * <li>java.util.logging.ConsoleHandler.filter specifies the name of the filter - * class to be associated with this handler, defaults to <code>null</code> if - * this property is not found or has an invalid value; + * class to be associated with this handler, defaults to {@code null} if this + * property is not found or has an invalid value. * <li>java.util.logging.ConsoleHandler.formatter specifies the name of the * formatter class to be associated with this handler, defaults to - * <code>java.util.logging.SimpleFormatter</code> if this property is not - * found or has an invalid value; + * {@code java.util.logging.SimpleFormatter} if this property is not found or + * has an invalid value. * <li>java.util.logging.ConsoleHandler.encoding specifies the encoding this - * handler will use to encode log messages, defaults to <code>null</code> if - * this property is not found or has an invalid value. + * handler will use to encode log messages, defaults to {@code null} if this + * property is not found or has an invalid value. * </ul> * </p> * <p> * This class is not thread-safe. * </p> * + * @since Android 1.0 */ public class ConsoleHandler extends StreamHandler { /** - * Constructs a <code>ConsoleHandler</code> object. + * Constructs a {@code ConsoleHandler} object. + * + * @since Android 1.0 */ public ConsoleHandler() { super(System.err); } /** - * Closes this handler. The <code>System.err</code> is flushed but not - * closed. + * Closes this handler. The {@code System.err} is flushed but not closed. + * + * @since Android 1.0 */ @Override public void close() { @@ -65,7 +69,10 @@ public class ConsoleHandler extends StreamHandler { /** * Logs a record if necessary. A flush operation will be done. * - * @param record the log record to be logged + * @param record + * the log record to be logged. + * + * @since Android 1.0 */ @Override public void publish(LogRecord record) { diff --git a/logging/src/main/java/java/util/logging/ErrorManager.java b/logging/src/main/java/java/util/logging/ErrorManager.java index 0b12df1..6f5084c 100644 --- a/logging/src/main/java/java/util/logging/ErrorManager.java +++ b/logging/src/main/java/java/util/logging/ErrorManager.java @@ -20,43 +20,55 @@ package java.util.logging; import org.apache.harmony.logging.internal.nls.Messages; /** - * <p> * An error reporting facility for {@link Handler} implementations to record any - * error that may happen during logging. <code>Handlers</code> should report - * errors to an <code>ErrorManager</code>, instead of throwing exceptions, - * which would interfere with the log issuer's execution. - * </p> + * error that may happen during logging. {@code Handlers} should report errors + * to an {@code ErrorManager}, instead of throwing exceptions, which would + * interfere with the log issuer's execution. + * + * @since Android 1.0 */ public class ErrorManager { /** * The error code indicating a failure that does not fit in any of the * specific types of failures that follow. + * + * @since Android 1.0 */ public static final int GENERIC_FAILURE = 0; /** * The error code indicating a failure when writing to an output stream. + * + * @since Android 1.0 */ public static final int WRITE_FAILURE = 1; /** * The error code indicating a failure when flushing an output stream. + * + * @since Android 1.0 */ public static final int FLUSH_FAILURE = 2; /** * The error code indicating a failure when closing an output stream. + * + * @since Android 1.0 */ public static final int CLOSE_FAILURE = 3; /** * The error code indicating a failure when opening an output stream. + * + * @since Android 1.0 */ public static final int OPEN_FAILURE = 4; /** * The error code indicating a failure when formatting the error messages. + * + * @since Android 1.0 */ public static final int FORMAT_FAILURE = 5; @@ -72,7 +84,9 @@ public class ErrorManager { private boolean called; /** - * Constructs an instance of <code>ErrorManager</code>. + * Constructs an instance of {@code ErrorManager}. + * + * @since Android 1.0 */ public ErrorManager() { super(); @@ -87,13 +101,15 @@ public class ErrorManager { * </p> * * @param message - * The error message, which may be <code>null</code>. + * the error message, which may be {@code null}. * @param exception - * The exception associated with the error, which may be - * <code>null</code>. + * the exception associated with the error, which may be + * {@code null}. * @param errorCode - * The error code that identifies the type of error; see the - * constant fields on this class. + * the error code that identifies the type of error; see the + * constant fields of this class for possible values. + * + * @since Android 1.0 */ public void error(String message, Exception exception, int errorCode) { synchronized (this) { diff --git a/logging/src/main/java/java/util/logging/FileHandler.java b/logging/src/main/java/java/util/logging/FileHandler.java index be21ebc..af71a6d 100644 --- a/logging/src/main/java/java/util/logging/FileHandler.java +++ b/logging/src/main/java/java/util/logging/FileHandler.java @@ -32,74 +32,74 @@ import java.util.Hashtable; import org.apache.harmony.logging.internal.nls.Messages; /** - * A <code>Handler</code> writes description of logging event into a specified - * file or a rotating set of files. + * A {@code FileHandler} writes logging records into a specified file or a + * rotating set of files. * <p> - * If a set of files are used, when a given amount of data has been written to - * one file, this file is closed, and another file is opened. The name of these - * files are generated by given name pattern, see below for details. + * When a set of files is used and a given amount of data has been written to + * one file, then this file is closed and another file is opened. The name of + * these files are generated by given name pattern, see below for details. * </p> * <p> - * By default the IO buffering mechanism is enabled, but when each log record is - * complete, it is flushed out. + * By default, the I/O buffering mechanism is enabled, but when each log record + * is complete, it is flushed out. * </p> * <p> - * <code>XMLFormatter</code> is default formatter for <code>FileHandler</code>. + * {@code XMLFormatter} is the default formatter for {@code FileHandler}. * </p> * <p> - * <code>MemoryHandler</code> will read following <code>LogManager</code> - * properties for initialization, if given properties are not defined or has - * invalid values, default value will be used. + * {@code FileHandler} reads the following {@code LogManager} properties for + * initialization; if a property is not defined or has an invalid value, a + * default value is used. * <ul> * <li>java.util.logging.FileHandler.level specifies the level for this - * <code>Handler</code>, defaults to <code>Level.ALL</code>.</li> - * <li>java.util.logging.FileHandler.filter specifies the <code>Filter</code> - * class name, defaults to no <code>Filter</code>.</li> - * <li>java.util.logging.FileHandler.formatter specifies the - * <code>Formatter</code> class, defaults to - * <code>java.util.logging.XMLFormatter</code>.</li> + * {@code Handler}, defaults to {@code Level.ALL}.</li> + * <li>java.util.logging.FileHandler.filter specifies the {@code Filter} class + * name, defaults to no {@code Filter}.</li> + * <li>java.util.logging.FileHandler.formatter specifies the {@code Formatter} + * class, defaults to {@code java.util.logging.XMLFormatter}.</li> * <li>java.util.logging.FileHandler.encoding specifies the character set * encoding name, defaults to the default platform encoding.</li> - * <li>java.util.logging.FileHandler.limit specifies an maximum bytes to write - * to any one file, defaults to zero, which means no limit.</li> + * <li>java.util.logging.FileHandler.limit specifies the maximum number of + * bytes to write to any one file, defaults to zero, which means no limit.</li> * <li>java.util.logging.FileHandler.count specifies how many output files to * rotate, defaults to 1.</li> * <li>java.util.logging.FileHandler.pattern specifies name pattern for the * output files. See below for details. Defaults to "%h/java%u.log".</li> * <li>java.util.logging.FileHandler.append specifies whether this - * <code>FileHandler</code> should append onto existing files, defaults to - * false.</li> + * {@code FileHandler} should append onto existing files, defaults to + * {@code false}.</li> * </ul> * </p> * <p> - * Name pattern is a string that may includes some special sub-strings, which - * will be replaced to generate output files: + * Name pattern is a string that may include some special substrings, which will + * be replaced to generate output files: + * </p> * <ul> * <li>"/" represents the local pathname separator</li> - * <li>"%t" represents the system temporary directory</li> - * <li>"%h" represents the home directory of current user, which is specified - * by "user.home" system property</li> + * <li>"%t" represents the system's temporary directory</li> + * <li>"%h" represents the home directory of the current user, which is + * specified by "user.home" system property</li> * <li>"%g" represents the generation number to distinguish rotated logs</li> * <li>"%u" represents a unique number to resolve conflicts</li> - * <li>"%%" represents percent sign character '%'</li> + * <li>"%%" represents the percent sign character '%'</li> * </ul> - * </p> - * Normally, the generation numbers are not larger than given file count and + * <p> + * Normally, the generation numbers are not larger than the given file count and * follow the sequence 0, 1, 2.... If the file count is larger than one, but the * generation field("%g") has not been specified in the pattern, then the - * generation number after a dot will be added to the end of the file name, + * generation number after a dot will be added to the end of the file name. * </p> * <p> - * The "%u" unique field is used to avoid conflicts and set to 0 at first. If - * one <code>FileHandler</code> tries to open the filename which is currently - * in use by another process, it will repeatedly increment the unique number - * field and try again. If the "%u" component has not been included in the file - * name pattern and some contention on a file does occur then a unique numerical + * The "%u" unique field is used to avoid conflicts and is set to 0 at first. If + * one {@code FileHandler} tries to open the filename which is currently in use + * by another process, it will repeatedly increment the unique number field and + * try again. If the "%u" component has not been included in the file name + * pattern and some contention on a file does occur, then a unique numerical * value will be added to the end of the filename in question immediately to the - * right of a dot. The unique IDs for avoiding conflicts is only guaranteed to - * work reliably when using a local disk file system. + * right of a dot. The generation of unique IDs for avoiding conflicts is only + * guaranteed to work reliably when using a local disk file system. * </p> - * + * @since Android 1.0 */ public class FileHandler extends StreamHandler { @@ -148,17 +148,18 @@ public class FileHandler extends StreamHandler { int uniqueID = -1; /** - * Construct a <code>FileHandler</code> using <code>LogManager</code> - * properties or their default value + * Construct a {@code FileHandler} using {@code LogManager} properties or + * their default value. * * @throws IOException - * if any IO exception happened + * if any I/O error occurs. * @throws SecurityException - * if security manager exists and it determines that caller does - * not have the required permissions to control this handler, - * required permissions include - * <code>LogPermission("control")</code> and other permission - * like <code>FilePermission("write")</code>, etc. + * if a security manager exists and it determines that the + * caller does not have the required permissions to control this + * handler; required permissions include + * {@code LogPermission("control")}, + * {@code FilePermission("write")} etc. + * @since Android 1.0 */ public FileHandler() throws IOException { init(null, null, null, null); @@ -277,11 +278,11 @@ public class FileHandler extends StreamHandler { /** * Transform the pattern to the valid file name, replacing any patterns, and - * applying generation and uniqueID if present + * applying generation and uniqueID if present. * * @param gen * generation of this file - * @return transformed filename ready for use + * @return transformed filename ready for use. */ private String parseFileName(int gen) { int cur = 0; @@ -392,27 +393,27 @@ public class FileHandler extends StreamHandler { } /** - * Construct a <code>FileHandler</code>, the given name pattern is used - * as output filename, the file limit is set to zero(no limit), and the file - * count is set to one, other configuration using <code>LogManager</code> - * properties or their default value - * - * This handler write to only one file and no amount limit. + * Constructs a new {@code FileHandler}. The given name pattern is used as + * output filename, the file limit is set to zero (no limit), the file count + * is set to one; the remaining configuration is done using + * {@code LogManager} properties or their default values. This handler write + * to only one file without size limit. * * @param pattern - * the name pattern of output file + * the name pattern for the output file. * @throws IOException - * if any IO exception happened + * if any I/O error occurs. * @throws SecurityException - * if security manager exists and it determines that caller does - * not have the required permissions to control this handler, - * required permissions include - * <code>LogPermission("control")</code> and other permission - * like <code>FilePermission("write")</code>, etc. - * @throws NullPointerException - * if the pattern is <code>null</code>. + * if a security manager exists and it determines that the + * caller does not have the required permissions to control this + * handler; required permissions include + * {@code LogPermission("control")}, + * {@code FilePermission("write")} etc. * @throws IllegalArgumentException * if the pattern is empty. + * @throws NullPointerException + * if the pattern is {@code null}. + * @since Android 1.0 */ public FileHandler(String pattern) throws IOException { if (pattern.equals("")) { //$NON-NLS-1$ @@ -424,30 +425,30 @@ public class FileHandler extends StreamHandler { } /** - * Construct a <code>FileHandler</code>, the given name pattern is used - * as output filename, the file limit is set to zero(i.e. no limit applies), - * the file count is initialized to one, and the value of - * <code>append</code> becomes the new instance's append mode. Other - * configuration is done using <code>LogManager</code> properties. - * - * This handler write to only one file and no amount limit. + * Construct a new {@code FileHandler}. The given name pattern is used as + * output filename, the file limit is set to zero (no limit), the file count + * is initialized to one and the value of {@code append} becomes the new + * instance's append mode. The remaining configuration is done using + * {@code LogManager} properties. This handler write to only one file + * without size limit. * * @param pattern - * the name pattern of output file + * the name pattern for the output file. * @param append - * the append mode + * the append mode. * @throws IOException - * if any IO exception happened + * if any I/O error occurs. * @throws SecurityException - * if security manager exists and it determines that caller does - * not have the required permissions to control this handler, - * required permissions include - * <code>LogPermission("control")</code> and other permission - * like <code>FilePermission("write")</code>, etc. - * @throws NullPointerException - * if the pattern is <code>null</code>. + * if a security manager exists and it determines that the + * caller does not have the required permissions to control this + * handler; required permissions include + * {@code LogPermission("control")}, + * {@code FilePermission("write")} etc. * @throws IllegalArgumentException - * if the pattern is empty. + * if {@code pattern} is empty. + * @throws NullPointerException + * if {@code pattern} is {@code null}. + * @since Android 1.0 */ public FileHandler(String pattern, boolean append) throws IOException { if (pattern.equals("")) { //$NON-NLS-1$ @@ -459,34 +460,34 @@ public class FileHandler extends StreamHandler { } /** - * Construct a <code>FileHandler</code>, the given name pattern is used - * as output filename, the file limit is set to given limit argument, and - * the file count is set to given count argument, other configuration using - * <code>LogManager</code> properties or their default value - * - * This handler is configured to write to a rotating set of count files, - * when the limit of bytes has been written to one output file, another file - * will be opened instead. + * Construct a new {@code FileHandler}. The given name pattern is used as + * output filename, the maximum file size is set to {@code limit} and the + * file count is initialized to {@code count}. The remaining configuration + * is done using {@code LogManager} properties. This handler is configured + * to write to a rotating set of count files, when the limit of bytes has + * been written to one output file, another file will be opened instead. * * @param pattern - * the name pattern of output file + * the name pattern for the output file. * @param limit - * the data amount limit in bytes of one output file, cannot less - * than one + * the data amount limit in bytes of one output file, can not be + * negative. * @param count - * the maximum number of files can be used, cannot less than one + * the maximum number of files to use, can not be less than one. * @throws IOException - * if any IO exception happened + * if any I/O error occurs. * @throws SecurityException - * if security manager exists and it determines that caller does - * not have the required permissions to control this handler, - * required permissions include - * <code>LogPermission("control")</code> and other permission - * like <code>FilePermission("write")</code>, etc. - * @throws NullPointerException - * if pattern is <code>null</code>. + * if a security manager exists and it determines that the + * caller does not have the required permissions to control this + * handler; required permissions include + * {@code LogPermission("control")}, + * {@code FilePermission("write")} etc. * @throws IllegalArgumentException - * if count<1, or limit<0 + * if {@code pattern} is empty, {@code limit < 0} or + * {@code count < 1}. + * @throws NullPointerException + * if {@code pattern} is {@code null}. + * @since Android 1.0 */ public FileHandler(String pattern, int limit, int count) throws IOException { if (pattern.equals("")) { //$NON-NLS-1$ @@ -501,37 +502,37 @@ public class FileHandler extends StreamHandler { } /** - * Construct a <code>FileHandler</code>, the given name pattern is used - * as output filename, the file limit is set to given limit argument, the - * file count is set to given count argument, and the append mode is set to - * given append argument, other configuration using <code>LogManager</code> - * properties or their default value - * - * This handler is configured to write to a rotating set of count files, - * when the limit of bytes has been written to one output file, another file - * will be opened instead. + * Construct a new {@code FileHandler}. The given name pattern is used as + * output filename, the maximum file size is set to {@code limit}, the file + * count is initialized to {@code count} and the append mode is set to + * {@code append}. The remaining configuration is done using + * {@code LogManager} properties. This handler is configured to write to a + * rotating set of count files, when the limit of bytes has been written to + * one output file, another file will be opened instead. * * @param pattern - * the name pattern of output file + * the name pattern for the output file. * @param limit - * the data amount limit in bytes of one output file, cannot less - * than one + * the data amount limit in bytes of one output file, can not be + * negative. * @param count - * the maximum number of files can be used, cannot less than one + * the maximum number of files to use, can not be less than one. * @param append - * the append mode + * the append mode. * @throws IOException - * if any IO exception happened + * if any I/O error occurs. * @throws SecurityException - * if security manager exists and it determines that caller does - * not have the required permissions to control this handler, - * required permissions include - * <code>LogPermission("control")</code> and other permission - * like <code>FilePermission("write")</code>, etc. - * @throws NullPointerException - * if pattern is <code>null</code>. + * if a security manager exists and it determines that the + * caller does not have the required permissions to control this + * handler; required permissions include + * {@code LogPermission("control")}, + * {@code FilePermission("write")} etc. * @throws IllegalArgumentException - * if count<1, or limit<0 + * if {@code pattern} is empty, {@code limit < 0} or + * {@code count < 1}. + * @throws NullPointerException + * if {@code pattern} is {@code null}. + * @since Android 1.0 */ public FileHandler(String pattern, int limit, int count, boolean append) throws IOException { @@ -548,14 +549,15 @@ public class FileHandler extends StreamHandler { } /** - * Flush and close all opened files. + * Flushes and closes all opened files. * * @throws SecurityException - * if security manager exists and it determines that caller does - * not have the required permissions to control this handler, - * required permissions include - * <code>LogPermission("control")</code> and other permission - * like <code>FilePermission("write")</code>, etc. + * if a security manager exists and it determines that the + * caller does not have the required permissions to control this + * handler; required permissions include + * {@code LogPermission("control")}, + * {@code FilePermission("write")} etc. + * @since Android 1.0 */ @Override public void close() { @@ -574,10 +576,11 @@ public class FileHandler extends StreamHandler { } /** - * Publish a <code>LogRecord</code> + * Publish a {@code LogRecord}. * * @param record - * the log record to be published + * the log record to publish. + * @since Android 1.0 */ @Override public void publish(LogRecord record) { @@ -594,9 +597,9 @@ public class FileHandler extends StreamHandler { } /** - * This output stream use decorator pattern to add measure feature to - * OutputStream which can detect the total size(in bytes) of output, the - * initial size can be set + * This output stream uses the decorator pattern to add measurement features + * to OutputStream which can detect the total size(in bytes) of output, the + * initial size can be set. */ static class MeasureOutputStream extends OutputStream { diff --git a/logging/src/main/java/java/util/logging/Filter.java b/logging/src/main/java/java/util/logging/Filter.java index d96f3ce..e81f216 100644 --- a/logging/src/main/java/java/util/logging/Filter.java +++ b/logging/src/main/java/java/util/logging/Filter.java @@ -18,17 +18,21 @@ package java.util.logging; /** - * <p>A Filter provides a mechanism for exercising fine-grained control over - * what records get logged.</p> + * A {@code Filter} provides a mechanism for exercising fine-grained control + * over which records get logged. + * + * @since Android 1.0 */ public interface Filter { /** - * <p>Checks the {@link LogRecord} to determine if it should be logged.</p> + * Checks {@code record} to determine if it should be logged. * - * @param record The {@link LogRecord} to be checked. - * @return <code>true</code> if the supplied log record needs to be - * logged, otherwise <code>false</code> + * @param record + * the {@link LogRecord} to be checked. + * @return {@code true} if the supplied log record needs to be logged, + * {@code false} otherwise. + * @since Android 1.0 */ boolean isLoggable(LogRecord record); } diff --git a/logging/src/main/java/java/util/logging/Formatter.java b/logging/src/main/java/java/util/logging/Formatter.java index 7321aa2..2941c24 100644 --- a/logging/src/main/java/java/util/logging/Formatter.java +++ b/logging/src/main/java/java/util/logging/Formatter.java @@ -22,11 +22,12 @@ import java.text.MessageFormat; import java.util.ResourceBundle; /** - * <code>Formatter</code> objects are used to format <code>LogRecord</code> - * objects into a string representation. Head and tail strings are sometime used - * to wrap a set of records. The <code>getHead</code> and <code>getTail</code> - * methods are presented for this purpose. + * {@code Formatter} objects are used to format {@link LogRecord} objects into a + * string representation. Head and tail strings are sometimes used to wrap a set + * of records. The {@code getHead} and {@code getTail} methods are used for this + * purpose. * + * @since Android 1.0 */ public abstract class Formatter { @@ -37,7 +38,9 @@ public abstract class Formatter { */ /** - * Constructs a <code>Formatter</code> object. + * Constructs a {@code Formatter} object. + * + * @since Android 1.0 */ protected Formatter() { super(); @@ -50,29 +53,34 @@ public abstract class Formatter { */ /** - * Formats a <code>LogRecord</code> object into a string representation. - * The resulted string is usually localized and includes the message field - * of the supplied <code>LogRecord</code> object. + * Converts a {@link LogRecord} object into a string representation. The + * resulted string is usually localized and includes the message field of + * the record. * * @param r - * the log record to be formatted into a string - * @return the string resulted from the formatting + * the log record to be formatted into a string. + * @return the formatted string. + * @since Android 1.0 */ public abstract String format(LogRecord r); /** - * Formats a <code>LogRecord</code> object into a localized string - * representation. This method can be regarded as a convenience for - * subclasses of <code>Formatter</code> to use. + * Formats a {@code LogRecord} object into a localized string + * representation. This is a convenience method for subclasses of {@code + * Formatter}. + * <p> + * The message string is firstly localized using the {@code ResourceBundle} + * object associated with the supplied {@code LogRecord}. + * </p> * <p> - * The message string is firstly localized using the - * <code>ResourceBundle</code> object associated with the supplied - * <code>LogRecord</code>. + * Notice : if message contains "{0", then java.text.MessageFormat is used. + * Otherwise no formatting is performed. * </p> * * @param r - * the log record to be formatted - * @return the string resulted from the formatting + * the log record to be formatted. + * @return the string resulted from the formatting. + * @since Android 1.0 */ public String formatMessage(LogRecord r) { String pattern = r.getMessage(); @@ -105,11 +113,13 @@ public abstract class Formatter { /** * Gets the head string used to wrap a set of log records. This base class - * always returns the empty string. + * always returns an empty string. * * @param h - * the target handler - * @return the head string used to wrap a set of log records + * the target handler. + * @return the head string used to wrap a set of log records, empty in this + * implementation. + * @since Android 1.0 */ @SuppressWarnings("unused") public String getHead(Handler h) { @@ -121,8 +131,10 @@ public abstract class Formatter { * always returns the empty string. * * @param h - * the target handler - * @return the tail string used to wrap a set of log records + * the target handler. + * @return the tail string used to wrap a set of log records, empty in this + * implementation. + * @since Android 1.0 */ @SuppressWarnings("unused") public String getTail(Handler h) { diff --git a/logging/src/main/java/java/util/logging/Handler.java b/logging/src/main/java/java/util/logging/Handler.java index 9bad459..d28bce0 100644 --- a/logging/src/main/java/java/util/logging/Handler.java +++ b/logging/src/main/java/java/util/logging/Handler.java @@ -26,10 +26,11 @@ import java.io.UnsupportedEncodingException; import org.apache.harmony.logging.internal.nls.Messages; /** - * A <code>Handler</code> object accepts a logging request and exports the - * desired messages to a target, for example, a file, the console, etc. It can - * be disabled by setting its logging level to <code>Level.OFF</code>. + * A {@code Handler} object accepts a logging request and exports the desired + * messages to a target, for example, a file, the console, etc. It can be + * disabled by setting its logging level to {@code Level.OFF}. * + * @since Android 1.0 */ public abstract class Handler { @@ -71,9 +72,11 @@ public abstract class Handler { */ /** - * Constructs a <code>Handler</code> object with a default error manager, - * the default encoding, and the default logging level - * <code>Level.ALL</code>. It has no filter and no formatter. + * Constructs a {@code Handler} object with a default error manager instance + * {@code ErrorManager}, the default encoding, and the default logging + * level {@code Level.ALL}. It has no filter and no formatter. + * + * @since Android 1.0 */ protected Handler() { this.errorMan = new ErrorManager(); @@ -187,33 +190,40 @@ public abstract class Handler { } /** - * Closes this handler. A flush operation will usually be performed and all - * the associated resources will be freed. Client applications should not - * use a handler after closing it. + * Closes this handler. A flush operation will be performed and all the + * associated resources will be freed. Client applications should not use + * this handler after closing it. * * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * + * @since Android 1.0 */ public abstract void close(); /** * Flushes any buffered output. + * + * @since Android 1.0 */ public abstract void flush(); /** - * Accepts an actual logging request. + * Accepts a logging request and sends it to the the target. * * @param record - * the log record to be logged + * the log record to be logged; {@code null} records are ignored. + * @since Android 1.0 */ public abstract void publish(LogRecord record); /** - * Gets the character encoding used by this handler. + * Gets the character encoding used by this handler, {@code null} for + * default encoding. * - * @return the character encoding used by this handler + * @return the character encoding used by this handler. + * @since Android 1.0 */ public String getEncoding() { return this.encoding; @@ -223,10 +233,11 @@ public abstract class Handler { * Gets the error manager used by this handler to report errors during * logging. * - * @return the error manager used by this handler + * @return the error manager used by this handler. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public ErrorManager getErrorManager() { LogManager.getLogManager().checkAccess(); @@ -236,7 +247,8 @@ public abstract class Handler { /** * Gets the filter used by this handler. * - * @return the filter used by this handler + * @return the filter used by this handler (possibly {@code null}). + * @since Android 1.0 */ public Filter getFilter() { return this.filter; @@ -245,29 +257,33 @@ public abstract class Handler { /** * Gets the formatter used by this handler to format the logging messages. * - * @return the formatter used by this handler + * @return the formatter used by this handler (possibly {@code null}). + * @since Android 1.0 */ public Formatter getFormatter() { return this.formatter; } /** - * Gets the logging level of this handler. + * Gets the logging level of this handler, records with levels lower than + * this value will be dropped. * - * @return the logging level of this handler + * @return the logging level of this handler. + * @since Android 1.0 */ public Level getLevel() { return this.level; } /** - * Determines whether the supplied log record need to be logged. The logging - * levels will be checked as well as the filter. + * Determines whether the supplied log record needs to be logged. The + * logging levels will be checked as well as the filter. * * @param record - * the log record to be checked - * @return <code>true</code> if the supplied log record need to be logged, - * otherwise <code>false</code> + * the log record to be checked. + * @return {@code true} if the supplied log record needs to be logged, + * otherwise {@code false}. + * @since Android 1.0 */ public boolean isLoggable(LogRecord record) { if (null == record) { @@ -282,28 +298,33 @@ public abstract class Handler { } /** - * Report an error to the error manager associated with this handler. + * Reports an error to the error manager associated with this handler, + * {@code ErrorManager} is used for that purpose. No security checks are + * done, therefore this is compatible with environments where the caller + * is non-privileged. * * @param msg - * the error message + * the error message, may be {@code null}. * @param ex - * the associated exception + * the associated exception, may be {@code null}. * @param code - * the error code + * an {@code ErrorManager} error code. + * @since Android 1.0 */ protected void reportError(String msg, Exception ex, int code) { this.errorMan.error(msg, ex, code); } /** - * Sets the character encoding used by this handler. A <code>null</code> - * value indicates the using of the default encoding. This internal method - * does not check security. + * Sets the character encoding used by this handler. A {@code null} value + * indicates the use of the default encoding. This internal method does + * not check security. * * @param newEncoding - * the character encoding to set + * the character encoding to set. * @throws UnsupportedEncodingException - * If the specified encoding is not supported by the runtime. + * if the specified encoding is not supported by the runtime. + * @since Android 1.0 */ void internalSetEncoding(String newEncoding) throws UnsupportedEncodingException { @@ -324,16 +345,17 @@ public abstract class Handler { } /** - * Sets the character encoding used by this handler. A <code>null</code> - * value indicates the using of the default encoding. + * Sets the character encoding used by this handler, {@code null} indicates + * a default encoding. * * @param encoding - * the character encoding to set + * the character encoding to set. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. * @throws UnsupportedEncodingException - * If the specified encoding is not supported by the runtime. + * if the specified encoding is not supported by the runtime. + * @since Android 1.0 */ public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException { @@ -345,10 +367,13 @@ public abstract class Handler { * Sets the error manager for this handler. * * @param em - * the error manager to set + * the error manager to set. + * @throws NullPointerException + * if {@code em} is {@code null}. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public void setErrorManager(ErrorManager em) { LogManager.getLogManager().checkAccess(); @@ -362,10 +387,11 @@ public abstract class Handler { * Sets the filter to be used by this handler. * * @param newFilter - * the filter to set + * the filter to set, may be {@code null}. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public void setFilter(Filter newFilter) { LogManager.getLogManager().checkAccess(); @@ -377,7 +403,7 @@ public abstract class Handler { * not check security. * * @param newFormatter - * the formatter to set + * the formatter to set. */ void internalSetFormatter(Formatter newFormatter) { if (null == newFormatter) { @@ -390,10 +416,13 @@ public abstract class Handler { * Sets the formatter to be used by this handler. * * @param newFormatter - * the formatter to set + * the formatter to set. + * @throws NullPointerException + * if {@code newFormatter} is {@code null}. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public void setFormatter(Formatter newFormatter) { LogManager.getLogManager().checkAccess(); @@ -401,13 +430,17 @@ public abstract class Handler { } /** - * Sets the logging level of this handler. + * Sets the logging level of the messages logged by this handler, levels + * lower than this value will be dropped. * * @param newLevel - * the logging level to set + * the logging level to set. + * @throws NullPointerException + * if {@code newLevel} is {@code null}. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public void setLevel(Level newLevel) { if (null == newLevel) { diff --git a/logging/src/main/java/java/util/logging/Level.java b/logging/src/main/java/java/util/logging/Level.java index bb39d51..32ba017 100644 --- a/logging/src/main/java/java/util/logging/Level.java +++ b/logging/src/main/java/java/util/logging/Level.java @@ -27,20 +27,22 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import org.apache.harmony.logging.internal.nls.Messages; -import org.apache.harmony.kernel.vm.VM; +// BEGIN android-changed +import dalvik.system.VMStack; +// END android-changed /** - * <code>Level</code> objects are used to indicate the level of logging. There - * are a set of predefined logging levels, each associated with an integer - * value. Enabling a certain logging level also enables all logging levels with - * larger values. + * {@code Level} objects are used to indicate the level of logging. There are a + * set of predefined logging levels, each associated with an integer value. + * Enabling a certain logging level also enables all logging levels with larger + * values. * <p> * The predefined levels in ascending order are FINEST, FINER, FINE, CONFIG, * INFO, WARNING, SEVERE. There are two additional predefined levels, which are * ALL and OFF. ALL indicates logging all messages, and OFF indicates logging no * messages. * </p> - * + * @since Android 1.0 */ public class Level implements Serializable { @@ -50,61 +52,85 @@ public class Level implements Serializable { /** * The OFF level provides no logging messages. + * + * @since Android 1.0 */ public static final Level OFF = new Level("OFF", Integer.MAX_VALUE); //$NON-NLS-1$ /** - * The SEVERE level indicates a severe failure. + * The SEVERE level provides severe failure messages. + * + * @since Android 1.0 */ public static final Level SEVERE = new Level("SEVERE", 1000); //$NON-NLS-1$ /** - * The WARNING level indicates a warning. + * The WARNING level provides warnings. + * + * @since Android 1.0 */ public static final Level WARNING = new Level("WARNING", 900); //$NON-NLS-1$ /** - * The INFO level indicates an informative message. + * The INFO level provides informative messages. + * + * @since Android 1.0 */ public static final Level INFO = new Level("INFO", 800); //$NON-NLS-1$ /** - * The CONFIG level indicates a static configuration message. + * The CONFIG level provides static configuration messages. + * + * @since Android 1.0 */ public static final Level CONFIG = new Level("CONFIG", 700); //$NON-NLS-1$ /** * The FINE level provides tracing messages. + * + * @since Android 1.0 */ public static final Level FINE = new Level("FINE", 500); //$NON-NLS-1$ /** * The FINER level provides more detailed tracing messages. + * + * @since Android 1.0 */ public static final Level FINER = new Level("FINER", 400); //$NON-NLS-1$ /** * The FINEST level provides highly detailed tracing messages. + * + * @since Android 1.0 */ public static final Level FINEST = new Level("FINEST", 300); //$NON-NLS-1$ /** * The ALL level provides all logging messages. + * + * @since Android 1.0 */ public static final Level ALL = new Level("ALL", Integer.MIN_VALUE); //$NON-NLS-1$ /** - * Parses a level name into a <code>Level</code> object. + * Parses a level name into a {@code Level} object. * * @param name - * the name of the desired level, which cannot be null - * @return a <code>Level</code> object with the specified name + * the name of the desired {@code level}, which cannot be + * {@code null}. + * @return the level with the specified name. * @throws NullPointerException - * if <code>name</code> is <code>null</code>. + * if {@code name} is {@code null}. * @throws IllegalArgumentException - * if <code>name</code> is not valid. + * if {@code name} is not valid. + * @since Android 1.0 */ - public static final Level parse(String name) { + public static Level parse(String name) throws IllegalArgumentException { + // BEGIN android-note + // final modifier removed and IAE added to get closer to the RI + // copied from newer version of harmony + // END android-note if (name == null) { // logging.1C=The 'name' parameter is null. throw new NullPointerException(Messages.getString("logging.1C")); //$NON-NLS-1$ @@ -176,25 +202,34 @@ public class Level implements Serializable { private transient ResourceBundle rb; /** - * Constructs an instance of <code>Level</code> taking the supplied name - * and level value. + * Constructs an instance of {@code Level} taking the supplied name and + * level value. * - * @param name name of the level - * @param level an integer value indicating the level - * @throws NullPointerException if <code>name</code> is <code>null</code>. + * @param name + * the name of the level. + * @param level + * an integer value indicating the level. + * @throws NullPointerException + * if {@code name} is {@code null}. + * @since Android 1.0 */ protected Level(String name, int level) { this(name, level, null); } /** - * Constructs an instance of <code>Level</code> taking the supplied name - * and level value. + * Constructs an instance of {@code Level} taking the supplied name, level + * value and resource bundle name. * - * @param name name of the level - * @param level an integer value indicating the level - * @param resourceBundleName the name of the resource bundle to use - * @throws NullPointerException if <code>name</code> is <code>null</code>. + * @param name + * the name of the level. + * @param level + * an integer value indicating the level. + * @param resourceBundleName + * the name of the resource bundle to use. + * @throws NullPointerException + * if {@code name} is {@code null}. + * @since Android 1.0 */ protected Level(String name, int level, String resourceBundleName) { if (name == null) { @@ -206,11 +241,10 @@ public class Level implements Serializable { this.resourceBundleName = resourceBundleName; if (resourceBundleName != null) { try { - rb = ResourceBundle.getBundle(resourceBundleName, - // TODO Implement kernel.vm.VM.callerClassLoader, or find - // another way to get the caller class loader - // Locale.getDefault(), VM.callerClassLoader()); - Locale.getDefault(), ClassLoader.getSystemClassLoader()); + rb = ResourceBundle.getBundle(resourceBundleName, + // BEGIN android-changed + Locale.getDefault(), VMStack.getCallingClassLoader()); + // BEGIN android-changed } catch (MissingResourceException e) { rb = null; } @@ -221,29 +255,30 @@ public class Level implements Serializable { } /** - * Gets the name of this <code>Level</code>. + * Gets the name of this level. * - * @return the name of this <code>Level</code> + * @return this level's name. + * @since Android 1.0 */ public String getName() { return this.name; } /** - * Gets the name of the resource bundle associated with this - * <code>Level</code>. + * Gets the name of the resource bundle associated with this level. * - * @return the name of the resource bundle associated with this - * <code>Level</code> + * @return the name of this level's resource bundle. + * @since Android 1.0 */ public String getResourceBundleName() { return this.resourceBundleName; } /** - * Gets the integer value indicating this <code>Level</code>. + * Gets the integer value indicating this level. * - * @return the integer value indicating this <code>Level</code> + * @return this level's integer value. + * @since Android 1.0 */ public final int intValue() { return this.value; @@ -255,7 +290,7 @@ public class Level implements Serializable { * levels. * </p> * - * @return The resolved instance. + * @return the resolved instance. */ private Object readResolve() { synchronized (levels) { @@ -280,10 +315,14 @@ public class Level implements Serializable { } /** - * <p>Serialization helper to setup transient resource bundle instance.</p> - * @param in The input stream to read the instance data from. - * @throws IOException if an IO error occurs. - * @throws ClassNotFoundException if a class is not found. + * Serialization helper to setup transient resource bundle instance. + * + * @param in + * the input stream to read the instance data from. + * @throws IOException + * if an IO error occurs. + * @throws ClassNotFoundException + * if a class is not found. */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); @@ -298,10 +337,11 @@ public class Level implements Serializable { /** * Gets the localized name of this level. The default locale is used. If no - * resource bundle is associated with this <code>Level</code>, the - * original level name is returned. + * resource bundle is associated with this level then the original level + * name is returned. * - * @return the localized name of this level + * @return the localized name of this level. + * @since Android 1.0 */ public String getLocalizedName() { if (rb == null) { @@ -316,12 +356,14 @@ public class Level implements Serializable { } /** - * Compares two <code>Level</code> objects for equality. They are - * considered to be equal if they have the same value. + * Compares two {@code Level} objects for equality. They are considered to + * be equal if they have the same level value. * - * @param o the other object to be compared with - * @return <code>true</code> if this object equals to the supplied object, - * otherwise <code>false</code> + * @param o + * the other object to compare this level to. + * @return {@code true} if this object equals to the supplied object, + * {@code false} otherwise. + * @since Android 1.0 */ @Override public boolean equals(Object o) { @@ -337,9 +379,10 @@ public class Level implements Serializable { } /** - * Returns the hash code of this <code>Level</code> object. + * Returns the hash code of this {@code Level} object. * - * @return the hash code of this <code>Level</code> object + * @return this level's hash code. + * @since Android 1.0 */ @Override public int hashCode() { @@ -347,14 +390,14 @@ public class Level implements Serializable { } /** - * Returns the string representation of this <code>Level</code> object. - * Usually this will include its name. + * Returns the string representation of this {@code Level} object. In + * this case, it is the level's name. * - * @return the string representation of this <code>Level</code> object + * @return the string representation of this level. + * @since Android 1.0 */ @Override public final String toString() { return this.name; } - } diff --git a/logging/src/main/java/java/util/logging/LogManager.java b/logging/src/main/java/java/util/logging/LogManager.java index 462b658..8409b81 100644 --- a/logging/src/main/java/java/util/logging/LogManager.java +++ b/logging/src/main/java/java/util/logging/LogManager.java @@ -17,10 +17,8 @@ package java.util.logging; -// BEGIN android-removed -// import java.beans.PropertyChangeListener; -// import java.beans.PropertyChangeSupport; -// END android-removed +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; @@ -47,29 +45,30 @@ import java.util.StringTokenizer; import org.apache.harmony.logging.internal.nls.Messages; /** - * <code>LogManager</code> is used to maintain configuration properties of the + * {@code LogManager} is used to maintain configuration properties of the * logging framework, and to manage a hierarchical namespace of all named - * <code>Logger</code> objects. + * {@code Logger} objects. * <p> - * There is only one global <code>LogManager</code> instance in the + * + * There is only one global {@code LogManager} instance in the * application, which can be get by calling static method - * <code>LogManager.getLogManager()</code>. This instance is created and + * {@link #getLogManager()}. This instance is created and * initialized during class initialization and cannot be changed. * </p> * <p> - * The <code>LogManager</code> class can be specified by + * The {@code LogManager} class can be specified by * java.util.logging.manager system property, if the property is unavailable or - * invalid, the default class <code>java.util.logging.LogManager</code> will + * invalid, the default class {@link java.util.logging.LogManager} will * be used. * </p> * <p> - * When initialization, <code>LogManager</code> read its configuration from a + * When initialization, {@code LogManager} read its configuration from a * properties file, which by default is the "lib/logging.properties" in the JRE * directory. * </p> * <p> * However, two optional system properties can be used to customize the initial - * configuration process of <code>LogManager</code>. + * configuration process of {@code LogManager}. * <ul> * <li>"java.util.logging.config.class"</li> * <li>"java.util.logging.config.file"</li> @@ -83,20 +82,20 @@ import org.apache.harmony.logging.internal.nls.Messages; * <p> * The "java.util.logging.config.class" should specifies a class name. If it is * set, this given class will be loaded and instantiated during - * <code>LogManager</code> initialization, so that this object's default + * {@code LogManager} initialization, so that this object's default * constructor can read the initial configuration and define properties for - * <code>LogManager</code>. + * {@code LogManager}. * </p> * <p> * If "java.util.logging.config.class" property is not set, or it is invalid, or * some exception is thrown during the instantiation, then the * "java.util.logging.config.file" system property can be used to specify a - * properties file. The <code>LogManager</code> will read initial + * properties file. The {@code LogManager} will read initial * configuration from this file. * </p> * <p> * If neither of these properties is defined, or some exception is thrown - * during these two properties using, the <code>LogManager</code> will read + * during these two properties using, the {@code LogManager} will read * its initial configuration from default properties file, as described above. * </p> * <p> @@ -104,21 +103,21 @@ import org.apache.harmony.logging.internal.nls.Messages; * <ul> * <li>"handlers". This property's values should be a list of class names for * handler classes separated by whitespace, these classes must be subclasses of - * <code>Handler</code> and each must have a default constructor, these + * {@code Handler} and each must have a default constructor, these * classes will be loaded, instantiated and registered as handlers on the root - * <code>Logger</code> (the <code>Logger</code> named ""). These - * <code>Handler</code>s maybe initialized lazily.</li> + * {@code Logger} (the {@code Logger} named ""). These + * {@code Handler}s maybe initialized lazily.</li> * <li>"config". The property defines a list of class names separated by * whitespace. Each class must have a default constructor, in which it can * update the logging configuration, such as levels, handlers, or filters for * some logger, etc. These classes will be loaded and instantiated during - * <code>LogManager</code> configuration</li> + * {@code LogManager} configuration</li> * </ul> * </p> * <p> * This class, together with any handler and configuration classes associated * with it, <b>must</b> be loaded from the system classpath when - * <code>LogManager</code> configuration occurs. + * {@code LogManager} configuration occurs. * </p> * <p> * Besides global properties, the properties for loggers and Handlers can be @@ -126,12 +125,12 @@ import org.apache.harmony.logging.internal.nls.Messages; * with the complete dot separated names for the handlers or loggers. * </p> * <p> - * In the <code>LogManager</code>'s hierarchical namespace, - * <code>Loggers</code> are organized based on their dot separated names. For + * In the {@code LogManager}'s hierarchical namespace, + * {@code Loggers} are organized based on their dot separated names. For * example, "x.y.z" is child of "x.y". * </p> * <p> - * Levels for <code>Loggers</code> can be defined by properties whose name end + * Levels for {@code Loggers} can be defined by properties whose name end * with ".level". Thus "alogger.level" defines a level for the logger named as * "alogger" and for all its children in the naming hierarchy. Log levels * properties are read and applied in the same order as they are specified in @@ -163,48 +162,54 @@ public class LogManager { static LogManager manager; /** - * <p>The String value of the {@link LoggingMXBean}'s ObjectName.</p> + * The {@code String} value of the {@link LoggingMXBean}'s ObjectName. + * + * @since Android 1.0 */ public static final String LOGGING_MXBEAN_NAME = "java.util.logging:type=Logging"; //$NON-NLS-1$ -// BENGIN android-removed -// /** -// * Get the <code>LoggingMXBean</code> instance -// * -// * @return the <code>LoggingMXBean</code> instance -// */ -// public static LoggingMXBean getLoggingMXBean() { -// try { -// ObjectName loggingMXBeanName = new ObjectName(LOGGING_MXBEAN_NAME); -// MBeanServer platformBeanServer = -// ManagementFactory.getPlatformMBeanServer(); -// Set loggingMXBeanSet = platformBeanServer.queryMBeans( -// loggingMXBeanName, null); -// -// if (loggingMXBeanSet.size() != 1) { -// // logging.21=There Can Be Only One logging MX bean. -// throw new AssertionError(Messages.getString("logging.21")); -// } -// -// Iterator i = loggingMXBeanSet.iterator(); -// ObjectInstance loggingMXBeanOI = (ObjectInstance) i.next(); -// String lmxbcn = loggingMXBeanOI.getClassName(); -// Class lmxbc = Class.forName(lmxbcn); -// Method giMethod = lmxbc.getDeclaredMethod("getInstance"); -// giMethod.setAccessible(true); -// LoggingMXBean lmxb = (LoggingMXBean) -// giMethod.invoke(null, new Object[] {}); -// -// return lmxb; -// } catch (Exception e) { -// //TODO -// //e.printStackTrace(); -// } -// // logging.22=Exception occurred while getting the logging MX bean. -// throw new AssertionError(Messages.getString("logging.22")); //$NON-NLS-1$ -// } -// END android-removed + /** + * Get the {@code LoggingMXBean} instance. this implementation always throws + * an UnsupportedOperationException. + * + * @return the {@code LoggingMXBean} instance + */ + public static LoggingMXBean getLoggingMXBean() { + // BEGIN android-added + throw new UnsupportedOperationException(); + // END android-added + // BEGIN android-removed + // try { + // ObjectName loggingMXBeanName = new ObjectName(LOGGING_MXBEAN_NAME); + // MBeanServer platformBeanServer = + // ManagementFactory.getPlatformMBeanServer(); + // Set loggingMXBeanSet = platformBeanServer.queryMBeans( + // loggingMXBeanName, null); + // + // if (loggingMXBeanSet.size() != 1) { + // // logging.21=There Can Be Only One logging MX bean. + // throw new AssertionError(Messages.getString("logging.21")); + // } + // + // Iterator i = loggingMXBeanSet.iterator(); + // ObjectInstance loggingMXBeanOI = (ObjectInstance) i.next(); + // String lmxbcn = loggingMXBeanOI.getClassName(); + // Class lmxbc = Class.forName(lmxbcn); + // Method giMethod = lmxbc.getDeclaredMethod("getInstance"); + // giMethod.setAccessible(true); + // LoggingMXBean lmxb = (LoggingMXBean) + // giMethod.invoke(null, new Object[] {}); + // + // return lmxb; + // } catch (Exception e) { + // //TODO + // //e.printStackTrace(); + // } + // // logging.22=Exception occurred while getting the logging MX bean. + // throw new AssertionError(Messages.getString("logging.22")); //$NON-NLS-1$ + // END android-removed + } /* * ------------------------------------------------------------------- @@ -218,9 +223,7 @@ public class LogManager { private Properties props; // the property change listener -// BEGIN android-removed -// private PropertyChangeSupport listeners; -// END android-removed + private PropertyChangeSupport listeners; /* * ------------------------------------------------------------------- @@ -263,16 +266,14 @@ public class LogManager { /** * Default constructor. This is not public because there should be only one - * <code>LogManager</code> instance, which can be get by - * <code>LogManager.getLogManager(</code>. This is protected so that + * {@code LogManager} instance, which can be get by + * {@code LogManager.getLogManager(}. This is protected so that * application can subclass the object. */ protected LogManager() { loggers = new Hashtable<String, Logger>(); props = new Properties(); -// BEGIN android-removed -// listeners = new PropertyChangeSupport(this); -// END android-removed + listeners = new PropertyChangeSupport(this); // add shutdown hook to ensure that the associated resource will be // freed when JVM exits AccessController.doPrivileged(new PrivilegedAction<Void>() { @@ -302,15 +303,15 @@ public class LogManager { } /** - * Check that the caller has <code>LoggingPermission("control")</code> so + * Check that the caller has {@code LoggingPermission("control")} so * that it is trusted to modify the configuration for logging framework. If - * the check passes, just return, otherwise <code>SecurityException</code> + * the check passes, just return, otherwise {@code SecurityException} * will be thrown. * * @throws SecurityException * if there is a security manager in operation and the invoker * of this method does not have the required security permission - * <code>LoggingPermission("control")</code> + * {@code LoggingPermission("control")} */ public void checkAccess() { if (null != System.getSecurityManager()) { @@ -320,21 +321,20 @@ public class LogManager { /** * Add a given logger into the hierarchical namespace. The - * <code>Logger.addLogger()</code> factory methods call this method to add - * newly created Logger. This returns false if a logger with the given name - * has existed in the namespace + * {@code Logger.addLogger()} factory methods call this method to add newly + * created Logger. This returns false if a logger with the given name has + * existed in the namespace * <p> - * Note that the <code>LogManager</code> may only retain weak references - * to registered loggers. In order to prevent <code>Logger</code> objects - * from being unexpectedly garbage collected it is necessary for - * <i>applications</i> to maintain references to them. + * Note that the {@code LogManager} may only retain weak references to + * registered loggers. In order to prevent {@code Logger} objects from being + * unexpectedly garbage collected it is necessary for <i>applications</i> + * to maintain references to them. * </p> * * @param logger - * the logger to be added + * the logger to be added. * @return true if the given logger is added into the namespace - * successfully, false if the logger of given name has existed in - * the namespace + * successfully, false if the given logger exists in the namespace. */ public synchronized boolean addLogger(Logger logger) { String name = logger.getName(); @@ -388,18 +388,18 @@ public class LogManager { } /** - * Get the logger with the given name + * Get the logger with the given name. * * @param name * name of logger - * @return logger with given name, or null if nothing is found + * @return logger with given name, or {@code null} if nothing is found. */ public synchronized Logger getLogger(String name) { return loggers.get(name); } /** - * Get a <code>Enumeration</code> of all registered logger names + * Get a {@code Enumeration} of all registered logger names. * * @return enumeration of registered logger names */ @@ -408,16 +408,16 @@ public class LogManager { } /** - * Get the global <code>LogManager</code> instance + * Get the global {@code LogManager} instance. * - * @return the global <code>LogManager</code> instance + * @return the global {@code LogManager} instance */ public static LogManager getLogManager() { return manager; } /** - * Get the value of property with given name + * Get the value of property with given name. * * @param name * the name of property @@ -428,17 +428,17 @@ public class LogManager { } /** - * Re-initialize the properties and configuration. The initialization process - * is same as the <code>LogManager</code> instantiation. + * Re-initialize the properties and configuration. The initialization + * process is same as the {@code LogManager} instantiation. * <p> - * A <code>PropertyChangeEvent</code> must be fired. + * Notice : No {@code PropertyChangeEvent} are fired. * </p> * * @throws IOException - * if any IO related problems happened + * if any IO related problems happened. * @throws SecurityException * if security manager exists and it determines that caller does - * not have the required permissions to perform this action + * not have the required permissions to perform this action. */ public void readConfiguration() throws IOException { checkAccess(); @@ -466,10 +466,13 @@ public class LogManager { // BEGIN android-added try { - input = new BufferedInputStream(new FileInputStream(configFile), 8192); + input = new BufferedInputStream( + new FileInputStream(configFile), 8192); } catch (Exception ex) { // consult fixed resource as a last resort - input = new BufferedInputStream(getClass().getResourceAsStream("logging.properties"), 8192); + input = new BufferedInputStream( + getClass().getResourceAsStream( + "logging.properties"), 8192); } // END android-added readConfigurationImpl(input); @@ -520,7 +523,7 @@ public class LogManager { throws IOException { reset(); props.load(ins); - + // parse property "config" and apply setting String configs = props.getProperty("config"); //$NON-NLS-1$ if (null != configs) { @@ -540,26 +543,24 @@ public class LogManager { logger.setLevel(Level.parse(property)); } } -// BEGIN android-removed -// listeners.firePropertyChange(null, null, null); -// END android-removed + listeners.firePropertyChange(null, null, null); } /** * Re-initialize the properties and configuration from the given - * <code>InputStream</code> + * {@code InputStream} * <p> - * A <code>PropertyChangeEvent</code> must be fired. + * Notice : No {@code PropertyChangeEvent} are fired. * </p> * * @param ins - * the input stream. + * the input stream * @throws IOException - * if any IO related problems happened + * if any IO related problems happened. * @throws SecurityException * if security manager exists and it determines that caller does - * not have the required permissions to perform this action + * not have the required permissions to perform this action. */ public void readConfiguration(InputStream ins) throws IOException { checkAccess(); @@ -571,12 +572,12 @@ public class LogManager { * <p> * All handlers are closed and removed from any named loggers. All loggers' * level is set to null, except the root logger's level is set to - * <code>Level.INFO</code>. + * {@code Level.INFO}. * </p> * * @throws SecurityException * if security manager exists and it determines that caller does - * not have the required permissions to perform this action + * not have the required permissions to perform this action. */ public void reset() { checkAccess(); @@ -596,39 +597,35 @@ public class LogManager { } /** - * Add a <code>PropertyChangeListener</code>, which will be invoked when + * Add a {@code PropertyChangeListener}, which will be invoked when * the properties are reread. * * @param l - * the <code>PropertyChangeListener</code> to be added + * the {@code PropertyChangeListener} to be added. * @throws SecurityException * if security manager exists and it determines that caller does - * not have the required permissions to perform this action + * not have the required permissions to perform this action. */ -// BEGIN android-removed -// public void addPropertyChangeListener(IPropertyChangeListener l) { -// if(l == null){ -// throw new NullPointerException(); -// } -// checkAccess(); -// listeners.addPropertyChangeListener(l); -// } -// END android-removed + public void addPropertyChangeListener(PropertyChangeListener l) { + if(l == null){ + throw new NullPointerException(); + } + checkAccess(); + listeners.addPropertyChangeListener(l); + } /** - * Remove a <code>PropertyChangeListener</code>, do nothing if the given + * Remove a {@code PropertyChangeListener}, do nothing if the given * listener is not found. * * @param l - * the <code>PropertyChangeListener</code> to be removed + * the {@code PropertyChangeListener} to be removed. * @throws SecurityException * if security manager exists and it determines that caller does - * not have the required permissions to perform this action + * not have the required permissions to perform this action. */ -// BEGIN android-removed -// public void removePropertyChangeListener(IPropertyChangeListener l) { -// checkAccess(); -// listeners.removePropertyChangeListener(l); -// } -// END android-removed + public void removePropertyChangeListener(PropertyChangeListener l) { + checkAccess(); + listeners.removePropertyChangeListener(l); + } } diff --git a/logging/src/main/java/java/util/logging/LogRecord.java b/logging/src/main/java/java/util/logging/LogRecord.java index e133797..b8a98ef 100644 --- a/logging/src/main/java/java/util/logging/LogRecord.java +++ b/logging/src/main/java/java/util/logging/LogRecord.java @@ -27,21 +27,22 @@ import java.util.ResourceBundle; import org.apache.harmony.logging.internal.nls.Messages; /** - * A <code>LogRecord</code> object represents a logging request. It is passed - * between the logging framework and individual logging handlers. Client - * applications should not modify a <code>LogRecord</code> object that has - * been passed into the logging framework. + * A {@code LogRecord} object represents a logging request. It is passed between + * the logging framework and individual logging handlers. Client applications + * should not modify a {@code LogRecord} object that has been passed into the + * logging framework. * <p> - * The <code>LogRecord</code> class will infer the source method name and - * source class name the first time they are accessed if the client application - * didn't specify them explicitly. This automatic inference is based on the - * analysis of the call stack and is not guaranteed to be precise. Client - * applications should force the initialization of these two fields by calling - * <code>getSourceClassName</code> or <code>getSourceMethodName</code> if - * they expect to use them after passing the <code>LogRecord</code> object to - * another thread or transmitting it over RMI. + * The {@code LogRecord} class will infer the source method name and source + * class name the first time they are accessed if the client application didn't + * specify them explicitly. This automatic inference is based on the analysis of + * the call stack and is not guaranteed to be precise. Client applications + * should force the initialization of these two fields by calling + * {@code getSourceClassName} or {@code getSourceMethodName} if they expect to + * use them after passing the {@code LogRecord} object to another thread or + * transmitting it over RMI. * </p> * + * @since Android 1.0 */ public class LogRecord implements Serializable { @@ -112,7 +113,7 @@ public class LogRecord implements Serializable { private long millis; /** - * The associated <code>Throwable</code> object if any. + * The associated {@code Throwable} object if any. * * @serial */ @@ -142,16 +143,19 @@ public class LogRecord implements Serializable { private transient boolean sourceInited; /** - * Constructs a <code>LogRecord</code> object using the supplied the - * logging level and message. The millis property is set to the current - * time. The sequence property is set to a new unique value, allocated in - * increasing order within a VM. The thread ID is set to a unique value for - * the current thread. All other properties are set to <code>null</code>. + * Constructs a {@code LogRecord} object using the supplied the logging + * level and message. The millis property is set to the current time. The + * sequence property is set to a new unique value, allocated in increasing + * order within the virtual machine. The thread ID is set to a unique value + * for the current thread. All other properties are set to {@code null}. * * @param level - * the logging level which may not be null + * the logging level, may not be {@code null}. * @param msg - * the raw message + * the raw message. + * @throws NullPointerException + * if {@code level} is {@code null}. + * @since Android 1.0 */ public LogRecord(Level level, String msg) { if (null == level) { @@ -185,7 +189,8 @@ public class LogRecord implements Serializable { /** * Gets the logging level. * - * @return the logging level + * @return the logging level. + * @since Android 1.0 */ public Level getLevel() { return level; @@ -195,7 +200,10 @@ public class LogRecord implements Serializable { * Sets the logging level. * * @param level - * the level to set + * the level to set. + * @throws NullPointerException + * if {@code level} is {@code null}. + * @since Android 1.0 */ public void setLevel(Level level) { if (null == level) { @@ -208,7 +216,8 @@ public class LogRecord implements Serializable { /** * Gets the name of the logger. * - * @return the logger name + * @return the logger name. + * @since Android 1.0 */ public String getLoggerName() { return loggerName; @@ -218,7 +227,8 @@ public class LogRecord implements Serializable { * Sets the name of the logger. * * @param loggerName - * the logger name to set + * the logger name to set. + * @since Android 1.0 */ public void setLoggerName(String loggerName) { this.loggerName = loggerName; @@ -227,36 +237,42 @@ public class LogRecord implements Serializable { /** * Gets the raw message. * - * @return the raw message + * @return the raw message, may be {@code null}. + * @since Android 1.0 */ public String getMessage() { return message; } /** - * Sets the raw message. + * Sets the raw message. When this record is formatted by a logger that has + * a localization resource bundle that contains an entry for {@code message}, + * then the raw message is replaced with its localized version. * * @param message - * the raw message to set + * the raw message to set, may be {@code null}. + * @since Android 1.0 */ public void setMessage(String message) { this.message = message; } /** - * Gets the time that the event occurred, in milliseconds since 1970. + * Gets the time when this event occurred, in milliseconds since 1970. * - * @return the time that the event occurred, in milliseconds since 1970 + * @return the time when this event occurred, in milliseconds since 1970. + * @since Android 1.0 */ public long getMillis() { return millis; } /** - * Sets the time that the event occurred, in milliseconds since 1970. + * Sets the time when this event occurred, in milliseconds since 1970. * * @param millis - * the time that the event occurred, in milliseconds since 1970 + * the time when this event occurred, in milliseconds since 1970. + * @since Android 1.0 */ public void setMillis(long millis) { this.millis = millis; @@ -265,7 +281,9 @@ public class LogRecord implements Serializable { /** * Gets the parameters. * - * @return the array of parameters + * @return the array of parameters or {@code null} if there are no + * parameters. + * @since Android 1.0 */ public Object[] getParameters() { return parameters; @@ -275,7 +293,8 @@ public class LogRecord implements Serializable { * Sets the parameters. * * @param parameters - * the array of parameters to set + * the array of parameters to set, may be {@code null}. + * @since Android 1.0 */ public void setParameters(Object[] parameters) { this.parameters = parameters; @@ -285,18 +304,20 @@ public class LogRecord implements Serializable { * Gets the resource bundle used to localize the raw message during * formatting. * - * @return the associated resource bundle + * @return the associated resource bundle, {@code null} if none is + * available or the message is not localizable. + * @since Android 1.0 */ public ResourceBundle getResourceBundle() { return resourceBundle; } /** - * Sets the resource bundle used to localize the raw message during - * formatting. + * Sets the resource bundle. * * @param resourceBundle - * the resource bundle to set + * the resource bundle to set, may be {@code null}. + * @since Android 1.0 */ public void setResourceBundle(ResourceBundle resourceBundle) { this.resourceBundle = resourceBundle; @@ -305,7 +326,9 @@ public class LogRecord implements Serializable { /** * Gets the name of the resource bundle. * - * @return the name of the resource bundle + * @return the name of the resource bundle, {@code null} if none is + * available or the message is not localizable. + * @since Android 1.0 */ public String getResourceBundleName() { return resourceBundleName; @@ -315,7 +338,8 @@ public class LogRecord implements Serializable { * Sets the name of the resource bundle. * * @param resourceBundleName - * the name of the resource bundle to set + * the name of the resource bundle to set. + * @since Android 1.0 */ public void setResourceBundleName(String resourceBundleName) { this.resourceBundleName = resourceBundleName; @@ -324,28 +348,32 @@ public class LogRecord implements Serializable { /** * Gets the sequence number. * - * @return the sequence number + * @return the sequence number. + * @since Android 1.0 */ public long getSequenceNumber() { return sequenceNumber; } /** - * Sets the sequence number. It is usually unnecessary to call this method + * Sets the sequence number. It is usually not necessary to call this method * to change the sequence number because the number is allocated when this * instance is constructed. * * @param sequenceNumber - * the sequence number to set + * the sequence number to set. + * @since Android 1.0 */ public void setSequenceNumber(long sequenceNumber) { this.sequenceNumber = sequenceNumber; } /** - * Gets the name of the class that issued the logging call. + * Gets the name of the class that is the source of this log record. This + * information can be changed, may be {@code null} and is untrusted. * - * @return the name of the class that issued the logging call + * @return the name of the source class of this log record (possiblity {@code null}) + * @since Android 1.0 */ public String getSourceClassName() { initSource(); @@ -378,10 +406,12 @@ public class LogRecord implements Serializable { } /** - * Sets the name of the class that issued the logging call. + * Sets the name of the class that is the source of this log record. * * @param sourceClassName - * the name of the class that issued the logging call + * the name of the source class of this log record, may be + * {@code null}. + * @since Android 1.0 */ public void setSourceClassName(String sourceClassName) { sourceInited = true; @@ -389,9 +419,10 @@ public class LogRecord implements Serializable { } /** - * Gets the name of the method that issued the logging call. + * Gets the name of the method that is the source of this log record. * - * @return the name of the method that issued the logging call + * @return the name of the source method of this log record. + * @since Android 1.0 */ public String getSourceMethodName() { initSource(); @@ -399,10 +430,12 @@ public class LogRecord implements Serializable { } /** - * Sets the name of the method that issued the logging call. + * Sets the name of the method that is the source of this log record. * * @param sourceMethodName - * the name of the method that issued the logging call + * the name of the source method of this log record, may be + * {@code null}. + * @since Android 1.0 */ public void setSourceMethodName(String sourceMethodName) { sourceInited = true; @@ -410,40 +443,47 @@ public class LogRecord implements Serializable { } /** - * Gets the ID of the thread originating the message. + * Gets a unique ID of the thread originating the log record. Every thread + * becomes a different ID. + * <p> + * Notice : the ID doesn't necessary map the OS thread ID + * </p> * - * @return the ID of the thread originating the message + * @return the ID of the thread originating this log record. + * @since Android 1.0 */ public int getThreadID() { return threadID; } /** - * Sets the ID of the thread originating the message. + * Sets the ID of the thread originating this log record. * * @param threadID - * the ID of the thread originating the message + * the new ID of the thread originating this log record. + * @since Android 1.0 */ public void setThreadID(int threadID) { this.threadID = threadID; } /** - * Gets the <code>Throwable</code> object associated with this log record. + * Gets the {@code Throwable} object associated with this log record. * - * @return the <code>Throwable</code> object associated with this log - * record + * @return the {@code Throwable} object associated with this log record. + * @since Android 1.0 */ public Throwable getThrown() { return thrown; } /** - * Sets the <code>Throwable</code> object associated with this log record. + * Sets the {@code Throwable} object associated with this log record. * * @param thrown - * the <code>Throwable</code> object associated with this log - * record + * the new {@code Throwable} object to associate with this log + * record. + * @since Android 1.0 */ public void setThrown(Throwable thrown) { this.thrown = thrown; diff --git a/logging/src/main/java/java/util/logging/Logger.java b/logging/src/main/java/java/util/logging/Logger.java index fbe32ed..cd88ca0 100644 --- a/logging/src/main/java/java/util/logging/Logger.java +++ b/logging/src/main/java/java/util/logging/Logger.java @@ -33,22 +33,22 @@ import org.apache.harmony.logging.internal.nls.Messages; * etc. They use various handlers to actually do the output-dependent * operations. * <p> - * Client applications can get named loggers by calling the methods - * <code>getLogger</code>. They can also get anonymous loggers by calling the - * methods <code>getAnonymousLogger</code>. Named loggers are organized in a + * Client applications can get named loggers by calling the {@code getLogger} + * methods. They can also get anonymous loggers by calling the + * {@code getAnonymousLogger} methods. Named loggers are organized in a * namespace hierarchy managed by a log manager. The naming convention is - * usually the same as java package's naming convention, i.e., using + * usually the same as java package's naming convention, that is using * dot-separated strings. Anonymous loggers do not belong to any namespace. * </p> * <p> - * Loggers "inherit" log level setting from their parent if its own level is set - * to <code>null</code>. This is also true for the resource bundle. The - * logger's resource bundle is used to localize the log messages if no resource - * bundle name is given when a log method is called. If - * <code>getUseParentHandlers</code> is <code>true</code>, loggers also - * inherit their parent's handlers. Here "inherit" only means the "behaviors" - * are inherited. The internal fields value will not change, for example, - * <code>getLevel()</code> still returns <code>null</code>. + * Loggers "inherit" log level setting from their parent if their own level is + * set to {@code null}. This is also true for the resource bundle. The logger's + * resource bundle is used to localize the log messages if no resource bundle + * name is given when a log method is called. If {@code getUseParentHandlers()} + * returns {@code true}, loggers also inherit their parent's handlers. In this + * context, "inherit" only means that "behavior" is inherited. The internal + * field values will not change, for example, {@code getLevel()} still returns + * {@code null}. * </p> * <p> * When loading a given resource bundle, the logger first tries to use the @@ -59,23 +59,26 @@ import org.apache.harmony.logging.internal.nls.Messages; * <p> * Some log methods accept log requests that do not specify the source class and * source method. In these cases, the logging framework will automatically infer - * the calling class and method, but not guaranteed to be accurate. + * the calling class and method, but this is not guaranteed to be accurate. * </p> * <p> - * Once a <code>LogRecord</code> object has been passed into the logging - * framework, it is owned by the logging framework and the client applications - * should not use it any longer. + * Once a {@code LogRecord} object has been passed into the logging framework, + * it is owned by the logging framework and the client applications should not + * use it any longer. * </p> * <p> * All methods of this class are thread-safe. * </p> * * @see LogManager + * @since Android 1.0 */ public class Logger { /** * The global logger is provided as convenience for casual use. + * + * @since Android 1.0 */ public final static Logger global = new Logger("global", null); //$NON-NLS-1$ @@ -116,7 +119,9 @@ public class Logger { private LogManager manager; + // BEGIN android-changed private volatile boolean handlerInited; + // END android-changed /* @@ -126,16 +131,21 @@ public class Logger { */ /** - * Constructs a <code>Logger</code> object with the supplied name and - * resource bundle name. + * Constructs a {@code Logger} object with the supplied name and resource + * bundle name; {@code notifiyParentHandlers} is set to {@code true}. + * <p> + * Notice : Loggers use a naming hierarchy. Thus "z.x.y" is a child of "z.x". + * </p> * * @param name - * the name of this logger, may be null for anonymous loggers + * the name of this logger, may be {@code null} for anonymous + * loggers. * @param resourceBundleName * the name of the resource bundle used to localize logging - * messages, may be null + * messages, may be {@code null}. * @throws MissingResourceException - * If the specified resource bundle can not be loaded. + * if the specified resource bundle can not be loaded. + * @since Android 1.0 */ protected Logger(String name, String resourceBundleName) { // try to load the specified resource bundle first @@ -199,10 +209,10 @@ public class Logger { * Load the specified resource bundle, use privileged code. * * @param resourceBundleName - * the name of the resource bundle to load, cannot be null + * the name of the resource bundle to load, cannot be {@code null}. * @return the loaded resource bundle. * @throws MissingResourceException - * If the specified resource bundle can not be loaded. + * if the specified resource bundle can not be loaded. */ static ResourceBundle loadResourceBundle(String resourceBundleName) { // try context class loader to load the resource @@ -270,14 +280,14 @@ public class Logger { /** * Gets an anonymous logger to use internally in a thread. Anonymous loggers * are not registered in the log manager's namespace. No security checks - * will be performed when updating an anonymous logger's control settings - * so that they can be used in applets. + * will be performed when updating an anonymous logger's control settings. * <p> - * Anonymous loggers' parent is set to be the root logger. This enables - * them to inherit default logging level and handlers from the root logger. + * The anonymous loggers' parent is set to be the root logger. This way it + * inherits the default logging level and handlers from the root logger. * </p> * - * @return a new instance of anonymous logger + * @return a new instance of anonymous logger. + * @since Android 1.0 */ public static Logger getAnonymousLogger() { return getAnonymousLogger(null); @@ -286,18 +296,18 @@ public class Logger { /** * Gets an anonymous logger to use internally in a thread. Anonymous loggers * are not registered in the log manager's namespace. No security checks - * will be performed when updating an anonymous logger's control settings - * so that they can be used in applets. + * will be performed when updating an anonymous logger's control settings. * <p> - * Anonymous loggers' parent is set to be the root logger. This enables - * them to inherit default logging level and handlers from the root logger. + * The anonymous loggers' parent is set to be the root logger. This way it + * inherits default logging level and handlers from the root logger. * </p> * * @param resourceBundleName - * the name of the resource bundle used to localize log messages - * @return a new instance of anonymous logger + * the name of the resource bundle used to localize log messages. + * @return a new instance of anonymous logger. * @throws MissingResourceException - * If the specified resource bundle can not be loaded. + * if the specified resource bundle can not be loaded. + * @since Android 1.0 */ public static Logger getAnonymousLogger(String resourceBundleName) { final Logger l = new Logger(null, resourceBundleName); @@ -365,15 +375,14 @@ public class Logger { } /** - * Gets a named logger. The returned logger may already exist, or may be - * newly created. If the latter, its level will be set to the configured - * level according to the <code>LogManager</code>'s properties if any. + * Gets a named logger. The returned logger may already exist or may be + * newly created. In the latter case, its level will be set to the + * configured level according to the {@code LogManager}'s properties. * * @param name - * the name of the logger to get, cannot be null - * @return a named logger - * @throws MissingResourceException - * If the specified resource bundle can not be loaded. + * the name of the logger to get, cannot be {@code null}. + * @return a named logger. + * @since Android 1.0 */ public static Logger getLogger(String name) { return getLoggerWithRes(name, null, false); @@ -384,24 +393,32 @@ public class Logger { * resource bundle will be used to localize logging messages. * * @param name - * the name of the logger to get, cannot be null + * the name of the logger to get, cannot be {@code null}. * @param resourceBundleName - * the name of the resource bundle, may be null - * @return a named logger + * the name of the resource bundle, may be {@code null}. + * @throws IllegalArgumentException + * if the logger identified by {@code name} is associated with a + * resource bundle and its name is not equal to + * {@code resourceBundleName}. + * @throws MissingResourceException + * if the name of the resource bundle cannot be found. + * @return a named logger. + * @since Android 1.0 */ public static Logger getLogger(String name, String resourceBundleName) { return getLoggerWithRes(name, resourceBundleName, true); } /** - * Adds a handler to this logger. The handler will be fed with log records - * received by this logger. + * Adds a handler to this logger. The {@code name} will be fed with log + * records received by this logger. * * @param handler - * the handler object to add, cannot be null + * the handler object to add, cannot be {@code null}. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public void addHandler(Handler handler) { if (null == handler) { @@ -434,7 +451,6 @@ public class Logger { */ LogManager.getLogManager(); // END android-added - if (handlers == null) { handlers = new ArrayList<Handler>(); } @@ -450,8 +466,8 @@ public class Logger { StringTokenizer st = new StringTokenizer(handlerStr, " "); //$NON-NLS-1$ while (st.hasMoreTokens()) { String handlerName = st.nextToken(); - - // BEGIN android-changed: deal with non-existing handler + // BEGIN android-changed + // deal with non-existing handler try { Handler handler = (Handler) LogManager .getInstanceByClass(handlerName); @@ -465,7 +481,6 @@ public class Logger { ex.printStackTrace(); } // END android-changed - } handlerInited = true; } @@ -476,7 +491,8 @@ public class Logger { /** * Gets all the handlers associated with this logger. * - * @return an array of all the handlers associated with this logger + * @return an array of all the handlers associated with this logger. + * @since Android 1.0 */ public Handler[] getHandlers() { initHandler(); @@ -486,14 +502,15 @@ public class Logger { } /** - * Removes a handler for this logger. If the specified handler does not - * exist, this method has no effect. + * Removes a handler from this logger. If the specified handler does not + * exist then this method has no effect. * * @param handler - * the handler to be removed, cannot be null + * the handler to be removed. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public void removeHandler(Handler handler) { // Anonymous loggers can always remove handlers @@ -512,7 +529,8 @@ public class Logger { /** * Gets the filter used by this logger. * - * @return the filter used by this logger + * @return the filter used by this logger, may be {@code null}. + * @since Android 1.0 */ public Filter getFilter() { return this.filter; @@ -522,10 +540,11 @@ public class Logger { * Sets the filter used by this logger. * * @param newFilter - * the filter to set + * the filter to set, may be {@code null}. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public void setFilter(Filter newFilter) { // Anonymous loggers can always set the filter @@ -536,23 +555,26 @@ public class Logger { } /** - * Gets the logging level of this logger. + * Gets the logging level of this logger. A {@code null} level indicates + * that this logger inherits its parent's level. * - * @return the logging level of this logger + * @return the logging level of this logger. + * @since Android 1.0 */ public Level getLevel() { return levelObjVal; } /** - * Sets the logging level for this logger. A <code>null</code> level - * indicates this logger will inherit its parent's level. + * Sets the logging level for this logger. A {@code null} level indicates + * that this logger will inherit its parent's level. * * @param newLevel - * the logging level to set + * the logging level to set. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public void setLevel(Level newLevel) { // Anonymous loggers can always set the level @@ -565,25 +587,28 @@ public class Logger { } /** - * Gets the flag which indicates whether to use parent's handlers to publish - * incoming log records, potentially recursively up the namespace. + * Gets the flag which indicates whether to use the handlers of this + * logger's parent to publish incoming log records, potentially recursively + * up the namespace. * - * @return <code>true</code> if set to use parent's handlers, otherwise - * <code>false</code> + * @return {@code true} if set to use parent's handlers, {@code false} + * otherwise. + * @since Android 1.0 */ public boolean getUseParentHandlers() { return this.notifyParentHandlers; } /** - * Sets the flag which indicates whether to use parent's handlers to publish - * incoming log records, potentially recursively up the namespace. + * Sets the flag which indicates whether to use the handlers of this + * logger's parent, potentially recursively up the namespace. * * @param notifyParentHandlers - * the flag whether to use parent's handlers + * the new flag indicating whether to use the parent's handlers. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public void setUseParentHandlers(boolean notifyParentHandlers) { // Anonymous loggers can always set the useParentHandlers flag @@ -594,9 +619,11 @@ public class Logger { } /** - * Gets the parent of this logger in the namespace. + * Gets the nearest parent of this logger in the namespace, a {@code null} + * value will be returned if called on the root logger. * - * @return the parent of this logger in the namespace + * @return the parent of this logger in the namespace. + * @since Android 1.0 */ public Logger getParent() { return parent; @@ -604,11 +631,12 @@ public class Logger { /** * Sets the parent of this logger in the namespace. This method should - * usually be used by the <code>LogManager</code> object only. This - * method does not check security. + * usually be used by the {@code LogManager} object only. This method does + * not check security. * * @param newParent - * the parent logger to set + * the parent logger to set. + * @since Android 1.0 */ void internalSetParent(Logger newParent) { //All hierarchy related modifications should get LogManager lock at first @@ -624,14 +652,15 @@ public class Logger { } /** - * Sets the parent of this logger in the namespace. This method should - * usually be used by the <code>LogManager</code> object only. + * Sets the parent of this logger in the namespace. This method should be + * used by the {@code LogManager} object only. * * @param parent - * the parent logger to set + * the parent logger to set. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ public void setParent(Logger parent) { if (null == parent) { @@ -653,9 +682,10 @@ public class Logger { /** - * Gets the name of this logger. + * Gets the name of this logger, {@code null} for anonymous loggers. * - * @return the name of this logger + * @return the name of this logger. + * @since Android 1.0 */ public String getName() { return this.name; @@ -663,9 +693,11 @@ public class Logger { /** * Gets the loaded resource bundle used by this logger to localize logging - * messages. If it's null, the parent's resource bundle will be inherited. + * messages. If the value is {@code null}, the parent's resource bundle will be + * inherited. * - * @return the loaded resource bundle used by this logger + * @return the loaded resource bundle used by this logger. + * @since Android 1.0 */ public ResourceBundle getResourceBundle() { return this.resBundle; @@ -673,19 +705,20 @@ public class Logger { /** * Gets the name of the loaded resource bundle used by this logger to - * localize logging messages. If it's null, the parent's resource bundle - * name will be inherited. + * localize logging messages. If the value is {@code null}, the parent's resource + * bundle name will be inherited. * - * @return the name of the loaded resource bundle used by this logger + * @return the name of the loaded resource bundle used by this logger. + * @since Android 1.0 */ public String getResourceBundleName() { return this.resBundleName; } /** - * This method is for compatibility. Tests written to the reference - * implementation API imply that the isLoggable() method is not called - * directly. This behavior is important because subclass may override + * This method is for compatibility. Tests written to the reference + * implementation API imply that the isLoggable() method is not called + * directly. This behavior is important because subclass may override * isLoggable() method, so that affect the result of log methods. */ private boolean internalIsLoggable(Level l) { @@ -700,12 +733,13 @@ public class Logger { /** * Determines whether this logger will actually log messages of the * specified level. The effective level used to do the determination may be - * inherited from its parent. The default level is <code>Level.INFO</code>. + * inherited from its parent. The default level is {@code Level.INFO}. * * @param l - * the level to check - * @return <code>true</code> if this logger will actually log this level, - * otherwise <code>false</code> + * the level to check. + * @return {@code true} if this logger will actually log this level, + * otherwise {@code false}. + * @since Android 1.0 */ public boolean isLoggable(Level l) { return internalIsLoggable(l); @@ -738,14 +772,15 @@ public class Logger { } /** - * Logs a message indicating entering a method. A log record with log level - * <code>Level.FINER</code>, log message "ENTRY", and the specified + * Logs a message indicating that a method has been entered. A log record + * with log level {@code Level.FINER}, log message "ENTRY", the specified * source class name and source method name is submitted for logging. * * @param sourceClass - * the calling class name + * the calling class name. * @param sourceMethod - * the method name + * the method name. + * @since Android 1.0 */ public void entering(String sourceClass, String sourceMethod) { if (internalIsLoggable(Level.FINER)) { @@ -759,17 +794,18 @@ public class Logger { } /** - * Logs a message indicating entering a method. A log record with log level - * <code>Level.FINER</code>, log message "ENTRY", and the specified - * source class name and source method name and one parameter is submitted - * for logging. + * Logs a message indicating that a method has been entered. A log record + * with log level {@code Level.FINER}, log message "ENTRY", the specified + * source class name, source method name and one parameter is submitted for + * logging. * * @param sourceClass - * the source class name + * the source class name. * @param sourceMethod - * the source method name + * the source method name. * @param param - * the parameter for the method call + * the parameter for the method call. + * @since Android 1.0 */ public void entering(String sourceClass, String sourceMethod, Object param) { if (internalIsLoggable(Level.FINER)) { @@ -784,17 +820,18 @@ public class Logger { } /** - * Logs a message indicating entering a method. A log record with log level - * <code>Level.FINER</code>, log message "ENTRY", and the specified - * source class name and source method name and parameters is submitted for - * logging. + * Logs a message indicating that a method has been entered. A log record + * with log level {@code Level.FINER}, log message "ENTRY", the specified + * source class name, source method name and array of parameters is + * submitted for logging. * * @param sourceClass - * the source class name + * the source class name. * @param sourceMethod - * the source method name + * the source method name. * @param params - * an array of parameters for the method call + * an array of parameters for the method call. + * @since Android 1.0 */ public void entering(String sourceClass, String sourceMethod, Object[] params) { @@ -818,14 +855,15 @@ public class Logger { } /** - * Logs a message indicating existing a method. A log record with log level - * <code>Level.FINER</code>, log message "RETURN", and the specified - * source class name and source method name is submitted for logging. + * Logs a message indicating that a method is exited. A log record with log + * level {@code Level.FINER}, log message "RETURN", the specified source + * class name and source method name is submitted for logging. * * @param sourceClass - * the calling class name + * the calling class name. * @param sourceMethod - * the method name + * the method name. + * @since Android 1.0 */ public void exiting(String sourceClass, String sourceMethod) { if (internalIsLoggable(Level.FINER)) { @@ -839,17 +877,17 @@ public class Logger { } /** - * Logs a message indicating exiting a method. A log record with log level - * <code>Level.FINER</code>, log message "RETURN", and the specified - * source class name and source method name and return value is submitted - * for logging. + * Logs a message indicating that a method is exited. A log record with log + * level {@code Level.FINER}, log message "RETURN", the specified source + * class name, source method name and return value is submitted for logging. * * @param sourceClass - * the source class name + * the source class name. * @param sourceMethod - * the source method name + * the source method name. * @param result - * the return value of the method call + * the return value of the method call. + * @since Android 1.0 */ public void exiting(String sourceClass, String sourceMethod, Object result) { if (internalIsLoggable(Level.FINER)) { @@ -864,17 +902,18 @@ public class Logger { } /** - * Logs a message indicating throwing an exception. A log record with log - * level <code>Level.FINER</code>, log message "THROW", and the specified - * source class name and source method name and <code>Throwable</code> - * object is submitted for logging. + * Logs a message indicating that an exception is thrown. A log record with + * log level {@code Level.FINER}, log message "THROW", the specified source + * class name, source method name and the {@code Throwable} object is + * submitted for logging. * * @param sourceClass - * the source class name + * the source class name. * @param sourceMethod - * the source method name + * the source method name. * @param thrown - * the <code>Throwable</code> object + * the {@code Throwable} object. + * @since Android 1.0 */ public void throwing(String sourceClass, String sourceMethod, Throwable thrown) { @@ -890,10 +929,12 @@ public class Logger { } /** - * Logs a message of level <code>Level.SEVERE</code>. + * Logs a message of level {@code Level.SEVERE}; the message is transmitted + * to all subscribed handlers. * * @param msg - * the message to log + * the message to log. + * @since Android 1.0 */ public void severe(String msg) { if (internalIsLoggable(Level.SEVERE)) { @@ -905,10 +946,12 @@ public class Logger { } /** - * Logs a message of level <code>Level.WARNING</code>. + * Logs a message of level {@code Level.WARNING}; the message is + * transmitted to all subscribed handlers. * * @param msg - * the message to log + * the message to log. + * @since Android 1.0 */ public void warning(String msg) { if (internalIsLoggable(Level.WARNING)) { @@ -920,10 +963,12 @@ public class Logger { } /** - * Logs a message of level <code>Level.INFO</code>. + * Logs a message of level {@code Level.INFO}; the message is transmitted + * to all subscribed handlers. * * @param msg - * the message to log + * the message to log. + * @since Android 1.0 */ public void info(String msg) { if (internalIsLoggable(Level.INFO)) { @@ -935,10 +980,12 @@ public class Logger { } /** - * Logs a message of level <code>Level.CONFIG</code>. + * Logs a message of level {@code Level.CONFIG}; the message is transmitted + * to all subscribed handlers. * * @param msg - * the message to log + * the message to log. + * @since Android 1.0 */ public void config(String msg) { if (internalIsLoggable(Level.CONFIG)) { @@ -950,10 +997,12 @@ public class Logger { } /** - * Logs a message of level <code>Level.FINE</code>. + * Logs a message of level {@code Level.FINE}; the message is transmitted + * to all subscribed handlers. * * @param msg - * the message to log + * the message to log. + * @since Android 1.0 */ public void fine(String msg) { if (internalIsLoggable(Level.FINE)) { @@ -965,10 +1014,12 @@ public class Logger { } /** - * Logs a message of level <code>Level.FINER</code>. + * Logs a message of level {@code Level.FINER}; the message is transmitted + * to all subscribed handlers. * * @param msg - * the message to log + * the message to log. + * @since Android 1.0 */ public void finer(String msg) { if (internalIsLoggable(Level.FINER)) { @@ -980,10 +1031,12 @@ public class Logger { } /** - * Logs a message of level <code>Level.FINEST</code>. + * Logs a message of level {@code Level.FINEST}; the message is transmitted + * to all subscribed handlers. * * @param msg - * the message to log + * the message to log. + * @since Android 1.0 */ public void finest(String msg) { if (internalIsLoggable(Level.FINEST)) { @@ -995,12 +1048,14 @@ public class Logger { } /** - * Logs a message of the specified level. + * Logs a message of the specified level. The message is transmitted to all + * subscribed handlers. * * @param logLevel - * the level of the given message + * the level of the specified message. * @param msg - * the message to log + * the message to log. + * @since Android 1.0 */ public void log(Level logLevel, String msg) { if (internalIsLoggable(logLevel)) { @@ -1012,14 +1067,16 @@ public class Logger { } /** - * Logs a message of the specified level with the supplied parameter. + * Logs a message of the specified level with the supplied parameter. The + * message is then transmitted to all subscribed handlers. * * @param logLevel - * the level of the given message + * the level of the given message. * @param msg - * the message to log + * the message to log. * @param param - * the parameter associated with the event that need to be logged + * the parameter associated with the event that is logged. + * @since Android 1.0 */ public void log(Level logLevel, String msg, Object param) { if (internalIsLoggable(logLevel)) { @@ -1033,14 +1090,15 @@ public class Logger { /** * Logs a message of the specified level with the supplied parameter array. + * The message is then transmitted to all subscribed handlers. * * @param logLevel * the level of the given message * @param msg - * the message to log + * the message to log. * @param params - * the parameter array associated with the event that need to be - * logged + * the parameter array associated with the event that is logged. + * @since Android 1.0 */ public void log(Level logLevel, String msg, Object[] params) { if (internalIsLoggable(logLevel)) { @@ -1053,16 +1111,17 @@ public class Logger { } /** - * Logs a message of the specified level with the supplied - * <code>Throwable</code> object. + * Logs a message of the specified level with the supplied {@code Throwable} + * object. The message is then transmitted to all subscribed handlers. * * @param logLevel - * the level of the given message + * the level of the given message. * @param msg - * the message to log + * the message to log. * @param thrown - * the <code>Throwable</code> object associated with the event - * that need to be logged + * the {@code Throwable} object associated with the event that is + * logged. + * @since Android 1.0 */ public void log(Level logLevel, String msg, Throwable thrown) { if (internalIsLoggable(logLevel)) { @@ -1075,11 +1134,11 @@ public class Logger { } /** - * Logs a given log record. Only those with a logging level no lower than - * this logger's level will be submitted to this logger's handlers for - * logging. If <code>getUseParentHandlers()</code> is <code>true</code>, - * the log record will also be submitted to the parent logger's handlers, - * potentially recursively up the namespace. + * Logs a given log record. Only records with a logging level that is equal + * or greater than this logger's level will be submitted to this logger's + * handlers for logging. If {@code getUseParentHandlers()} returns {@code + * true}, the log record will also be submitted to the handlers of this + * logger's parent, potentially recursively up the namespace. * <p> * Since all other log methods call this method to actually perform the * logging action, subclasses of this class can override this method to @@ -1087,7 +1146,8 @@ public class Logger { * </p> * * @param record - * the log record to be logged + * the log record to be logged. + * @since Android 1.0 */ public void log(LogRecord record) { if (internalIsLoggable(record.getLevel())) { @@ -1124,13 +1184,14 @@ public class Logger { * and source method name. * * @param logLevel - * the level of the given message + * the level of the given message. * @param sourceClass - * the source class name + * the source class name. * @param sourceMethod - * the source method name + * the source method name. * @param msg - * the message to be logged + * the message to be logged. + * @since Android 1.0 */ public void logp(Level logLevel, String sourceClass, String sourceMethod, String msg) { @@ -1145,8 +1206,8 @@ public class Logger { } /** - * Logs a message of the given level with the specified source class name - * and source method name and parameter. + * Logs a message of the given level with the specified source class name, + * source method name and parameter. * * @param logLevel * the level of the given message @@ -1157,7 +1218,8 @@ public class Logger { * @param msg * the message to be logged * @param param - * the parameter associated with the event that need to be logged + * the parameter associated with the event that is logged. + * @since Android 1.0 */ public void logp(Level logLevel, String sourceClass, String sourceMethod, String msg, Object param) { @@ -1173,20 +1235,20 @@ public class Logger { } /** - * Logs a message of the given level with the specified source class name - * and source method name and parameter array. + * Logs a message of the given level with the specified source class name, + * source method name and parameter array. * * @param logLevel - * the level of the given message + * the level of the given message. * @param sourceClass - * the source class name + * the source class name. * @param sourceMethod - * the source method name + * the source method name. * @param msg - * the message to be logged + * the message to be logged. * @param params - * the parameter array associated with the event that need to be - * logged + * the parameter array associated with the event that is logged. + * @since Android 1.0 */ public void logp(Level logLevel, String sourceClass, String sourceMethod, String msg, Object[] params) { @@ -1202,19 +1264,20 @@ public class Logger { } /** - * Logs a message of the given level with the specified source class name - * and source method name and <code>Throwable</code> object. + * Logs a message of the given level with the specified source class name, + * source method name and {@code Throwable} object. * * @param logLevel - * the level of the given message + * the level of the given message. * @param sourceClass - * the source class name + * the source class name. * @param sourceMethod - * the source method name + * the source method name. * @param msg - * the message to be logged + * the message to be logged. * @param thrown - * the <code>Throwable</code> object + * the {@code Throwable} object. + * @since Android 1.0 */ public void logp(Level logLevel, String sourceClass, String sourceMethod, String msg, Throwable thrown) { @@ -1232,18 +1295,20 @@ public class Logger { /** * Logs a message of the given level with the specified source class name * and source method name, using the given resource bundle to localize the - * message. + * message. If {@code bundleName} is null, the empty string or not valid then + * the message is not localized. * * @param logLevel - * the level of the given message + * the level of the given message. * @param sourceClass - * the source class name + * the source class name. * @param sourceMethod - * the source method name + * the source method name. * @param bundleName - * the name of the resource bundle, used to localize the message + * the name of the resource bundle used to localize the message. * @param msg - * the message to be logged + * the message to be logged. + * @since Android 1.0 */ public void logrb(Level logLevel, String sourceClass, String sourceMethod, String bundleName, String msg) { @@ -1265,22 +1330,24 @@ public class Logger { } /** - * Logs a message of the given level with the specified source class name - * and source method name and parameter, using the given resource bundle to - * localize the message. + * Logs a message of the given level with the specified source class name, + * source method name and parameter, using the given resource bundle to + * localize the message. If {@code bundleName} is null, the empty string + * or not valid then the message is not localized. * * @param logLevel - * the level of the given message + * the level of the given message. * @param sourceClass - * the source class name + * the source class name. * @param sourceMethod - * the source method name + * the source method name. * @param bundleName - * the name of the resource bundle, used to localize the message + * the name of the resource bundle used to localize the message. * @param msg - * the message to be logged + * the message to be logged. * @param param - * the parameter associated with the event that need to be logged + * the parameter associated with the event that is logged. + * @since Android 1.0 */ public void logrb(Level logLevel, String sourceClass, String sourceMethod, String bundleName, String msg, Object param) { @@ -1303,23 +1370,24 @@ public class Logger { } /** - * Logs a message of the given level with the specified source class name - * and source method name and parameter array, using the given resource - * bundle to localize the message. + * Logs a message of the given level with the specified source class name, + * source method name and parameter array, using the given resource bundle + * to localize the message. If {@code bundleName} is null, the empty string + * or not valid then the message is not localized. * * @param logLevel - * the level of the given message + * the level of the given message. * @param sourceClass - * the source class name + * the source class name. * @param sourceMethod - * the source method name + * the source method name. * @param bundleName - * the name of the resource bundle, used to localize the message + * the name of the resource bundle used to localize the message. * @param msg - * the message to be logged + * the message to be logged. * @param params - * the parameter array associated with the event that need to be - * logged + * the parameter array associated with the event that is logged. + * @since Android 1.0 */ public void logrb(Level logLevel, String sourceClass, String sourceMethod, String bundleName, String msg, Object[] params) { @@ -1342,9 +1410,10 @@ public class Logger { } /** - * Logs a message of the given level with the specified source class name - * and source method name and <code>Throwable</code> object, using the - * given resource bundle to localize the message. + * Logs a message of the given level with the specified source class name, + * source method name and {@code Throwable} object, using the given resource + * bundle to localize the message. If {@code bundleName} is null, the empty + * string or not valid then the message is not localized. * * @param logLevel * the level of the given message @@ -1353,11 +1422,12 @@ public class Logger { * @param sourceMethod * the source method name * @param bundleName - * the name of the resource bundle, used to localize the message + * the name of the resource bundle used to localize the message. * @param msg - * the message to be logged + * the message to be logged. * @param thrown - * the <code>Throwable</code> object + * the {@code Throwable} object. + * @since Android 1.0 */ public void logrb(Level logLevel, String sourceClass, String sourceMethod, String bundleName, String msg, Throwable thrown) { diff --git a/logging/src/main/java/java/util/logging/LoggingMXBean.java b/logging/src/main/java/java/util/logging/LoggingMXBean.java index 71ea65d..f6b49a6 100644 --- a/logging/src/main/java/java/util/logging/LoggingMXBean.java +++ b/logging/src/main/java/java/util/logging/LoggingMXBean.java @@ -20,67 +20,66 @@ package java.util.logging; import java.util.List; /** + * {@code LoggingMXBean} is the management interface for the logging sub-system. * <p> - * The management interface for the logging sub-system. + * The ObjectName for identifying the {@code LoggingMXBean} in a bean server is + * {@link LogManager#LOGGING_MXBEAN_NAME}. * </p> * - * <p> - * ObjectName = - * {@link LogManager#LOGGING_MXBEAN_NAME java.util.logging:type=Logging} - * </p> - * - * @since 1.5 + * @since Android 1.0 */ public interface LoggingMXBean { /** - * <p> - * Gets the String value of the logging level of a logger. An empty String - * is returned when the logger's level is defined by its parent. - * </p> + * Gets the string value of the logging level of a logger. An empty string + * is returned when the logger's level is defined by its parent. A + * {@code null} is returned if the specified logger does not exist. * - * @param loggerName The name of the logger lookup. - * @return A String if the logger was found, otherwise <code>null</code>. + * @param loggerName + * the name of the logger lookup. + * @return a {@code String} if the logger is found, otherwise {@code null}. * @see Level#getName() + * @since Android 1.0 */ String getLoggerLevel(String loggerName); /** - * <p> - * Gets a list of all currently registered logger's names. This is performed + * Gets a list of all currently registered logger names. This is performed * using the {@link LogManager#getLoggerNames()}. - * </p> * - * @return A List of String instances. + * @return a list of logger names. + * @since Android 1.0 */ List<String> getLoggerNames(); /** - * <p> * Gets the name of the parent logger of a logger. If the logger doesn't - * exist then <code>null</code> is returned. If the logger is the root - * logger, then an empty String is returned. - * </p> + * exist then {@code null} is returned. If the logger is the root logger, + * then an empty {@code String} is returned. * - * @param loggerName The name of the logger to lookup. - * @return A String if the logger was found, otherwise <code>null</code>. + * @param loggerName + * the name of the logger to lookup. + * @return a {@code String} if the logger was found, otherwise {@code null}. + * @since Android 1.0 */ String getParentLoggerName(String loggerName); /** - * <p> - * Sets the log level of a logger. - * </p> + * Sets the log level of a logger. LevelName set to {@code null} means the + * level is inherited from the nearest non-null ancestor. * - * @param loggerName The name of the logger to set the level on, which must - * not be <code>null</code>. - * @param levelName The level to set on the logger, which may be - * <code>null</code>. - * @throws IllegalArgumentException if <code>loggerName</code> is not a - * registered logger or if <code>levelName</code> is not null and - * an invalid value. - * @throws SecurityException if a security manager exists and the caller - * doesn't have LoggingPermission("control"). + * @param loggerName + * the name of the logger to set the level on, which must not be + * {@code null}. + * @param levelName + * the level to set on the logger, which may be {@code null}. + * @throws IllegalArgumentException + * if {@code loggerName} is not a registered logger or if + * {@code levelName} is not null and not valid. + * @throws SecurityException + * if a security manager exists and the caller doesn't have + * LoggingPermission("control"). * @see Level#parse(String) + * @since Android 1.0 */ void setLoggerLevel(String loggerName, String levelName); } diff --git a/logging/src/main/java/java/util/logging/LoggingPermission.java b/logging/src/main/java/java/util/logging/LoggingPermission.java index 6962127..fb6d4f8 100644 --- a/logging/src/main/java/java/util/logging/LoggingPermission.java +++ b/logging/src/main/java/java/util/logging/LoggingPermission.java @@ -26,7 +26,7 @@ import org.apache.harmony.logging.internal.nls.Messages; /** * The permission required to control the logging when run with a - * <code>SecurityManager</code>. + * {@code SecurityManager}. * */ public final class LoggingPermission extends BasicPermission implements Guard, @@ -43,14 +43,20 @@ public final class LoggingPermission extends BasicPermission implements Guard, */ /** - * Constructs a <code>LoggingPermission</code> object required to control - * the logging. + * Constructs a {@code LoggingPermission} object required to control the + * logging. The {@code SecurityManager} checks the permissions. + * <p> + * {@code LoggingPermission} objects are created by the security policy code + * and depends on the security policy file, therefore programmers shouldn't + * normally use them directly. + * </p> * * @param name - * Currently must be "control". + * currently must be "control". * @param actions - * Currently must be either <code>null</code> or the empty - * string. + * currently must be either {@code null} or the empty string. + * @throws IllegalArgumentException + * if name null or different from {@code string} control. */ public LoggingPermission(String name, String actions) { super(name, actions); diff --git a/logging/src/main/java/java/util/logging/MemoryHandler.java b/logging/src/main/java/java/util/logging/MemoryHandler.java index ca96dc5..c1e8670 100644 --- a/logging/src/main/java/java/util/logging/MemoryHandler.java +++ b/logging/src/main/java/java/util/logging/MemoryHandler.java @@ -24,46 +24,47 @@ import org.apache.harmony.logging.internal.nls.Messages; /** - * A <code>Handler</code> put the description of log events into a cycled memory + * A {@code Handler} put the description of log events into a cycled memory * buffer. - * <p> - * Mostly this <code>MemoryHandler</code> just puts the given <code>LogRecord</code> - * into the internal buffer and doesn't perform any formatting or any other process. - * When the buffer is full, the earliest buffered records will be discarded. + * <p> + * Mostly this {@code MemoryHandler} just puts the given {@code LogRecord} into + * the internal buffer and doesn't perform any formatting or any other process. + * When the buffer is full, the earliest buffered records will be discarded. * </p> * <p> - * Every <code>MemoryHandler</code> has a target handler, and push action can be - * triggered so that all buffered records will be output to the target handler - * and normally the latter will publish the records. After the push action, the - * buffer will be cleared. + * Every {@code MemoryHandler} has a target handler, and push action can be + * triggered so that all buffered records will be output to the target handler + * and normally the latter will publish the records. After the push action, the + * buffer will be cleared. * </p> * <p> * The push action can be triggered in three ways: * <ul> * <li>The push method is called explicitly</li> - * <li>When a new <code>LogRecord</code> is put into the internal buffer, and it has a level which is not less than the specified push level.</li> - * <li>A subclass extends this <code>MemoryHandler</code> and call push method implicitly according to some criteria.</li> + * <li>When a new {@code LogRecord} is put into the internal buffer, and it has + * a level which is not less than the specified push level.</li> + * <li>A subclass extends this {@code MemoryHandler} and call push method + * implicitly according to some criteria.</li> * </ul> * </p> * <p> - * <code>MemoryHandler</code> will read following <code>LogManager</code> - * properties for initialization, if given properties are not defined or has - * invalid values, default value will be used. + * {@code MemoryHandler} will read following {@code LogManager} properties for + * initialization, if given properties are not defined or has invalid values, + * default value will be used. * <ul> - * <li>java.util.logging.MemoryHandler.level specifies the level for this - * <code>Handler</code>, defaults to <code>Level.ALL</code>.</li> - * <li>java.util.logging.MemoryHandler.filter specifies the <code>Filter</code> - * class name, defaults to no <code>Filter</code>.</li> - * <li>java.util.logging.MemoryHandler.size specifies the buffer size in number - * of <code>LogRecord</code>, defaults to 1000.</li> - * <li>java.util.logging.MemoryHandler.push specifies the push level, defaults + * <li>java.util.logging.MemoryHandler.level specifies the level for this + * {@code Handler}, defaults to {@code Level.ALL}.</li> + * <li>java.util.logging.MemoryHandler.filter specifies the {@code Filter} + * class name, defaults to no {@code Filter}.</li> + * <li>java.util.logging.MemoryHandler.size specifies the buffer size in number + * of {@code LogRecord}, defaults to 1000.</li> + * <li>java.util.logging.MemoryHandler.push specifies the push level, defaults * to level.SEVERE.</li> - * <li>java.util.logging.MemoryHandler.target specifies the class of the target - * <code>Handler</code>, no default value, which means this property must be - * specified either by property setting or by constructor.</li> + * <li>java.util.logging.MemoryHandler.target specifies the class of the target + * {@code Handler}, no default value, which means this property must be + * specified either by property setting or by constructor.</li> * </ul> * </p> - * */ public class MemoryHandler extends Handler { @@ -88,8 +89,12 @@ public class MemoryHandler extends Handler { private int cursor; /** - * Default constructor, construct and init a <code>MemoryHandler</code> using - * <code>LogManager</code> properties or default values + * Default constructor, construct and init a {@code MemoryHandler} using + * {@code LogManager} properties or default values. + * + * @throws RuntimeException + * if property value are invalid and no default value could be + * used. */ public MemoryHandler() { super(); @@ -139,17 +144,22 @@ public class MemoryHandler extends Handler { } /** - * Construct and init a <code>MemoryHandler</code> using given target, size - * and push level, other properties using <code>LogManager</code> properties - * or default values + * Construct and init a {@code MemoryHandler} using given target, size and + * push level, other properties using {@code LogManager} properties or + * default values. * * @param target - * the given <code>Handler</code> to output - * @param size the maximum number of buffered <code>LogRecord</code> + * the given {@code Handler} to output + * @param size + * the maximum number of buffered {@code LogRecord}, greater than + * zero * @param pushLevel - * the push level + * the push level * @throws IllegalArgumentException - * if size<=0 + * if {@code size}<=0 + * @throws RuntimeException + * if property value are invalid and no default value could be + * used. */ public MemoryHandler(Handler target, int size, Level pushLevel) { if (size <= 0) { @@ -166,11 +176,11 @@ public class MemoryHandler extends Handler { } /** - * Close this handler and target handler, free all associated resources + * Close this handler and target handler, free all associated resources. * * @throws SecurityException - * if security manager exists and it determines that caller - * does not have the required permissions to control this handler + * if security manager exists and it determines that caller does + * not have the required permissions to control this handler. */ @Override public void close() { @@ -180,10 +190,8 @@ public class MemoryHandler extends Handler { } /** - * Call target handler to flush any buffered output. - * - * Note that this doesn't cause this <code>MemoryHandler</code> to push. - * + * Call target handler to flush any buffered output. Note that this doesn't + * cause this {@code MemoryHandler} to push. */ @Override public void flush() { @@ -191,14 +199,14 @@ public class MemoryHandler extends Handler { } /** - * Put a given <code>LogRecord</code> into internal buffer. - * - * If given record is not loggable, just return. Otherwise it is stored in - * the buffer. Furthermore if the record's level is not less than the push - * level, the push action is triggered to output all the buffered records - * to the target handler, and the target handler will publish them. + * Put a given {@code LogRecord} into internal buffer. If given record is + * not loggable, just return. Otherwise it is stored in the buffer. + * Furthermore if the record's level is not less than the push level, the + * push action is triggered to output all the buffered records to the target + * handler, and the target handler will publish them. * - * @param record the log record. + * @param record + * the log record */ @Override public synchronized void publish(LogRecord record) { @@ -225,19 +233,22 @@ public class MemoryHandler extends Handler { } /** - * <p>Check if given <code>LogRecord</code> would be put into this - * <code>MemoryHandler</code>'s internal buffer. + * <p> + * Check if given {@code LogRecord} would be put into this + * {@code MemoryHandler}'s internal buffer. * </p> * <p> - * The given <code>LogRecord</code> is loggable if and only if it has - * appropriate level and it pass any associated filter's check. + * The given {@code LogRecord} is loggable if and only if it has appropriate + * level and it pass any associated filter's check. * </p> * <p> - * Note that the push level is not used for this check. + * Note that the push level is not used for this check. * </p> + * * @param record - * the given <code>LogRecord</code> - * @return if the given <code>LogRecord</code> should be logged + * the given {@code LogRecord} + * @return the given {@code LogRecord} if it should be logged, {@code false} + * if {@code LogRecord} is {@code null}. */ @Override public boolean isLoggable(LogRecord record) { @@ -266,15 +277,15 @@ public class MemoryHandler extends Handler { /** * Set the push level. The push level is used to check the push action - * triggering. When a new <code>LogRecord</code> is put into the internal + * triggering. When a new {@code LogRecord} is put into the internal * buffer and its level is not less than the push level, the push action * will be triggered. Note that set new push level won't trigger push action. * * @param newLevel - * the new level to set + * the new level to set. * @throws SecurityException * if security manager exists and it determines that caller - * does not have the required permissions to control this handler + * does not have the required permissions to control this handler. */ public void setPushLevel(Level newLevel) { manager.checkAccess(); diff --git a/logging/src/main/java/java/util/logging/SimpleFormatter.java b/logging/src/main/java/java/util/logging/SimpleFormatter.java index cfccda0..1595796 100644 --- a/logging/src/main/java/java/util/logging/SimpleFormatter.java +++ b/logging/src/main/java/java/util/logging/SimpleFormatter.java @@ -24,19 +24,29 @@ import java.text.MessageFormat; import java.util.Date; /** - * <code>SimpleFormatter</code> can be used to print a summary of the - * information contained in a <code>LogRecord</code> object in a human - * readable format. - * + * {@code SimpleFormatter} can be used to print a summary of the information + * contained in a {@code LogRecord} object in a human readable format. + * @since Android 1.0 */ public class SimpleFormatter extends Formatter { /** - * Constructs a <code>SimpleFormatter</code> object. + * Constructs a new {@code SimpleFormatter}. + * + * @since Android 1.0 */ public SimpleFormatter() { super(); } + /** + * Converts a {@link LogRecord} object into a human readable string + * representation. + * + * @param r + * the log record to be formatted into a string. + * @return the formatted string. + * @since Android 1.0 + */ @Override public String format(LogRecord r) { StringBuilder sb = new StringBuilder(); diff --git a/logging/src/main/java/java/util/logging/SocketHandler.java b/logging/src/main/java/java/util/logging/SocketHandler.java index 3d9ab29..8626007 100644 --- a/logging/src/main/java/java/util/logging/SocketHandler.java +++ b/logging/src/main/java/java/util/logging/SocketHandler.java @@ -31,18 +31,18 @@ import org.apache.harmony.logging.internal.nls.Messages; * initialize itself: * <ul> * <li>java.util.logging.ConsoleHandler.level specifies the logging level, - * defaults to <code>Level.ALL</code> if this property is not found or has an - * invalid value; + * defaults to {@code Level.ALL} if this property is not found or has an invalid + * value. * <li>java.util.logging.SocketHandler.filter specifies the name of the filter - * class to be associated with this handler, defaults to <code>null</code> if - * this property is not found or has an invalid value; + * class to be associated with this handler, defaults to {@code null} if this + * property is not found or has an invalid value. * <li>java.util.logging.SocketHandler.formatter specifies the name of the * formatter class to be associated with this handler, defaults to - * <code>java.util.logging.XMLFormatter</code> if this property is not found - * or has an invalid value; + * {@code java.util.logging.XMLFormatter} if this property is not found or has + * an invalid value. * <li>java.util.logging.SocketHandler.encoding specifies the encoding this - * handler will use to encode log messages, defaults to <code>null</code> if - * this property is not found or has an invalid value. + * handler will use to encode log messages, defaults to {@code null} if this + * property is not found or has an invalid value. * <li>java.util.logging.SocketHandler.host specifies the name of the host that * this handler should connect to. There's no default value for this property. * <li>java.util.logging.SocketHandler.encoding specifies the port number that @@ -56,7 +56,6 @@ import org.apache.harmony.logging.internal.nls.Messages; * <p> * This class is not thread-safe. * </p> - * */ public class SocketHandler extends StreamHandler { // default level @@ -69,15 +68,16 @@ public class SocketHandler extends StreamHandler { private Socket socket; /** - * Constructs a <code>SocketHandler</code> object using the properties - * read by the log manager, including the host name and port number. + * Constructs a {@code SocketHandler} object using the properties read by + * the log manager, including the host name and port number. Default + * formatting uses the XMLFormatter class and level is set to ALL. * * @throws IOException - * If failed to connect to the specified host and port. + * if failed to connect to the specified host and port. * @throws IllegalArgumentException - * If the host name or port number is illegal. + * if the host name or port number is illegal. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission to control this handler. */ public SocketHandler() throws IOException { @@ -89,20 +89,20 @@ public class SocketHandler extends StreamHandler { } /** - * Constructs a <code>SocketHandler</code> object using the specified host - * name and port number together with other properties read by the log - * manager. + * Constructs a {@code SocketHandler} object using the specified host name + * and port number together with other properties read by the log manager. + * Default formatting uses the XMLFormatter class and level is set to ALL. * * @param host * the host name * @param port * the port number * @throws IOException - * If failed to connect to the specified host and port. + * if failed to connect to the specified host and port. * @throws IllegalArgumentException - * If the host name or port number is illegal. + * if the host name or port number is illegal. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission to control this handler. */ public SocketHandler(String host, int port) throws IOException { @@ -170,7 +170,7 @@ public class SocketHandler extends StreamHandler { * Logs a record if necessary. A flush operation will be done afterwards. * * @param record - * the log record to be logged + * the log record to be logged. */ @Override public void publish(LogRecord record) { diff --git a/logging/src/main/java/java/util/logging/StreamHandler.java b/logging/src/main/java/java/util/logging/StreamHandler.java index fb48c2a..ee12190 100644 --- a/logging/src/main/java/java/util/logging/StreamHandler.java +++ b/logging/src/main/java/java/util/logging/StreamHandler.java @@ -26,31 +26,32 @@ import java.io.Writer; import org.apache.harmony.logging.internal.nls.Messages; /** - * A <code>StreamHandler</code> object writes log messages to an output - * stream, that is, objects of the class <code>java.io.OutputStream</code>. + * A {@code StreamHandler} object writes log messages to an output stream, that + * is, objects of the class {@link java.io.OutputStream}. * <p> - * A <code>StreamHandler</code> object reads the following properties from the - * log manager to initialize itself: + * A {@code StreamHandler} object reads the following properties from the log + * manager to initialize itself: * <ul> * <li>java.util.logging.StreamHandler.level specifies the logging level, - * defaults to <code>Level.INFO</code> if this property is not found or has an - * invalid value; + * defaults to {@code Level.INFO} if this property is not found or has an + * invalid value. * <li>java.util.logging.StreamHandler.filter specifies the name of the filter - * class to be associated with this handler, defaults to <code>null</code> if - * this property is not found or has an invalid value; + * class to be associated with this handler, defaults to {@code null} if this + * property is not found or has an invalid value. * <li>java.util.logging.StreamHandler.formatter specifies the name of the * formatter class to be associated with this handler, defaults to - * <code>java.util.logging.SimpleFormatter</code> if this property is not - * found or has an invalid value; + * {@code java.util.logging.SimpleFormatter} if this property is not found or + * has an invalid value. * <li>java.util.logging.StreamHandler.encoding specifies the encoding this - * handler will use to encode log messages, defaults to <code>null</code> if - * this property is not found or has an invalid value. + * handler will use to encode log messages, defaults to {@code null} if this + * property is not found or has an invalid value. * </ul> * </p> * <p> * This class is not thread-safe. * </p> * + * @since Android 1.0 */ public class StreamHandler extends Handler { // the output stream this handler writes to @@ -63,8 +64,10 @@ public class StreamHandler extends Handler { private boolean writerNotInitialized; /** - * Constructs a <code>StreamHandler</code> object. The new stream handler + * Constructs a {@code StreamHandler} object. The new stream handler * does not have an associated output stream. + * + * @since Android 1.0 */ public StreamHandler() { initProperties("INFO", null, "java.util.logging.SimpleFormatter", //$NON-NLS-1$//$NON-NLS-2$ @@ -75,11 +78,11 @@ public class StreamHandler extends Handler { } /** - * Constructs a <code>StreamHandler</code> object with the supplied output + * Constructs a {@code StreamHandler} object with the supplied output * stream. Default properties are read. * * @param os - * the output stream this handler writes to + * the output stream this handler writes to. */ StreamHandler(OutputStream os) { this(); @@ -87,8 +90,8 @@ public class StreamHandler extends Handler { } /** - * Constructs a <code>StreamHandler</code> object. Specified default - * values will be used if the corresponding properties are found in log + * Constructs a {@code StreamHandler} object. The specified default values + * will be used if the corresponding properties are not found in the log * manager's properties. */ StreamHandler(String defaultLevel, String defaultFilter, @@ -101,13 +104,16 @@ public class StreamHandler extends Handler { } /** - * Constructs a <code>StreamHandler</code> object with the supplied output - * stream and formatter. + * Constructs a {@code StreamHandler} object with the supplied output stream + * and formatter. * * @param os - * the output stream this handler writes to + * the output stream this handler writes to. * @param formatter - * the formatter this handler uses to format the output + * the formatter this handler uses to format the output. + * @throws NullPointerException + * if {@code os} or {@code formatter} is {@code null}. + * @since Android 1.0 */ public StreamHandler(OutputStream os, Formatter formatter) { this(); @@ -166,13 +172,16 @@ public class StreamHandler extends Handler { /** * Sets the output stream this handler writes to. If there's an existing * output stream, the tail string of the associated formatter will be - * written to it. Then it will be flushed and closed. + * written to it. Then it will be flushed, closed and replaced with + * {@code os}. * * @param os - * the new output stream + * the new output stream. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @throws NullPointerException + * if {@code os} is {@code null}. */ protected void setOutputStream(OutputStream os) { if (null == os) { @@ -186,16 +195,17 @@ public class StreamHandler extends Handler { } /** - * Sets the character encoding used by this handler. A <code>null</code> - * value indicates the using of the default encoding. + * Sets the character encoding used by this handler. A {@code null} value + * indicates that the default encoding should be used. * * @param encoding - * the character encoding to set + * the character encoding to set. * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. * @throws UnsupportedEncodingException - * If the specified encoding is not supported by the runtime. + * if the specified encoding is not supported by the runtime. + * @since Android 1.0 */ @Override public void setEncoding(String encoding) throws SecurityException, @@ -222,11 +232,11 @@ public class StreamHandler extends Handler { } /** - * Closes this handler, but the underlying output stream is only closed when - * <code>closeStream</code> is <code>true</code>. Security is not checked. + * Closes this handler, but the underlying output stream is only closed if + * {@code closeStream} is {@code true}. Security is not checked. * * @param closeStream - * whether to close the underlying output stream + * whether to close the underlying output stream. */ void close(boolean closeStream) { if (null != this.os) { @@ -251,13 +261,14 @@ public class StreamHandler extends Handler { /** * Closes this handler. The tail string of the formatter associated with - * this handler will be written out. A flush operation a subsequent close - * operation will then be performed upon the outputstream. Client - * applications should not use a handler after closing it. + * this handler is written out. A flush operation and a subsequent close + * operation is then performed upon the output stream. Client applications + * should not use a handler after closing it. * * @throws SecurityException - * If a security manager determines that the caller does not + * if a security manager determines that the caller does not * have the required permission. + * @since Android 1.0 */ @Override public void close() { @@ -267,6 +278,8 @@ public class StreamHandler extends Handler { /** * Flushes any buffered output. + * + * @since Android 1.0 */ @Override public void flush() { @@ -286,21 +299,20 @@ public class StreamHandler extends Handler { } /** - * Accepts an actual logging request. The log record will be formatted and - * written to the output stream if the following three conditions are met: + * Accepts a logging request. The log record is formatted and written to the + * output stream if the following three conditions are met: * <ul> * <li>the supplied log record has at least the required logging level; * <li>the supplied log record passes the filter associated with this - * handler if any; - * <li>the output stream associated with this handler is not - * <code>null</code>. + * handler, if any; + * <li>the output stream associated with this handler is not {@code null}. * </ul> - * If it is the first time a log record need to be written out, the head - * string of the formatter associated with this handler will be written out - * first. + * If it is the first time a log record is written out, the head string of + * the formatter associated with this handler is written out first. * * @param record - * the log record to be logged + * the log record to be logged. + * @since Android 1.0 */ @Override public synchronized void publish(LogRecord record) { @@ -327,14 +339,19 @@ public class StreamHandler extends Handler { } /** - * Determines whether the supplied log record need to be logged. The logging - * levels will be checked as well as the filter. The output stream of this - * handler is also checked. If it's null, this method returns false. + * Determines whether the supplied log record needs to be logged. The + * logging levels are checked as well as the filter. The output stream of + * this handler is also checked. If it is {@code null}, this method returns + * {@code false}. + * <p> + * Notice : Case of no output stream will return {@code false}. + * </p> * * @param record - * the log record to be checked - * @return <code>true</code> if the supplied log record need to be logged, - * otherwise <code>false</code> + * the log record to be checked. + * @return {@code true} if {@code record} needs to be logged, {@code false} + * otherwise. + * @since Android 1.0 */ @Override public boolean isLoggable(LogRecord record) { diff --git a/logging/src/main/java/java/util/logging/XMLFormatter.java b/logging/src/main/java/java/util/logging/XMLFormatter.java index f3ff280..6279d8c 100644 --- a/logging/src/main/java/java/util/logging/XMLFormatter.java +++ b/logging/src/main/java/java/util/logging/XMLFormatter.java @@ -25,12 +25,13 @@ import java.util.Date; import java.util.ResourceBundle; /** - * Format a given <code>LogRecord</code> into string represents XML. The DTD specified in - * Appendix A to Java Logging APIs specification is used. - * - * <code>XMLFormatter</code> uses given <code>Handler</code>'s encoding if has, otherwise - * uses default platform encoding instead. However, the UTF-8 is recommended encoding. + * Formatter to convert a {@link LogRecord} into an XML string. The DTD + * specified in Appendix A to the Java Logging APIs specification is used. + * {@code XMLFormatter} uses the output handler's encoding if it is specified, + * otherwise the default platform encoding is used instead. UTF-8 is the + * recommended encoding. * + * @since Android 1.0 */ public class XMLFormatter extends Formatter { @@ -40,17 +41,21 @@ public class XMLFormatter extends Formatter { private static final String indent = " "; //$NON-NLS-1$ /** - * Default constructor + * Constructs a new {@code XMLFormatter}. + * + * @since Android 1.0 */ public XMLFormatter() { super(); } /** - * Format a <code>LogRecord</code> into string which represents XML + * Converts a {@code LogRecord} into an XML string. * - * @param r the given LogRecord instance to be formatted - * @return string which represents XML + * @param r + * the log record to be formatted. + * @return the log record formatted as an XML string. + * @since Android 1.0 */ @Override public String format(LogRecord r) { @@ -160,11 +165,14 @@ public class XMLFormatter extends Formatter { } /** - * Return the header string for XML, use given handler's encoding if has, - * other wise use default platform encoding + * Returns the header string for a set of log records formatted as XML + * strings, using the output handler's encoding if it is defined, otherwise + * using the default platform encoding. * - * @param h the given handler - * @return the header string for XML + * @param h + * the output handler, may be {@code null}. + * @return the header string for log records formatted as XML strings. + * @since Android 1.0 */ @Override public String getHead(Handler h) { @@ -184,10 +192,13 @@ public class XMLFormatter extends Formatter { } /** - * Return the tail string for XML + * Returns the tail string for a set of log records formatted as XML + * strings. * - * @param h the given handler - * @return the tail string for XML + * @param h + * the output handler, may be {@code null}. + * @return the tail string for log records formatted as XML strings. + * @since Android 1.0 */ @Override @SuppressWarnings("unused") diff --git a/logging/src/main/java/java/util/logging/package.html b/logging/src/main/java/java/util/logging/package.html index 4cc90c9..c523c7a 100644 --- a/logging/src/main/java/java/util/logging/package.html +++ b/logging/src/main/java/java/util/logging/package.html @@ -3,7 +3,8 @@ <p> This package allows to add logging to any application. It supports different levels of importance of a message that needs to be - logged. Later the output can be filtered by this level. + logged. The output written to the target can be filtered by this level. </p> + @since Android 1.0 </body> </html> diff --git a/logging/src/main/java/org/apache/harmony/logging/internal/nls/Messages.java b/logging/src/main/java/org/apache/harmony/logging/internal/nls/Messages.java index e052773..87535ae 100644 --- a/logging/src/main/java/org/apache/harmony/logging/internal/nls/Messages.java +++ b/logging/src/main/java/org/apache/harmony/logging/internal/nls/Messages.java @@ -21,6 +21,10 @@ * if this tool runs again. Better make changes in the template file. */ +// BEGIN android-note +// Redundant code has been removed and is now called from MsgHelp. +// END android-note + package org.apache.harmony.logging.internal.nls; @@ -30,8 +34,9 @@ import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; -import org.apache.harmony.kernel.vm.VM; +// BEGIN android-changed import org.apache.harmony.luni.util.MsgHelp; +// END android-changed /** * This class retrieves strings from a resource bundle and returns them, @@ -48,9 +53,11 @@ import org.apache.harmony.luni.util.MsgHelp; * */ public class Messages { - + + // BEGIN android-changed private static final String sResource = "org.apache.harmony.logging.internal.nls.messages"; //$NON-NLS-1$ + // END android-changed /** * Retrieves a message which has no arguments. @@ -60,7 +67,9 @@ public class Messages { * @return String the message for that key in the system message bundle. */ static public String getString(String msg) { + // BEGIN android-changed return MsgHelp.getString(sResource, msg); + // END android-changed } /** @@ -127,6 +136,12 @@ public class Messages { * @return String the message for that key in the system message bundle. */ static public String getString(String msg, Object[] args) { + // BEGIN android-changed return MsgHelp.getString(sResource, msg, args); + // END android-changed } + + // BEGIN android-note + // Duplicate code was dropped in favor of using MsgHelp. + // END android-note } diff --git a/logging/src/test/java/java/util/logging/LoggerExtension.java b/logging/src/test/java/java/util/logging/LoggerExtension.java deleted file mode 100644 index c31984b..0000000 --- a/logging/src/test/java/java/util/logging/LoggerExtension.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package java.util.logging; - -import java.util.ResourceBundle; - -/** - * Example of a type injected into logging to access package private members. - */ -public class LoggerExtension { - - public static ResourceBundle loadResourceBundle(String resourceBundleName) { - return Logger.loadResourceBundle(resourceBundleName); - } - -} diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/AllTests.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/AllTests.java index ee4a932..8c8baa1 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/AllTests.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/AllTests.java @@ -32,10 +32,11 @@ public class AllTests { suite.addTestSuite(ErrorManagerTest.class); suite.addTestSuite(FileHandlerTest.class); suite.addTestSuite(FilterTest.class); - suite.addTestSuite(FormatterTest.class); +// suite.addTestSuite(FormatterTest.class); suite.addTestSuite(HandlerTest.class); suite.addTestSuite(LevelTest.class); suite.addTestSuite(LoggerTest.class); + suite.addTestSuite(LoggingMXBeanTest.class); suite.addTestSuite(LoggingPermissionTest.class); suite.addTestSuite(LogManagerTest.class); suite.addTestSuite(LogRecordTest.class); @@ -44,6 +45,7 @@ public class AllTests { suite.addTestSuite(SocketHandlerTest.class); suite.addTestSuite(StreamHandlerTest.class); suite.addTestSuite(XMLFormatterTest.class); + suite.addTestSuite(MessagesTest.class); // $JUnit-END$ return suite; } diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ConsoleHandlerTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ConsoleHandlerTest.java index bb9717d..188a138 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ConsoleHandlerTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ConsoleHandlerTest.java @@ -17,11 +17,17 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestInfo; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.security.Permission; +import java.util.Currency; import java.util.Properties; import java.util.logging.ConsoleHandler; import java.util.logging.Filter; @@ -42,6 +48,7 @@ import tests.util.CallVerificationStack; /** * Test class java.util.logging.ConsoleHandler */ +@TestTargetClass(ConsoleHandler.class) public class ConsoleHandlerTest extends TestCase { private final static String INVALID_LEVEL = "impossible_level"; @@ -75,6 +82,16 @@ public class ConsoleHandlerTest extends TestCase { /* * Test the constructor with no relevant log manager properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with no relevant log manager " + + "properties are set.", + targets = { + @TestTarget( + methodName = "ConsoleHandler", + methodArgs = {} + ) + }) public void testConstructor_NoProperties() { assertNull(LogManager.getLogManager().getProperty( "java.util.logging.ConsoleHandler.level")); @@ -95,6 +112,15 @@ public class ConsoleHandlerTest extends TestCase { /* * Test the constructor with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with insufficient privilege.", + targets = { + @TestTarget( + methodName = "ConsoleHandler", + methodArgs = {} + ) + }) public void testConstructor_InsufficientPrivilege() { assertNull(LogManager.getLogManager().getProperty( "java.util.logging.ConsoleHandler.level")); @@ -122,6 +148,16 @@ public class ConsoleHandlerTest extends TestCase { /* * Test the constructor with valid relevant log manager properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with valid relevant log manager " + + "properties are set.", + targets = { + @TestTarget( + methodName = "ConsoleHandler", + methodArgs = {} + ) + }) public void testConstructor_ValidProperties() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.level", "FINE"); @@ -148,6 +184,16 @@ public class ConsoleHandlerTest extends TestCase { * Test the constructor with invalid relevant log manager properties are * set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with invalid relevant " + + "log manager properties are set.", + targets = { + @TestTarget( + methodName = "ConsoleHandler", + methodArgs = {} + ) + }) public void testConstructor_InvalidProperties() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.level", INVALID_LEVEL); @@ -174,6 +220,16 @@ public class ConsoleHandlerTest extends TestCase { * Test close() when having sufficient privilege, and a record has been * written to the output stream. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies close() when having sufficient privilege, " + + "and a record has been written to the output stream.", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) public void testClose_SufficientPrivilege_NormalClose() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.formatter", className @@ -194,6 +250,16 @@ public class ConsoleHandlerTest extends TestCase { * Test close() when having sufficient privilege, and an output stream that * always throws exceptions. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies close() when having sufficient privilege, " + + "and an output stream that always throws exceptions", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) public void testClose_SufficientPrivilege_Exception() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.formatter", className @@ -212,6 +278,16 @@ public class ConsoleHandlerTest extends TestCase { * Test close() when having sufficient privilege, and no record has been * written to the output stream. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks close() when having sufficient privilege, and no record " + + "has been written to the output stream", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) public void testClose_SufficientPrivilege_DirectClose() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.formatter", className @@ -230,6 +306,15 @@ public class ConsoleHandlerTest extends TestCase { /* * Test close() when having insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies close() when insufficient privilege is set up.", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) public void testClose_InsufficientPrivilege() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.formatter", className @@ -249,6 +334,16 @@ public class ConsoleHandlerTest extends TestCase { /* * Test publish(), use no filter, having output stream, normal log record. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), use no filter, having output stream, " + + "normal log record.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_NoFilter() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.formatter", className @@ -287,6 +382,15 @@ public class ConsoleHandlerTest extends TestCase { /* * Test publish(), after system err is reset. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), after system err is reset.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_AfterResetSystemErr() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.formatter", className @@ -309,6 +413,16 @@ public class ConsoleHandlerTest extends TestCase { /* * Test publish(), use a filter, having output stream, normal log record. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), use a filter, having output stream, " + + "normal log record.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_WithFilter() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.formatter", className @@ -350,6 +464,17 @@ public class ConsoleHandlerTest extends TestCase { * rather than throw exception, handler should call errormanager to handle * exception case, so NullPointerException shouldn't be thrown. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), null log record, having output stream, spec said " + + "rather than throw exception, handler should call errormanager to handle " + + "exception case, so NullPointerException shouldn't be thrown.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_Null() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.formatter", className @@ -363,6 +488,16 @@ public class ConsoleHandlerTest extends TestCase { /* * Test publish(), a log record with empty msg, having output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), a log record with empty msg, " + + "having output stream.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_EmptyMsg() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.formatter", className @@ -379,6 +514,15 @@ public class ConsoleHandlerTest extends TestCase { /* * Test publish(), a log record with null msg, having output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), a log record with null msg, having output stream.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_NullMsg() throws Exception { Properties p = new Properties(); p.put("java.util.logging.ConsoleHandler.formatter", className @@ -392,7 +536,15 @@ public class ConsoleHandlerTest extends TestCase { // assertEquals("MockFormatter_Head", // this.errSubstituteStream.toString()); } - + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish method after close.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_AfterClose() throws Exception { PrintStream backup = System.err; try { @@ -429,6 +581,15 @@ public class ConsoleHandlerTest extends TestCase { /* * Test setOutputStream() under normal condition. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies setOutputStream() under normal condition.", + targets = { + @TestTarget( + methodName = "setOutputStream", + methodArgs = {java.io.OutputStream.class} + ) + }) public void testSetOutputStream_Normal() { MockStreamHandler h = new MockStreamHandler(); h.setFormatter(new MockFormatter()); diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ErrorManagerTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ErrorManagerTest.java index dec61fb..d2f2723 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ErrorManagerTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/ErrorManagerTest.java @@ -17,14 +17,21 @@ package org.apache.harmony.logging.tests.java.util.logging; -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.logging.ErrorManager; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; import org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream; -import junit.framework.TestCase; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.logging.ErrorManager; +@TestTargetClass(ErrorManager.class) public class ErrorManagerTest extends TestCase { @@ -42,14 +49,50 @@ public class ErrorManagerTest extends TestCase { System.setErr(err); super.tearDown(); } + + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case only with ErrorManager.GENERIC_FAILURE, impove MockStream", + targets = { + @TestTarget( + methodName = "error", + methodArgs = {java.lang.String.class, java.lang.Exception.class, int.class} + ) + }) + public void test_errorCheck() { + ErrorManager em = new ErrorManager(); + MockStream aos = new MockStream(); + PrintStream st = new PrintStream(aos); + System.setErr(st); + System.setOut(st); + em.error("supertest", null, ErrorManager.GENERIC_FAILURE); + st.flush(); + assertTrue("message appears (supertest)", aos.getWrittenData().indexOf("supertest") != -1); + } + + @TestInfo(level = TestLevel.PARTIAL_OK, + purpose = "Verifies positive case only with ErrorManager.GENERIC_FAILURE", + targets = {@TestTarget(methodName = "error", + methodArgs = { java.lang.String.class, java.lang.Exception.class, int.class})}) public void test_errorStringStringint() { ErrorManager em = new ErrorManager(); - em.error(null, new NullPointerException(), ErrorManager.GENERIC_FAILURE); + em.error(null, new NullPointerException(), + ErrorManager.GENERIC_FAILURE); em.error("An error message.", null, ErrorManager.GENERIC_FAILURE); em.error(null, null, ErrorManager.GENERIC_FAILURE); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "ErrorManager", + methodArgs = {} + ) + }) public void test_constants() { assertEquals(3, ErrorManager.CLOSE_FAILURE); assertEquals(2, ErrorManager.FLUSH_FAILURE); @@ -58,5 +101,27 @@ public class ErrorManagerTest extends TestCase { assertEquals(4, ErrorManager.OPEN_FAILURE); assertEquals(1, ErrorManager.WRITE_FAILURE); } + + public class MockStream extends ByteArrayOutputStream { + + private StringBuffer linesWritten = new StringBuffer(); + + public void flush() {} + public void close() {} + + @Override + public void write(byte[] buffer) { + linesWritten.append(new String(buffer)); + } + + @Override + public synchronized void write(byte[] buffer, int offset, int len) { + linesWritten.append(new String(buffer, offset, len)); + } + + public String getWrittenData() {return linesWritten.toString();} + + } + } diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java index 745c560..445bd96 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java @@ -17,6 +17,11 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; @@ -47,6 +52,7 @@ import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper /** */ +@TestTargetClass(FileHandler.class) public class FileHandlerTest extends TestCase { static LogManager manager = LogManager.getLogManager(); @@ -79,21 +85,8 @@ public class FileHandlerTest extends TestCase { protected void setUp() throws Exception { super.setUp(); manager.reset(); - initProps(); - File file = new File(TEMPPATH + SEP + "log"); - file.mkdir(); - manager.readConfiguration(EnvironmentHelper - .PropertiesToInputStream(props)); - handler = new FileHandler(); - r = new LogRecord(Level.CONFIG, "msg"); - errSubstituteStream = new NullOutputStream(); - System.setErr(new PrintStream(errSubstituteStream)); - } - - /** - * - */ - private void initProps() { + + //initProp props.clear(); props.put("java.util.logging.FileHandler.level", "FINE"); props.put("java.util.logging.FileHandler.filter", className @@ -107,14 +100,25 @@ public class FileHandlerTest extends TestCase { props.put("java.util.logging.FileHandler.count", "2"); // using append mode props.put("java.util.logging.FileHandler.append", "true"); - props - .put("java.util.logging.FileHandler.pattern", + props.put("java.util.logging.FileHandler.pattern", "%t/log/java%u.test"); + + + File file = new File(TEMPPATH + SEP + "log"); + file.mkdir(); + manager.readConfiguration(EnvironmentHelper + .PropertiesToInputStream(props)); + handler = new FileHandler(); + r = new LogRecord(Level.CONFIG, "msg"); + errSubstituteStream = new NullOutputStream(); + System.setErr(new PrintStream(errSubstituteStream)); } + /* * @see TestCase#tearDown() */ + protected void tearDown() throws Exception { if (null != handler) { handler.close(); @@ -123,21 +127,37 @@ public class FileHandlerTest extends TestCase { System.setErr(err); super.tearDown(); } - - public void testLock() throws Exception { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies getFormatter() method after close.", + targets = { + @TestTarget( + methodName = "getFormatter", + methodArgs = {} + ) + }) + public void _testLock() throws Exception { FileOutputStream output = new FileOutputStream(TEMPPATH + SEP + "log" - + SEP + "java1.test.0"); + + SEP + "java1.test.Lock"); FileHandler h = new FileHandler(); h.publish(r); h.close(); - assertFileContent(TEMPPATH + SEP + "log", "java1.test.0", h - .getFormatter()); + assertFileContent(TEMPPATH + SEP + "log", "java1.test.Lock", h.getFormatter()); output.close(); } /* * test for constructor void FileHandler() */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {} + ) + }) public void testFileHandler() throws Exception { assertEquals("character encoding is non equal to actual value", "iso-8859-1", handler.getEncoding()); @@ -163,6 +183,15 @@ public class FileHandlerTest extends TestCase { /* * test for constructor void FileHandler(String) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class} + ) + }) public void testFileHandler_1params() throws Exception { handler = new FileHandler("%t/log/string"); @@ -239,6 +268,15 @@ public class FileHandlerTest extends TestCase { /* * test for constructor void FileHandler(String pattern, boolean append) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, boolean.class} + ) + }) public void testFileHandler_2params() throws Exception { boolean append = false; do { @@ -275,6 +313,15 @@ public class FileHandlerTest extends TestCase { * test for constructor void FileHandler(String pattern, int limit, int * count) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, int.class, int.class} + ) + }) public void testFileHandler_3params() throws Exception { int limit = 120; int count = 1; @@ -303,6 +350,15 @@ public class FileHandlerTest extends TestCase { * test for constructor public FileHandler(String pattern, int limit, int * count, boolean append) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, int.class, int.class, boolean.class} + ) + }) public void testFileHandler_4params() throws Exception { int limit = 120; int count = 1; @@ -336,7 +392,31 @@ public class FileHandlerTest extends TestCase { } } while (append); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "getEncoding", + methodArgs = {} + ), + @TestTarget( + methodName = "getFilter", + methodArgs = {} + ), + @TestTarget( + methodName = "getFormatter", + methodArgs = {} + ), + @TestTarget( + methodName = "getLevel", + methodArgs = {} + ), + @TestTarget( + methodName = "getErrorManager", + methodArgs = {} + ) + }) public void testDefaultValue() throws Exception { handler.publish(r); handler.close(); @@ -441,7 +521,15 @@ public class FileHandlerTest extends TestCase { e.printStackTrace(); } } - + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, int.class, int.class, boolean.class} + ) + }) public void testLimitAndCount() throws Exception { handler.close(); // very small limit value, count=2 @@ -524,7 +612,31 @@ public class FileHandlerTest extends TestCase { reset("log", ""); } } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, boolean.class} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, int.class, int.class} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, int.class, int.class, boolean.class} + ) + }) public void testSecurity() throws IOException { SecurityManager currentManager = System.getSecurityManager(); @@ -568,7 +680,35 @@ public class FileHandlerTest extends TestCase { } } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies SecurityException.", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, boolean.class} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, int.class, int.class} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, int.class, int.class, boolean.class} + ) + }) public void testFileSecurity() throws IOException { SecurityManager currentManager = System.getSecurityManager(); @@ -611,7 +751,15 @@ public class FileHandlerTest extends TestCase { System.setSecurityManager(currentManager); } } - + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies FileHandler when configuration file is invalid.", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {} + ) + }) public void testInvalidProperty() throws Exception { props.put("java.util.logging.FileHandler.level", "null"); props.put("java.util.logging.FileHandler.filter", className @@ -646,8 +794,29 @@ public class FileHandlerTest extends TestCase { } catch (NullPointerException e) { } } - - public void testInvalidParams() throws IOException { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies illegal parameters and exceptions: " + + "IOException, NullPointerException, IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, boolean.class} + ), + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, int.class, int.class} + ), + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) + public void _testInvalidParams() throws IOException { // %t and %p parsing can add file separator automatically FileHandler h1 = new FileHandler("%taaa"); @@ -695,6 +864,39 @@ public class FileHandlerTest extends TestCase { } file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0"); assertFalse(file.exists()); + + // bad directory, IOException, append + try { + h1 = new FileHandler("%t/baddir/multi%g", true); + fail("should throw IO exception"); + } catch (IOException e) { + } + file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0"); + assertFalse(file.exists()); + try { + h1 = new FileHandler("%t/baddir/multi%g", false); + fail("should throw IO exception"); + } catch (IOException e) { + } + file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0"); + assertFalse(file.exists()); + + try { + h1 = new FileHandler("%t/baddir/multi%g", 12, 4); + fail("should throw IO exception"); + } catch (IOException e) { + } + file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0"); + assertFalse(file.exists()); + + try { + h1 = new FileHandler("%t/baddir/multi%g", 12, 4, true); + fail("should throw IO exception"); + } catch (IOException e) { + } + file = new File(TEMPPATH + SEP + "baddir" + SEP + "multi0"); + assertFalse(file.exists()); + try { new FileHandler(null); @@ -712,7 +914,6 @@ public class FileHandlerTest extends TestCase { } catch (NullPointerException e) { } try { - // regression test for Harmony-1299 new FileHandler(""); fail("should throw IllegalArgumentException"); } catch (IllegalArgumentException e) { @@ -728,11 +929,26 @@ public class FileHandlerTest extends TestCase { fail("should throw IllegalArgumentException"); } catch (IllegalArgumentException e) { } + + try { + new FileHandler("%t/java%u", -1, -1); + fail("should throw IllegalArgumentException"); + } catch (IllegalArgumentException e) { + } } /* * test for method public void publish(LogRecord record) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish() throws Exception { LogRecord[] r = new LogRecord[] { new LogRecord(Level.CONFIG, "msg__"), new LogRecord(Level.WARNING, "message"), @@ -750,6 +966,15 @@ public class FileHandlerTest extends TestCase { /* * test for method public void close() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) public void testClose() throws Exception { FileHandler h = new FileHandler("%t/log/stringPublish"); h.publish(r); @@ -757,7 +982,15 @@ public class FileHandlerTest extends TestCase { assertFileContent(TEMPPATH + SEP + "log", "stringPublish", h .getFormatter()); } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify SecurityException.", + targets = { + @TestTarget( + methodName = "setOutputStream", + methodArgs = {java.io.OutputStream.class} + ) + }) // set output stream still works, just like super StreamHandler public void testSetOutputStream() throws Exception { MockFileHandler handler = new MockFileHandler("%h/setoutput.log"); @@ -773,10 +1006,18 @@ public class FileHandlerTest extends TestCase { assertEquals(msg, f.getHead(handler) + f.format(r) + f.getTail(handler)); assertFileContent(HOMEPATH, "setoutput.log", handler.getFormatter()); } - + + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, int.class, int.class} + ) + }) public void testEmptyPattern_3params() throws SecurityException, IOException { - // regression HARMONY-2421 try { new FileHandler(new String(), 1, 1); fail("Expected an IllegalArgumentException"); @@ -784,10 +1025,17 @@ public class FileHandlerTest extends TestCase { // Expected } } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, boolean.class} + ) + }) public void testEmptyPattern_2params() throws SecurityException, IOException { - // regression HARMONY-2421 try { new FileHandler(new String(), true); fail("Expected an IllegalArgumentException"); @@ -795,10 +1043,17 @@ public class FileHandlerTest extends TestCase { // Expected } } - + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "FileHandler", + methodArgs = {java.lang.String.class, int.class, int.class, boolean.class} + ) + }) public void testEmptyPattern_4params() throws SecurityException, IOException { - // regression HARMONY-2421 try { new FileHandler(new String(), 1, 1, true); fail("Expected an IllegalArgumentException"); diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FilterTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FilterTest.java index 710d757..3c82d70 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FilterTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FilterTest.java @@ -15,8 +15,26 @@ * limitations under the License. */ +//TODO : +/* + * 1. Don't forget to write tests for org.apache.harmony.logging.internal.nls/Messages.java this file is in logging/src/main/java folder + * 2. inrteface filter / LoggingMXBean tests machen + * 3. XMLFormatter.java should be finish for Monday (not a lot to do) but as I beginn want to finish. + * 3. In my case + * I didn't use the PARTIAL_OK, so I believe that 98% of COMPLETE are PARTIAL_OK + * COMPLETE = Tests finish and should be working. If error check the test before to make a ticket. + * PARTIAL = Tests finish, but need special reviewing + * TODO = A test to do (or not). Mostly a test to complete + * 4. For questions christian.wiederseiner + */ + package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; + import java.util.logging.Filter; import java.util.logging.LogRecord; @@ -26,10 +44,20 @@ import junit.framework.TestCase; * This testcase verifies the signature of the interface Filter. * */ +@TestTargetClass(Filter.class) public class FilterTest extends TestCase { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies interface.", + targets = { + @TestTarget( + methodName = "isLoggable", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testFilter() { MockFilter f = new MockFilter(); - f.isLoggable(null); + assertFalse(f.isLoggable(null)); } /* diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FormatterTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FormatterTest.java index 0012035..d8b6def 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FormatterTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FormatterTest.java @@ -17,6 +17,11 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.text.MessageFormat; import java.util.Locale; import java.util.ResourceBundle; @@ -27,6 +32,7 @@ import java.util.logging.LogRecord; import junit.framework.TestCase; +@TestTargetClass(Formatter.class) public class FormatterTest extends TestCase { Formatter f; @@ -44,26 +50,67 @@ public class FormatterTest extends TestCase { f = new MockFormatter(); r = new LogRecord(Level.FINE, MSG); h = new FileHandler(); + } /* * test for constructor protected Formatter() */ - public void testFormatter() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Formatter", + methodArgs = {} + ) + }) + public void _testFormatter() { Formatter formatter; formatter = new MockFormatter(); assertEquals("head string is not empty", "", formatter.getHead(null)); assertEquals("tail string is not empty", "", formatter.getTail(null)); + } - - public void testFormat() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Abstract method.", + targets = { + @TestTarget( + methodName = "format", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) + public void _testFormat() { assertEquals("format", f.format(r)); } + + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "format", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) + public void _testFormatNull() { + assertEquals("format",f.format(null)); + } /* * test for method public String getHead(Handler h) */ - public void testGetHead() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getHead", + methodArgs = {java.util.logging.Handler.class} + ) + }) + public void _testGetHead() { assertEquals("head string is not empty", "", f.getHead(null)); assertEquals("head string is not empty", "", f.getHead(h)); h.publish(r); @@ -73,14 +120,31 @@ public class FormatterTest extends TestCase { /* * test for method public String getTail(Handler h) */ - public void testGetTail() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getTail", + methodArgs = {java.util.logging.Handler.class} + ) + }) + public void _testGetTail() { assertEquals("tail string is not empty", "", f.getTail(null)); assertEquals("tail string is not empty", "", f.getTail(h)); h.publish(r); assertEquals("tail string is not empty", "", f.getTail(h)); } - - public void testFormatMessage() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "formatMessage", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) + public void _testFormatMessage() { assertEquals(MSG, f.formatMessage(r)); String pattern = "test formatter {0, number}"; @@ -109,9 +173,21 @@ public class FormatterTest extends TestCase { pattern = null; r.setMessage(pattern); assertNull(f.formatMessage(r)); + + + assertNull(f.formatMessage(null)); + } - - public void testLocalizedFormatMessage() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "formatMessage", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) + public void _testLocalizedFormatMessage() { // normal case r.setMessage("msg"); ResourceBundle rb = ResourceBundle diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/HandlerTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/HandlerTest.java index 9edfb83..d3edc45 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/HandlerTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/HandlerTest.java @@ -17,10 +17,16 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.security.Permission; +import java.util.EmptyStackException; import java.util.Properties; import java.util.logging.ErrorManager; import java.util.logging.Filter; @@ -40,6 +46,7 @@ import tests.util.CallVerificationStack; * Test suite for the class java.util.logging.Handler. * */ +@TestTargetClass(Handler.class) public class HandlerTest extends TestCase { private static String className = HandlerTest.class.getName(); @@ -70,6 +77,15 @@ public class HandlerTest extends TestCase { /* * Test the constructor. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Handler", + methodArgs = {} + ) + }) public void testConstructor() { MockHandler h = new MockHandler(); assertSame(h.getLevel(), Level.ALL); @@ -82,12 +98,20 @@ public class HandlerTest extends TestCase { /* * Test the constructor, with properties set */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "Handler", + methodArgs = {} + ) + }) public void testConstructor_Properties() throws Exception { Properties p = new Properties(); p.put("java.util.logging.MockHandler.level", "FINE"); - p - .put("java.util.logging.MockHandler.filter", className - + "$MockFilter"); + p.put("java.util.logging.MockHandler.filter", className + + "$MockFilter"); p.put("java.util.logging.Handler.formatter", className + "$MockFormatter"); p.put("java.util.logging.MockHandler.encoding", "utf-8"); @@ -95,9 +119,9 @@ public class HandlerTest extends TestCase { EnvironmentHelper.PropertiesToInputStream(p)); assertEquals(LogManager.getLogManager().getProperty( - "java.util.logging.MockHandler.level"), "FINE"); + "java.util.logging.MockHandler.level"), "FINE"); assertEquals(LogManager.getLogManager().getProperty( - "java.util.logging.MockHandler.encoding"), "utf-8"); + "java.util.logging.MockHandler.encoding"), "utf-8"); MockHandler h = new MockHandler(); assertSame(h.getLevel(), Level.ALL); assertNull(h.getFormatter()); @@ -110,6 +134,15 @@ public class HandlerTest extends TestCase { /* * Abstract method, no test needed. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Abstract method.", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) public void testClose() { MockHandler h = new MockHandler(); h.close(); @@ -118,6 +151,15 @@ public class HandlerTest extends TestCase { /* * Abstract method, no test needed. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Abstract method.", + targets = { + @TestTarget( + methodName = "flush", + methodArgs = {} + ) + }) public void testFlush() { MockHandler h = new MockHandler(); h.flush(); @@ -126,6 +168,15 @@ public class HandlerTest extends TestCase { /* * Abstract method, no test needed. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Abstract method.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish() { MockHandler h = new MockHandler(); h.publish(null); @@ -134,6 +185,19 @@ public class HandlerTest extends TestCase { /* * Test getEncoding & setEncoding methods with supported encoding. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify exceptions.", + targets = { + @TestTarget( + methodName = "getEncoding", + methodArgs = {} + ), + @TestTarget( + methodName = "setEncoding", + methodArgs = {java.lang.String.class} + ) + }) public void testGetSetEncoding_Normal() throws Exception { MockHandler h = new MockHandler(); h.setEncoding("iso-8859-1"); @@ -143,6 +207,15 @@ public class HandlerTest extends TestCase { /* * Test getEncoding & setEncoding methods with null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "getEncoding", + methodArgs = {} + ) + }) public void testGetSetEncoding_Null() throws Exception { MockHandler h = new MockHandler(); h.setEncoding(null); @@ -152,6 +225,15 @@ public class HandlerTest extends TestCase { /* * Test getEncoding & setEncoding methods with unsupported encoding. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies UnsupportedEncodingException.", + targets = { + @TestTarget( + methodName = "setEncoding", + methodArgs = {java.lang.String.class} + ) + }) public void testGetSetEncoding_Unsupported() { MockHandler h = new MockHandler(); try { @@ -165,6 +247,15 @@ public class HandlerTest extends TestCase { /* * Test setEncoding with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify UnsupportedEncodingException.", + targets = { + @TestTarget( + methodName = "setEncoding", + methodArgs = {java.lang.String.class} + ) + }) public void testSetEncoding_InsufficientPrivilege() throws Exception { MockHandler h = new MockHandler(); SecurityManager oldMan = System.getSecurityManager(); @@ -194,6 +285,19 @@ public class HandlerTest extends TestCase { /* * Test getErrorManager & setErrorManager methods with non-null value. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "setErrorManager", + methodArgs = {java.util.logging.ErrorManager.class} + ), + @TestTarget( + methodName = "getErrorManager", + methodArgs = {} + ) + }) public void testGetSetErrorManager_Normal() throws Exception { MockHandler h = new MockHandler(); ErrorManager man = new ErrorManager(); @@ -204,6 +308,19 @@ public class HandlerTest extends TestCase { /* * Test getErrorManager & setErrorManager methods with null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "getErrorManager", + methodArgs = {} + ), + @TestTarget( + methodName = "setErrorManager", + methodArgs = {java.util.logging.ErrorManager.class} + ) + }) public void testGetSetErrorManager_Null() throws Exception { MockHandler h = new MockHandler(); // test set null @@ -225,6 +342,15 @@ public class HandlerTest extends TestCase { /* * Test getErrorManager with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies SecurityException.", + targets = { + @TestTarget( + methodName = "getErrorManager", + methodArgs = {} + ) + }) public void testGetErrorManager_InsufficientPrivilege() throws Exception { MockHandler h = new MockHandler(); SecurityManager oldMan = System.getSecurityManager(); @@ -242,6 +368,15 @@ public class HandlerTest extends TestCase { /* * Test setErrorManager with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies setErrorManager with insufficient privilege.", + targets = { + @TestTarget( + methodName = "setErrorManager", + methodArgs = {java.util.logging.ErrorManager.class} + ) + }) public void testSetErrorManager_InsufficientPrivilege() throws Exception { MockHandler h = new MockHandler(); SecurityManager oldMan = System.getSecurityManager(); @@ -271,6 +406,19 @@ public class HandlerTest extends TestCase { /* * Test getFilter & setFilter methods with non-null value. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify SecurityException.", + targets = { + @TestTarget( + methodName = "setFilter", + methodArgs = {java.util.logging.Filter.class} + ), + @TestTarget( + methodName = "getFilter", + methodArgs = {} + ) + }) public void testGetSetFilter_Normal() throws Exception { MockHandler h = new MockHandler(); Filter f = new MockFilter(); @@ -281,6 +429,19 @@ public class HandlerTest extends TestCase { /* * Test getFilter & setFilter methods with null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "getFilter", + methodArgs = {} + ), + @TestTarget( + methodName = "setFilter", + methodArgs = {java.util.logging.Filter.class} + ) + }) public void testGetSetFilter_Null() throws Exception { MockHandler h = new MockHandler(); // test set null @@ -294,6 +455,15 @@ public class HandlerTest extends TestCase { /* * Test setFilter with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies SecurityException.", + targets = { + @TestTarget( + methodName = "setFilter", + methodArgs = {java.util.logging.Filter.class} + ) + }) public void testSetFilter_InsufficientPrivilege() throws Exception { MockHandler h = new MockHandler(); SecurityManager oldMan = System.getSecurityManager(); @@ -323,6 +493,19 @@ public class HandlerTest extends TestCase { /* * Test getFormatter & setFormatter methods with non-null value. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify SecurityException.", + targets = { + @TestTarget( + methodName = "getFormatter", + methodArgs = {} + ), + @TestTarget( + methodName = "setFormatter", + methodArgs = {java.util.logging.Formatter.class} + ) + }) public void testGetSetFormatter_Normal() throws Exception { MockHandler h = new MockHandler(); Formatter f = new SimpleFormatter(); @@ -333,6 +516,19 @@ public class HandlerTest extends TestCase { /* * Test getFormatter & setFormatter methods with null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "getFormatter", + methodArgs = {} + ), + @TestTarget( + methodName = "setFormatter", + methodArgs = {java.util.logging.Formatter.class} + ) + }) public void testGetSetFormatter_Null() throws Exception { MockHandler h = new MockHandler(); // test set null @@ -354,6 +550,15 @@ public class HandlerTest extends TestCase { /* * Test setFormatter with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies SecurityException.", + targets = { + @TestTarget( + methodName = "getFormatter", + methodArgs = {} + ) + }) public void testSetFormatter_InsufficientPrivilege() throws Exception { MockHandler h = new MockHandler(); SecurityManager oldMan = System.getSecurityManager(); @@ -383,6 +588,19 @@ public class HandlerTest extends TestCase { /* * Test getLevel & setLevel methods with non-null value. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify SecurityException.", + targets = { + @TestTarget( + methodName = "getLevel", + methodArgs = {} + ), + @TestTarget( + methodName = "setLevel", + methodArgs = {java.util.logging.Level.class} + ) + }) public void testGetSetLevel_Normal() throws Exception { MockHandler h = new MockHandler(); Level f = Level.CONFIG; @@ -393,6 +611,19 @@ public class HandlerTest extends TestCase { /* * Test getLevel & setLevel methods with null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLevel & setLevel methods with null.", + targets = { + @TestTarget( + methodName = "getLevel", + methodArgs = {} + ), + @TestTarget( + methodName = "setLevel", + methodArgs = {java.util.logging.Level.class} + ) + }) public void testGetSetLevel_Null() throws Exception { MockHandler h = new MockHandler(); // test set null @@ -414,6 +645,15 @@ public class HandlerTest extends TestCase { /* * Test setLevel with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException, SecurityException.", + targets = { + @TestTarget( + methodName = "setLevel", + methodArgs = {java.util.logging.Level.class} + ) + }) public void testSetLevel_InsufficientPrivilege() throws Exception { MockHandler h = new MockHandler(); SecurityManager oldMan = System.getSecurityManager(); @@ -443,6 +683,15 @@ public class HandlerTest extends TestCase { /* * Use no filter */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "isLoggable", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testIsLoggable_NoFilter() { MockHandler h = new MockHandler(); LogRecord r = new LogRecord(Level.CONFIG, null); @@ -462,24 +711,51 @@ public class HandlerTest extends TestCase { /* * Use a filter */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Verifies isLoggable method with filter.", + targets = { + @TestTarget( + methodName = "isLoggable", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testIsLoggable_WithFilter() { MockHandler h = new MockHandler(); LogRecord r = new LogRecord(Level.CONFIG, null); + LogRecord r1 = new LogRecord(Level.CONFIG, null); + LogRecord r2 = new LogRecord(Level.CONFIG, null); + h.setFilter(new MockFilter()); assertFalse(h.isLoggable(r)); - + assertSame(r,CallVerificationStack.getInstance().pop()); + h.setLevel(Level.CONFIG); - assertFalse(h.isLoggable(r)); - assertSame(r, CallVerificationStack.getInstance().pop()); + assertFalse(h.isLoggable(r1)); + assertSame(r1, CallVerificationStack.getInstance().pop()); h.setLevel(Level.SEVERE); - assertFalse(h.isLoggable(r)); - assertSame(r, CallVerificationStack.getInstance().pop()); + assertFalse(h.isLoggable(r2)); + + try{ + CallVerificationStack.getInstance().pop(); + }catch(EmptyStackException e){ + //normal + } } /** * @tests java.util.logging.Handler#isLoggable(LogRecord) */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "isLoggable", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testIsLoggable_Null() { MockHandler h = new MockHandler(); try { @@ -494,6 +770,15 @@ public class HandlerTest extends TestCase { * Test whether the error manager is actually called with expected * parameters. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "reportError", + methodArgs = {java.lang.String.class, java.lang.Exception.class, int.class} + ) + }) public void testReportError() { MockHandler h = new MockHandler(); h.setErrorManager(new MockErrorManager()); diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LevelTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LevelTest.java index 7f1fc5a..bf6920f 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LevelTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LevelTest.java @@ -17,8 +17,14 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + import java.io.Serializable; import java.util.ResourceBundle; +import java.util.logging.Handler; import java.util.logging.Level; import junit.framework.TestCase; @@ -30,6 +36,7 @@ import org.apache.harmony.testframework.serialization.SerializationTest.Serializ * This class implements Serializable, so that the non-static inner class * MockLevel can be Serializable. */ +@TestTargetClass(Level.class) public class LevelTest extends TestCase implements Serializable { private static final long serialVersionUID = 1L; @@ -38,6 +45,20 @@ public class LevelTest extends TestCase implements Serializable { * Test the constructor without resource bundle parameter using normal * values. As byproducts, getName & intValue are also tested. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks the constructor without resource bundle parameter " + + "using normal values.", + targets = { + @TestTarget( + methodName = "Level", + methodArgs = {java.lang.String.class, int.class} + ), + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void testConstructorNoResBundle_Normal() { MockLevel l = new MockLevel("level1", 1); assertEquals("level1", l.getName()); @@ -49,6 +70,20 @@ public class LevelTest extends TestCase implements Serializable { * Test the constructor without resource bundle parameter using null name. * As byproducts, getName & intValue are also tested. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks the constructor without resource bundle parameter " + + "using null name.", + targets = { + @TestTarget( + methodName = "Level", + methodArgs = {java.lang.String.class, int.class} + ), + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void testConstructorNoResBundle_NullName() { try { new MockLevel(null, -2); @@ -62,6 +97,20 @@ public class LevelTest extends TestCase implements Serializable { * Test the constructor without resource bundle parameter using empty name. * As byproducts, getName & intValue are also tested. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks the constructor without resource bundle parameter " + + "using empty name.", + targets = { + @TestTarget( + methodName = "Level", + methodArgs = {java.lang.String.class, int.class} + ), + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void testConstructorNoResBundle_EmptyName() { MockLevel l = new MockLevel("", -3); assertEquals("", l.getName()); @@ -73,6 +122,19 @@ public class LevelTest extends TestCase implements Serializable { * Test the constructor having resource bundle parameter using normal * values. As byproducts, getName & intValue are also tested. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "Level", + methodArgs = {String.class, int.class, String.class} + ), + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void testConstructorHavingResBundle_Normal() { MockLevel l = new MockLevel("level1", 1, "resourceBundle"); assertEquals("level1", l.getName()); @@ -84,6 +146,16 @@ public class LevelTest extends TestCase implements Serializable { * Test the constructor having resource bundle parameter using null names. * As byproducts, getName & intValue are also tested. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks NullPointerException.", + targets = { + @TestTarget( + methodName = "Level", + methodArgs = {java.lang.String.class, int.class, + java.lang.String.class} + ) + }) public void testConstructorHavingResBundle_NullName() { try { new MockLevel(null, -123, "qwe"); @@ -98,6 +170,16 @@ public class LevelTest extends TestCase implements Serializable { names. * As byproducts, getName & intValue are also tested. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor having resource bundle parameter " + + "using empty names.", + targets = { + @TestTarget( + methodName = "Level", + methodArgs = {String.class, int.class, String.class} + ) + }) public void testConstructorHavingResBundle_EmptyName() { MockLevel l = new MockLevel("", -1000, ""); assertEquals("", l.getName()); @@ -108,6 +190,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test method parse, with the pre-defined string consts. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies parse, with the pre-defined string consts.", + targets = { + @TestTarget( + methodName = "parse", + methodArgs = {java.lang.String.class} + ) + }) public void testParse_PredefinedConstStrings() { assertSame(Level.SEVERE, Level.parse("SEVERE")); assertSame(Level.WARNING, Level.parse("WARNING")); @@ -123,6 +214,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test method parse, with an undefined string. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "IllegalArgumentException is verified.", + targets = { + @TestTarget( + methodName = "parse", + methodArgs = {java.lang.String.class} + ) + }) public void testParse_IllegalConstString() { try { Level.parse("SEVERe"); @@ -135,6 +235,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test method parse, with a null string. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "parse", + methodArgs = {java.lang.String.class} + ) + }) public void testParse_NullString() { try { Level.parse(null); @@ -147,6 +256,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test method parse, with pre-defined valid number strings. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies parse, with pre-defined valid number strings.", + targets = { + @TestTarget( + methodName = "parse", + methodArgs = {java.lang.String.class} + ) + }) public void testParse_PredefinedNumber() { assertSame(Level.SEVERE, Level.parse("SEVERE")); assertSame(Level.WARNING, Level.parse("WARNING")); @@ -171,6 +289,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test method parse, with an undefined valid number strings. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies parse, with an undefined valid number strings.", + targets = { + @TestTarget( + methodName = "parse", + methodArgs = {java.lang.String.class} + ) + }) public void testParse_UndefinedNumber() { Level l = Level.parse("0"); assertEquals(0, l.intValue()); @@ -181,6 +308,16 @@ public class LevelTest extends TestCase implements Serializable { /* * Test method parse, with an undefined valid number strings with spaces. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies parse, with an undefined valid number strings " + + "with spaces.", + targets = { + @TestTarget( + methodName = "parse", + methodArgs = {java.lang.String.class} + ) + }) public void testParse_UndefinedNumberWithSpaces() { try { Level.parse(" 0"); @@ -188,7 +325,15 @@ public class LevelTest extends TestCase implements Serializable { // expected } } - + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies negative number.", + targets = { + @TestTarget( + methodName = "parse", + methodArgs = {java.lang.String.class} + ) + }) public void testParse_NegativeNumber() { Level l = Level.parse("-4"); assertEquals(-4, l.intValue()); @@ -200,6 +345,16 @@ public class LevelTest extends TestCase implements Serializable { * Test method parse, expecting the same objects will be returned given the * same name, even for non-predefined levels. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies parse, expecting the same objects will be returned " + + "given the same name, even for non-predefined levels.", + targets = { + @TestTarget( + methodName = "parse", + methodArgs = {java.lang.String.class} + ) + }) public void testParse_SameObject() { Level l = Level.parse("-100"); assertSame(l, Level.parse("-100")); @@ -208,6 +363,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test method hashCode, with normal fields. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "hashCode", + methodArgs = {} + ) + }) public void testHashCode_Normal() { assertEquals(100, Level.parse("100").hashCode()); assertEquals(-1, Level.parse("-1").hashCode()); @@ -218,6 +382,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test equals when two objects are equal. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't check negative case.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void testEquals_Equal() { MockLevel l1 = new MockLevel("level1", 1); MockLevel l2 = new MockLevel("level2", 1); @@ -228,6 +401,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test equals when two objects are not equal. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks negative case.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void testEquals_NotEqual() { MockLevel l1 = new MockLevel("level1", 1); MockLevel l2 = new MockLevel("level1", 2); @@ -238,6 +420,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test equals when the other object is null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks null as a parameter.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void testEquals_Null() { assertFalse(Level.ALL.equals(null)); } @@ -245,6 +436,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test equals when the other object is not an instance of Level. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks negative case.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void testEquals_NotLevel() { assertFalse(Level.ALL.equals(new Object())); } @@ -252,6 +452,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test equals when the other object is itself. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Checks equals when the other object is itself.", + targets = { + @TestTarget( + methodName = "equals", + methodArgs = {java.lang.Object.class} + ) + }) public void testEquals_Itself() { assertTrue(Level.ALL.equals(Level.ALL)); } @@ -259,6 +468,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test toString of a normal Level. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "toString", + methodArgs = {} + ) + }) public void testToString_Normal() { assertEquals("ALL", Level.ALL.toString()); @@ -293,6 +511,15 @@ public class LevelTest extends TestCase implements Serializable { * Test serialization of pre-defined const levels. It is expected that the * deserialized cost level should be the same instance as the existing one. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Serialization of pre-defined const levels. ", + targets = { + @TestTarget( + methodName = "!SerializationSelf", + methodArgs = {} + ) + }) public void testSerialization_ConstLevel() throws Exception { SerializationTest.verifySelf(Level.ALL, @@ -305,6 +532,15 @@ public class LevelTest extends TestCase implements Serializable { * Test serialization of normal instance of Level. It is expected that the * deserialized level object should be equal to the original one. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Test serialization of normal instance of Level.", + targets = { + @TestTarget( + methodName = "!SerializationSelf", + methodArgs = {} + ) + }) public void testSerialization_InstanceLevel() throws Exception { // tests that objects are the same @@ -324,12 +560,29 @@ public class LevelTest extends TestCase implements Serializable { /** * @tests serialization/deserialization compatibility with RI. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Serialization/deserialization compatibility", + targets = { + @TestTarget( + methodName = "!SerializationGolden", + methodArgs = {} + ) + }) public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new MockLevel("123", 123, "bundle"), LEVEL_COMPARATOR); } - + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getLocalizedName", + methodArgs = {} + ) + }) public void testGetLocalName() { ResourceBundle rb = ResourceBundle.getBundle("bundles/java/util/logging/res"); Level l = new MockLevel("level1", 120, @@ -356,6 +609,15 @@ public class LevelTest extends TestCase implements Serializable { /* * test for method public String getResourceBundleName() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getResourceBundleName", + methodArgs = {} + ) + }) public void testGetResourceBundleName() { String bundleName = "bundles/java/util/logging/res"; Level l = new MockLevel("level1", 120); @@ -372,6 +634,15 @@ public class LevelTest extends TestCase implements Serializable { /* * test for method public final int intValue() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "intValue", + methodArgs = {} + ) + }) public void testIntValue() { int value1 = 120; Level l = new MockLevel("level1", value1); @@ -383,6 +654,15 @@ public class LevelTest extends TestCase implements Serializable { /* * Test defining new levels in subclasses of Level */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Test defining new levels in subclasses of Level", + targets = { + @TestTarget( + methodName = "parse", + methodArgs = {String.class} + ) + }) public void testSubclassNewLevel() { MyLevel.DUPLICATENAME.getName();// just to load MyLevel class diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LevelTestResource.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LevelTestResource.java index 5e06b70..9b41a9d 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LevelTestResource.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LevelTestResource.java @@ -17,8 +17,12 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestTargetClass; + import java.util.ListResourceBundle; +import java.util.logging.Level; +//@TestTargetClass = No test needed, just test class helper public class LevelTestResource extends ListResourceBundle { public Object[][] getContents() { return contents; diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java index 61406ff..8e6256e 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java @@ -19,6 +19,9 @@ package org.apache.harmony.logging.tests.java.util.logging; //import android.access.IPropertyChangeEvent; //import android.access.; +import dalvik.annotation.*; + + import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; @@ -33,6 +36,7 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import java.util.logging.LoggingPermission; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream; @@ -43,6 +47,7 @@ import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper * add/get logger(dot) * */ +@TestTargetClass(LogManager.class) public class LogManagerTest extends TestCase { private static final String FOO = "LogManagerTestFoo"; @@ -77,11 +82,7 @@ public class LogManagerTest extends TestCase { mockManager = new MockLogManager(); // listener = new MockPropertyChangeListener(); handler = new MockHandler(); - props = initProps(); - } - - static Properties initProps() throws Exception { - Properties props = new Properties(); + props = new Properties(); props.put("handlers", className + "$MockHandler " + className + "$MockHandler"); props.put("java.util.logging.FileHandler.pattern", "%h/java%u.log"); props.put("java.util.logging.FileHandler.limit", "50000"); @@ -89,13 +90,12 @@ public class LogManagerTest extends TestCase { props.put("java.util.logging.FileHandler.formatter", "java.util.logging.XMLFormatter"); props.put(".level", "FINE"); props.put("java.util.logging.ConsoleHandler.level", "OFF"); - props - .put("java.util.logging.ConsoleHandler.formatter", - "java.util.logging.SimpleFormatter"); + props.put("java.util.logging.ConsoleHandler.formatter","java.util.logging.SimpleFormatter"); props.put("LogManagerTestFoo.handlers", "java.util.logging.ConsoleHandler"); props.put("LogManagerTestFoo.level", "WARNING"); - return props; } + + /* * @see TestCase#tearDown() @@ -105,6 +105,36 @@ public class LogManagerTest extends TestCase { handler = null; } + @TestInfo( + level = TestLevel.TODO, + purpose = "not really necessary, already tested with the singleton " + + "getLogManager.", + targets = { + + @TestTarget( + methodName = "LogManager", + methodArgs = {Logger.class} + ) + }) + public void testLogManager() { + + } + + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NullPointerException.", + targets = { + + @TestTarget( + methodName = "addLogger", + methodArgs = {Logger.class} + ), + + @TestTarget( + methodName = "getLogger", + methodArgs = {String.class} + ) + }) public void testAddGetLogger() { Logger log = new MockLogger(FOO, null); Logger foo = mockManager.getLogger(FOO); @@ -138,6 +168,21 @@ public class LogManagerTest extends TestCase { assertEquals(i, 1); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + + @TestTarget( + methodName = "addLogger", + methodArgs = {Logger.class} + ), + + @TestTarget( + methodName = "getLogger", + methodArgs = {String.class} + ) + }) public void testAddGetLogger_duplicateName() { // add logger with duplicate name has no effect Logger foo = new MockLogger(FOO, null); @@ -155,6 +200,21 @@ public class LogManagerTest extends TestCase { assertEquals(1, i); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + + @TestTarget( + methodName = "addLogger", + methodArgs = {Logger.class} + ), + + @TestTarget( + methodName = "getLogger", + methodArgs = {String.class} + ) + }) public void testAddGetLogger_Hierachy() { Logger foo = new MockLogger("testAddGetLogger_Hierachy.foo", null); Logger child = new MockLogger("testAddGetLogger_Hierachy.foo.child", null); @@ -194,6 +254,21 @@ public class LogManagerTest extends TestCase { assertSame(otherChild, grandson.getParent()); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + + @TestTarget( + methodName = "addLogger", + methodArgs = {Logger.class} + ), + + @TestTarget( + methodName = "getLogger", + methodArgs = {String.class} + ) + }) public void testAddLoggerReverseOrder() { Logger root = new MockLogger("testAddLoggerReverseOrder", null); Logger foo = new MockLogger("testAddLoggerReverseOrder.foo", null); @@ -226,6 +301,17 @@ public class LogManagerTest extends TestCase { assertSame(realRoot, root.getParent()); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + + @TestTarget( + methodName = "addLogger", + methodArgs = {Logger.class} + ) + + }) public void testAddSimiliarLogger() { Logger root = new MockLogger("testAddSimiliarLogger", null); Logger foo = new MockLogger("testAddSimiliarLogger.foo", null); @@ -257,6 +343,21 @@ public class LogManagerTest extends TestCase { assertSame(fooo, foooChild.getParent()); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + + @TestTarget( + methodName = "addLogger", + methodArgs = {Logger.class} + ), + @TestTarget( + methodName = "getLogger", + methodArgs = {String.class} + ) + + }) public void testAddGetLogger_nameWithSpace() { Logger foo = new MockLogger(FOO, null); Logger fooBeforeSpace = new MockLogger(FOO + " ", null); @@ -273,6 +374,22 @@ public class LogManagerTest extends TestCase { assertSame(fooWithBothSpace, mockManager.getLogger(" " + FOO + " ")); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify NullPointerException of addLogger " + + "method.", + targets = { + + @TestTarget( + methodName = "addLogger", + methodArgs = {Logger.class} + ), + @TestTarget( + methodName = "getLogger", + methodArgs = {String.class} + ) + + }) public void testAddGetLogger_addRoot() throws IOException { Logger foo = new MockLogger(FOO, null); Logger fooChild = new MockLogger(FOO + ".child", null); @@ -303,6 +420,21 @@ public class LogManagerTest extends TestCase { /** * @tests java.util.logging.LogManager#addLogger(Logger) */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + + @TestTarget( + methodName = "addLogger", + methodArgs = {Logger.class} + ), + @TestTarget( + methodName = "getLogManager", + methodArgs = {} + ) + + }) public void test_addLoggerLLogger_Security() throws Exception { // regression test for Harmony-1286 SecurityManager originalSecurityManager = System.getSecurityManager(); @@ -316,7 +448,16 @@ public class LogManagerTest extends TestCase { } } - public void testDefaultLoggerProperties() throws Exception { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "readConfiguration", + methodArgs = {InputStream.class} + ) + }) + public void _testDefaultLoggerProperties() throws Exception { // mock LogManager has no default logger assertNull(mockManager.getLogger("")); assertNull(mockManager.getLogger("global")); @@ -349,6 +490,22 @@ public class LogManagerTest extends TestCase { * case 3: test bad name * case 4: check correct tested value */ + + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + + @TestTarget( + methodName = "getLogger", + methodArgs = {String.class} + ), + @TestTarget( + methodName = "getLoggerNames", + methodArgs = {} + ) + + }) public void testGetLogger() throws Exception { // case 1: test default and valid value @@ -385,6 +542,20 @@ public class LogManagerTest extends TestCase { /* * test for method public Logger getLogger(String name) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + + @TestTarget( + methodName = "getLogger", + methodArgs = {String.class} + ), + @TestTarget( + methodName = "getLoggerNames", + methodArgs = {} + ) + }) public void testGetLogger_duplicateName() throws Exception { // test duplicate name // add logger with duplicate name has no effect @@ -408,6 +579,17 @@ public class LogManagerTest extends TestCase { /* * test for method public Logger getLogger(String name) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + + @TestTarget( + methodName = "getLogger", + methodArgs = {String.class} + ) + + }) public void testGetLogger_hierachy() throws Exception { // test hierachy Logger foo = new MockLogger("testGetLogger_hierachy.foo", null); @@ -420,6 +602,17 @@ public class LogManagerTest extends TestCase { /* * test for method public Logger getLogger(String name) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + + @TestTarget( + methodName = "getLogger", + methodArgs = {String.class} + ) + + }) public void testGetLogger_nameSpace() throws Exception { // test name with space Logger foo = new MockLogger(FOO, null); @@ -440,6 +633,22 @@ public class LogManagerTest extends TestCase { /* * test for method public void checkAccess() throws SecurityException */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + + @TestTarget( + methodName = "checkAccess", + methodArgs = {} + ), + + @TestTarget( + methodName = "getLogManager", + methodArgs = {} + ) + + }) public void testCheckAccess() { try { manager.checkAccess(); @@ -461,6 +670,33 @@ public class LogManagerTest extends TestCase { System.setSecurityManager(securityManager); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies SecurityException.", + targets = { + @TestTarget( + methodName = "readConfiguration", + methodArgs = {InputStream.class} + ), + @TestTarget( + methodName = "readConfiguration", + methodArgs = {} + ), + @TestTarget( + methodName = "checkAccess", + methodArgs = {} + ), + @TestTarget( + methodName = "reset", + methodArgs = {} + ), + + @TestTarget( + methodName = "getLogManager", + methodArgs = {} + ) + + }) public void testLoggingPermission() throws IOException { System.setSecurityManager(new MockSecurityManagerLogPermission()); mockManager.addLogger(new MockLogger("abc", null)); @@ -512,6 +748,20 @@ public class LogManagerTest extends TestCase { System.setSecurityManager(securityManager); } + + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + @TestTarget( + methodName = "readConfiguration", + methodArgs = {InputStream.class} + ), + @TestTarget( + methodName = "getProperty", + methodArgs = {String.class} + ) + }) public void testMockGetProperty() throws Exception { // mock manager doesn't read configuration until you call // readConfiguration() @@ -530,15 +780,19 @@ public class LogManagerTest extends TestCase { assertEquals(0, mockManager.getLogger("").getHandlers().length); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + + @TestTarget( + methodName = "getProperty", + methodArgs = {String.class} + ) + + }) public void testGetProperty() throws SecurityException, IOException { - // //FIXME: move it to exec - // manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props)); - // Logger root = manager.getLogger(""); - //// checkProperty(manager); - // assertEquals(Level.FINE, root.getLevel()); - // assertEquals(2, root.getHandlers().length); - - // but non-mock manager DO read it from the very beginning + Logger root = manager.getLogger(""); manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props)); checkProperty(manager); @@ -552,6 +806,17 @@ public class LogManagerTest extends TestCase { manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props)); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NullPointerException.", + targets = { + + @TestTarget( + methodName = "readConfiguration", + methodArgs = {InputStream.class} + ) + + }) public void testReadConfiguration_null() throws SecurityException, IOException { try { manager.readConfiguration(null); @@ -560,7 +825,20 @@ public class LogManagerTest extends TestCase { } } - + + + + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + + @TestTarget( + methodName = "getProperty", + methodArgs = {String.class} + ) + + }) private static void checkPropertyNull(LogManager m) { // assertNull(m.getProperty(".level")); assertNull(m.getProperty("java.util.logging.FileHandler.limit")); @@ -573,6 +851,17 @@ public class LogManagerTest extends TestCase { assertNull(m.getProperty("java.util.logging.FileHandler.pattern")); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + + @TestTarget( + methodName = "getProperty", + methodArgs = {String.class} + ) + + }) private static void checkProperty(LogManager m) { // assertEquals(m.getProperty(".level"), "INFO"); assertEquals(m.getProperty("java.util.logging.FileHandler.limit"), "50000"); @@ -618,10 +907,21 @@ public class LogManagerTest extends TestCase { /* * Class under test for void readConfiguration(InputStream) */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + + @TestTarget( + methodName = "readConfiguration", + methodArgs = {InputStream.class} + ) + + }) public void testReadConfigurationInputStream() throws IOException { // mock LogManager InputStream stream = EnvironmentHelper.PropertiesToInputStream(props); - + Logger foo = new MockLogger(FOO, null); assertNull(foo.getLevel()); assertTrue(mockManager.addLogger(foo)); @@ -632,7 +932,7 @@ public class LogManagerTest extends TestCase { Handler h = new ConsoleHandler(); Level l = h.getLevel(); - assertNotSame(Level.OFF, h.getLevel()); + assertSame(Level.OFF, h.getLevel()); // read configuration from stream mockManager.readConfiguration(stream); @@ -645,10 +945,21 @@ public class LogManagerTest extends TestCase { assertNull(fo.getLevel()); // read properties don't affect handler - assertNotSame(Level.OFF, h.getLevel()); + assertSame(Level.OFF, h.getLevel()); assertSame(l, h.getLevel()); } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies NullPointerException.", + targets = { + + @TestTarget( + methodName = "readConfiguration", + methodArgs = {InputStream.class} + ) + + }) public void testReadConfigurationInputStream_null() throws SecurityException, IOException { try { mockManager.readConfiguration(null); @@ -657,7 +968,38 @@ public class LogManagerTest extends TestCase { } } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies IOException.", + targets = { + + @TestTarget( + methodName = "readConfiguration", + methodArgs = {InputStream.class} + ) + + }) + public void testReadConfigurationInputStream_IOException_1parm() throws SecurityException { + try { + mockManager.readConfiguration(new MockInputStream()); + fail("should throw IOException"); + } catch (IOException e) { + //ignore + } + + } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "", + targets = { + + @TestTarget( + methodName = "readConfiguration", + methodArgs = {InputStream.class} + ) + + }) public void testReadConfigurationInputStream_root() throws IOException { InputStream stream = EnvironmentHelper.PropertiesToInputStream(props); manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props)); @@ -744,6 +1086,17 @@ public class LogManagerTest extends TestCase { // mockManager.removePropertyChangeListener(null); // } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Doesn't verify SecurityException.", + targets = { + + @TestTarget( + methodName = "reset", + methodArgs = {} + ) + + }) public void testReset() throws SecurityException, IOException { // mock LogManager mockManager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props)); @@ -778,6 +1131,18 @@ public class LogManagerTest extends TestCase { assertEquals(0, root.getHandlers().length); } + + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Doesn't verify SecurityException.", + targets = { + + @TestTarget( + methodName = "readConfiguration", + methodArgs = {InputStream.class} + ) + + }) public void testGlobalPropertyConfig() throws Exception { PrintStream err = System.err; try { @@ -850,7 +1215,17 @@ public class LogManagerTest extends TestCase { } } - + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + + @TestTarget( + methodName = "readConfiguration", + methodArgs = {} + ) + + }) public void testValidConfigClass() throws Exception { String oldProperty = System.getProperty("java.util.logging.config.class"); try { @@ -872,21 +1247,27 @@ public class LogManagerTest extends TestCase { } } - // regression for HARMONY-3075 - //??? logging: MX is based on Management package: not supported. - // public void testGetLoggingMXBean() throws Exception{ - // assertNotNull(LogManager.getLoggingMXBean()); - // } - /* * ---------------------------------------------------- * mock classes * ---------------------------------------------------- */ + + public static class ConfigClass { public ConfigClass() throws Exception { LogManager man = LogManager.getLogManager(); - Properties props = LogManagerTest.initProps(); + Properties props = new Properties(); + props.put("handlers", className + "$MockHandler " + className + "$MockHandler"); + props.put("java.util.logging.FileHandler.pattern", "%h/java%u.log"); + props.put("java.util.logging.FileHandler.limit", "50000"); + props.put("java.util.logging.FileHandler.count", "5"); + props.put("java.util.logging.FileHandler.formatter", "java.util.logging.XMLFormatter"); + props.put(".level", "FINE"); + props.put("java.util.logging.ConsoleHandler.level", "OFF"); + props.put("java.util.logging.ConsoleHandler.formatter","java.util.logging.SimpleFormatter"); + props.put("LogManagerTestFoo.handlers", "java.util.logging.ConsoleHandler"); + props.put("LogManagerTestFoo.level", "WARNING"); props.put("testConfigClass.foo.level", "OFF"); props.put("testConfigClass.foo.handlers", "java.util.logging.ConsoleHandler"); props.put(".level", "FINEST"); @@ -1194,4 +1575,16 @@ public class LogManagerTest extends TestCase { static class MockError extends Error { } } + + public static class MockInputStream extends InputStream { + + @Override + public int read() throws IOException { + throw new IOException(); + } + + + } + + } diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogRecordTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogRecordTest.java index 5656f6d..166483e 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogRecordTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogRecordTest.java @@ -17,6 +17,11 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + import java.io.Serializable; import java.util.Locale; import java.util.ResourceBundle; @@ -25,11 +30,13 @@ import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; + import junit.framework.TestCase; import org.apache.harmony.testframework.serialization.SerializationTest; import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert; +@TestTargetClass(LogRecord.class) public class LogRecordTest extends TestCase { static final String MSG = "test msg, pls. ignore itb"; @@ -41,9 +48,13 @@ public class LogRecordTest extends TestCase { protected void setUp() throws Exception { super.setUp(); lr = new LogRecord(Level.CONFIG, MSG); - } + @TestInfo(level = TestLevel.COMPLETE, purpose = "", + targets = { + @TestTarget(methodName = "LogRecord", methodArgs = { + Level.class, String.class}) + }) public void testLogRecordWithNullPointers() { try { new LogRecord(null, null); @@ -60,6 +71,10 @@ public class LogRecordTest extends TestCase { assertNull(r.getMessage()); } + @TestInfo(level = TestLevel.COMPLETE, purpose = "normally set/get don't need to be tested", targets = { + @TestTarget(methodName = "getLoggerName", methodArgs = {}), + @TestTarget(methodName = "setLoggerName", methodArgs = {String.class}) + }) public void testGetSetLoggerName() { assertNull(lr.getLoggerName()); lr.setLoggerName(null); @@ -68,6 +83,11 @@ public class LogRecordTest extends TestCase { assertEquals("test logger name", lr.getLoggerName()); } + + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getResourceBundle", methodArgs = {}), + @TestTarget(methodName = "setResourceBundle", methodArgs = {ResourceBundle.class}) + }) public void testGetSetResourceBundle() { assertNull(lr.getResourceBundleName()); assertNull(lr.getResourceBundle()); @@ -86,6 +106,10 @@ public class LogRecordTest extends TestCase { assertNull(lr.getResourceBundleName()); } + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getResourceBundleName", methodArgs = {}), + @TestTarget(methodName = "setResourceBundleName", methodArgs = {String.class}) + }) public void testGetSetResourceBundleName() { assertNull(lr.getResourceBundleName()); lr.setResourceBundleName(null); @@ -93,8 +117,24 @@ public class LogRecordTest extends TestCase { lr.setResourceBundleName("test"); assertEquals("test", lr.getResourceBundleName()); } + + @TestInfo(level = TestLevel.COMPLETE, purpose = "normal behavior of getter/setter don't need to be tested (normally)", targets = { + @TestTarget(methodName = "getLevel", methodArgs = {}), + @TestTarget(methodName = "setLevel", methodArgs = {Level.class}) + }) + public void testGetSetLevelNormal() { + assertSame(lr.getLevel(), Level.CONFIG); + lr.setLevel(Level.ALL); + assertSame(lr.getLevel(), Level.ALL); + lr.setLevel(Level.FINEST); + assertSame(lr.getLevel(), Level.FINEST); + } - public void testGetSetLevel() { + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getLevel", methodArgs = {}), + @TestTarget(methodName = "setLevel", methodArgs = {Level.class}) + }) + public void testGetSetLevelNullPointerException() { try { lr.setLevel(null); fail("should throw NullPointerException"); @@ -103,16 +143,24 @@ public class LogRecordTest extends TestCase { assertSame(lr.getLevel(), Level.CONFIG); } + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getSequenceNumber", methodArgs = {}), + @TestTarget(methodName = "setSequenceNumber", methodArgs = {long.class}) + }) public void testGetSetSequenceNumber() { long l = lr.getSequenceNumber(); lr.setSequenceNumber(-111); assertEquals(lr.getSequenceNumber(), -111L); lr.setSequenceNumber(0); assertEquals(lr.getSequenceNumber(), 0L); - lr = new LogRecord(Level.ALL, null); + lr = new LogRecord(Level.ALL, null); //sequenceNumber is updated to a private static counter assertEquals(lr.getSequenceNumber(), l + 1); } + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getSourceClassName", methodArgs = {}), + @TestTarget(methodName = "setSourceClassName", methodArgs = {String.class}) + }) public void testGetSetSourceClassName() { lr.setSourceClassName(null); assertNull(lr.getSourceClassName()); @@ -122,6 +170,10 @@ public class LogRecordTest extends TestCase { assertEquals(this.getClass().getName(), lr.getSourceClassName()); } + @TestInfo(level = TestLevel.PARTIAL_OK, purpose = "", targets = { + @TestTarget(methodName = "getSourceMethodName", methodArgs = {}), + @TestTarget(methodName = "setSourceMethodName", methodArgs = {String.class}) + }) public void testGetSetSourceMethodName() { lr.setSourceMethodName(null); assertNull(lr.getSourceMethodName()); @@ -131,6 +183,12 @@ public class LogRecordTest extends TestCase { assertEquals(this.getClass().getName(), lr.getSourceMethodName()); } + @TestInfo(level = TestLevel.PARTIAL_OK, purpose = "", targets = { + @TestTarget(methodName = "getSourceMethodName", methodArgs = {}), + @TestTarget(methodName = "setSourceMethodName", methodArgs = {String.class}), + @TestTarget(methodName = "getSourceClassName", methodArgs = {}), + @TestTarget(methodName = "setSourceClassName", methodArgs = {String.class}) + }) public void testGetSourceDefaultValue() { assertNull(lr.getSourceMethodName()); assertNull(lr.getSourceClassName()); @@ -160,10 +218,10 @@ public class LogRecordTest extends TestCase { // set both lr = new LogRecord(Level.SEVERE, MSG); lr.setSourceClassName("className"); - lr.setSourceMethodName(null); + lr.setSourceMethodName("methodName"); logger.log(lr); assertEquals("className", handler.getSourceClassName()); - assertNull(handler.getSourceMethodName()); + assertEquals("methodName", handler.getSourceMethodName()); // test if LogRecord is constructed in another class, and is published // by Logger @@ -172,8 +230,6 @@ public class LogRecordTest extends TestCase { assertEquals("testGetSourceDefaultValue", handler.getSourceMethodName()); lr = RecordFactory.getDefaultRecord(); - // assertNull(lr.getSourceClassName()); - // assertNull(lr.getSourceMethodName()); RecordFactory.log(logger, lr); assertEquals(RecordFactory.class.getName(), handler .getSourceClassName()); @@ -187,21 +243,18 @@ public class LogRecordTest extends TestCase { assertNull(handler.getSourceClassName()); assertNull(handler.getSourceMethodName()); - // it cannot find correct default value when logger is subclass MockLogger ml = new MockLogger("foo", null); ml.addHandler(handler); ml.info(MSG); assertEquals(className + "$MockLogger", handler.getSourceClassName()); assertEquals("info", handler.getSourceMethodName()); - // it can find nothing when only call Subclass ml = new MockLogger("foo", null); ml.addHandler(handler); ml.log(Level.SEVERE, MSG); assertNull(handler.getSourceClassName()); assertNull(handler.getSourceMethodName()); - // test if don't call logger, what is the default value lr = new LogRecord(Level.SEVERE, MSG); handler.publish(lr); assertNull(handler.getSourceClassName()); @@ -209,6 +262,10 @@ public class LogRecordTest extends TestCase { logger.removeHandler(handler); } + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getMessage", methodArgs = {}), + @TestTarget(methodName = "setMessage", methodArgs = {String.class}) + }) public void testGetSetMessage() { assertEquals(MSG, lr.getMessage()); lr.setMessage(null); @@ -217,6 +274,10 @@ public class LogRecordTest extends TestCase { assertEquals("", lr.getMessage()); } + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getParameters", methodArgs = {}), + @TestTarget(methodName = "setParameters", methodArgs = {Object[].class}) + }) public void testGetSetParameters() { assertNull(lr.getParameters()); lr.setParameters(null); @@ -224,11 +285,15 @@ public class LogRecordTest extends TestCase { Object[] oa = new Object[0]; lr.setParameters(oa); assertEquals(oa, lr.getParameters()); - oa = new Object[] { new Object(), new Object() }; + oa = new Object[] {new Object(), new Object()}; lr.setParameters(oa); assertSame(oa, lr.getParameters()); } + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getMillis", methodArgs = {}), + @TestTarget(methodName = "setMillis", methodArgs = {long.class}) + }) public void testGetSetMillis() { long milli = lr.getMillis(); assertTrue(milli > 0); @@ -237,9 +302,30 @@ public class LogRecordTest extends TestCase { lr.setMillis(0); assertEquals(0, lr.getMillis()); } + + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getMillis", methodArgs = {}), + @TestTarget(methodName = "setMillis", methodArgs = {long.class}) + }) + public void testGetSetTimeCheck() { + long before = lr.getMillis(); + try { + Thread.sleep(2); + } catch (InterruptedException e) { + e.printStackTrace(); + } + LogRecord lr2 = new LogRecord(Level.CONFIG, "MSG2"); + long after = lr2.getMillis(); + assertTrue(after-before>0); + } + + + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getThreadID", methodArgs = {}), + @TestTarget(methodName = "setThreadID", methodArgs = {int.class}) + }) public void testGetSetThreadID() { - // TODO how to test the different thread int id = lr.getThreadID(); lr = new LogRecord(Level.ALL, "a1"); assertEquals(id, lr.getThreadID()); @@ -248,7 +334,43 @@ public class LogRecordTest extends TestCase { lr = new LogRecord(Level.ALL, "a1"); assertEquals(id, lr.getThreadID()); } + + /* + * Check threadID are different + */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getThreadID", methodArgs = {}), + @TestTarget(methodName = "setThreadID", methodArgs = {int.class}) + }) + public void testGetSetThreadID_DifferentThread() { + int id = lr.getThreadID(); + // Create and start the thread + MockThread thread = new MockThread(); + thread.start(); + try { + thread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + // Create and start the thread2 + MockThread thread2 = new MockThread(); + thread2.start(); + try { + thread2.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + //All threadID must be different, based on the ThreadLocal.java ID + assertTrue(lr.getThreadID() != thread.lr.getThreadID()); + assertTrue(lr.getThreadID() != thread2.lr.getThreadID()); + assertTrue(thread.lr.getThreadID() != thread2.lr.getThreadID()); + } + + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "getThrown", methodArgs = {}), + @TestTarget(methodName = "setThrown", methodArgs = {Throwable.class})}) public void testGetSetThrown() { assertNull(lr.getThrown()); lr.setThrown(null); @@ -256,6 +378,9 @@ public class LogRecordTest extends TestCase { Throwable e = new Exception(); lr.setThrown(e); assertEquals(e, lr.getThrown()); + Throwable n = new NullPointerException(); + lr.setThrown(n); + assertEquals(n, lr.getThrown()); } // comparator for LogRecord objects @@ -303,6 +428,8 @@ public class LogRecordTest extends TestCase { /** * @tests serialization/deserialization compatibility. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "serialisation/deserialization", targets = { + @TestTarget(methodName = "!SerializationSelf", methodArgs = {})}) public void testSerializationSelf() throws Exception { LogRecord r = new LogRecord(Level.ALL, "msg"); r.setLoggerName("LoggerName"); @@ -311,9 +438,7 @@ public class LogRecordTest extends TestCase { r.setSequenceNumber(987654321); r.setSourceClassName("SourceClassName"); r.setSourceMethodName("SourceMethodName"); - r - .setParameters(new Object[] { "test string", - new Exception("ex-msg") }); + r.setParameters(new Object[] {"test string", new Exception("ex-msg")}); r.setThreadID(3232); r.setThrown(new Exception("ExceptionMessage")); @@ -323,6 +448,11 @@ public class LogRecordTest extends TestCase { /** * @tests resolution of resource bundle for serialization/deserialization. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "tests resolution of resource bundle during deserialization", + targets = { + @TestTarget(methodName = "!Serialization", methodArgs = {})}) public void testSerializationResourceBundle() throws Exception { // test case: valid resource bundle name @@ -346,6 +476,8 @@ public class LogRecordTest extends TestCase { /** * @tests serialization/deserialization compatibility with RI. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "!SerializationGolden", methodArgs = {})}) public void testSerializationCompatibility() throws Exception { LogRecord r = new LogRecord(Level.ALL, "msg"); r.setLoggerName("LoggerName"); @@ -354,9 +486,7 @@ public class LogRecordTest extends TestCase { r.setSequenceNumber(987654321); r.setSourceClassName("SourceClassName"); r.setSourceMethodName("SourceMethodName"); - r - .setParameters(new Object[] { "test string", - new Exception("ex-msg") }); + r.setParameters(new Object[] {"test string", new Exception("ex-msg")}); r.setThreadID(3232); r.setThrown(new Exception("ExceptionMessage")); @@ -445,4 +575,22 @@ public class LogRecordTest extends TestCase { } } } + + public class MockThread extends Thread { + + public LogRecord lr = null; //will be update by the thread + + public MockThread(){ + super(); + } + + public void run() { + update(); + } + + public synchronized void update(){ + lr = new LogRecord(Level.CONFIG, "msg thread"); + } + + } } diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerExtension.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerExtension.java deleted file mode 100644 index 1828d94..0000000 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerExtension.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -package org.apache.harmony.logging.tests.java.util.logging; - -import java.util.ResourceBundle; -import java.util.logging.Logger; - -/** - * Example of a type injected into logging to access package private members. - */ -public class LoggerExtension { - - public static ResourceBundle loadResourceBundle(String resourceBundleName) { -// return Logger.loadResourceBundle(resourceBundleName); - return Logger.getAnonymousLogger(resourceBundleName).getResourceBundle(); - } - -} diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java index ca9dc1c..19c6eb3 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggerTest.java @@ -17,8 +17,17 @@ package org.apache.harmony.logging.tests.java.util.logging; -import java.io.File; -import java.io.FileInputStream; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + +import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper; + +import tests.util.CallVerificationStack; + import java.security.Permission; import java.util.Locale; import java.util.MissingResourceException; @@ -32,16 +41,10 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; import java.util.logging.LoggingPermission; -import junit.framework.TestCase; - -import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper; - -import tests.util.CallVerificationStack; - /** * Test suite for the class java.util.logging.Logger. - * */ +@TestTargetClass(Logger.class) public class LoggerTest extends TestCase { private final static String VALID_RESOURCE_BUNDLE = "bundles/java/util/logging/res"; @@ -51,8 +54,8 @@ public class LoggerTest extends TestCase { private final static String VALID_RESOURCE_BUNDLE3 = "bundles/java/util/logging/res3"; private final static String INVALID_RESOURCE_BUNDLE = "impossible_not_existing"; - - private final static String LOGGING_CONFIG_FILE= "src/test/resources/config/java/util/logging/logging.config"; + + private final static String LOGGING_CONFIG_FILE = "src/test/resources/config/java/util/logging/logging.config"; private final static String VALID_KEY = "LOGGERTEST"; @@ -63,9 +66,10 @@ public class LoggerTest extends TestCase { private Logger sharedLogger = null; private Locale oldLocale = null; - + /* - * @see TestCase#setUp() + * @see TestCase#setUp() Notice : Logger constructor is protected => + * MockLogger */ protected void setUp() throws Exception { super.setUp(); @@ -81,6 +85,7 @@ public class LoggerTest extends TestCase { protected void tearDown() throws Exception { CallVerificationStack.getInstance().clear(); Locale.setDefault(oldLocale); + LogManager.getLogManager().reset(); super.tearDown(); } @@ -96,6 +101,9 @@ public class LoggerTest extends TestCase { /* * Test the global logger */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "Logger", methodArgs = {String.class, String.class})}) public void testGlobalLogger() { assertNull(Logger.global.getFilter()); assertEquals(0, Logger.global.getHandlers().length); @@ -112,9 +120,16 @@ public class LoggerTest extends TestCase { /* * Test constructor under normal conditions. - * - * TODO: using a series of class loaders to load resource bundles */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor under normal conditions.", + targets = { + @TestTarget( + methodName = "Logger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testConstructor_Normal() { MockLogger mlog = new MockLogger("myname", VALID_RESOURCE_BUNDLE); assertNull(mlog.getFilter()); @@ -131,6 +146,15 @@ public class LoggerTest extends TestCase { /* * Test constructor with null parameters. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with null parameters.", + targets = { + @TestTarget( + methodName = "Logger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testConstructor_Null() { MockLogger mlog = new MockLogger(null, null); assertNull(mlog.getFilter()); @@ -146,6 +170,15 @@ public class LoggerTest extends TestCase { /* * Test constructor with invalid name. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with invalid name.", + targets = { + @TestTarget( + methodName = "Logger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testConstructor_InvalidName() { MockLogger mlog = new MockLogger("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|", null); @@ -155,6 +188,15 @@ public class LoggerTest extends TestCase { /* * Test constructor with empty name. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies constructor with empty name.", + targets = { + @TestTarget( + methodName = "Logger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testConstructor_EmptyName() { MockLogger mlog = new MockLogger("", null); assertEquals("", mlog.getName()); @@ -163,49 +205,81 @@ public class LoggerTest extends TestCase { /* * Test constructor with invalid resource bundle name. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies MissingResourceException.", + targets = { + @TestTarget( + methodName = "Logger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testConstructor_InvalidResourceBundle() { + + // try anonymous with invalid resource try { new MockLogger(null, INVALID_RESOURCE_BUNDLE); fail("Should throw MissingResourceException!"); } catch (MissingResourceException e) { + // ok ! + } + // try named Logger with invalid resource + try { + new MockLogger("testConstructor_InvalidResourceBundle", + INVALID_RESOURCE_BUNDLE); + fail("Should throw MissingResourceException!"); + } catch (MissingResourceException e) { + // ok ! } // try empty string try { new MockLogger(null, ""); fail("Should throw MissingResourceException!"); } catch (MissingResourceException e) { + // ok ! } } /* * Test getAnonymousLogger() */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getAnonymousLogger", + methodArgs = {} + ) + }) public void testGetAnonymousLogger() { - SecurityManager oldMan = System.getSecurityManager(); - System.setSecurityManager(new MockSecurityManager()); - - try { - Logger alog = Logger.getAnonymousLogger(); - assertNotSame(alog, Logger.getAnonymousLogger()); - assertNull(alog.getFilter()); - assertEquals(0, alog.getHandlers().length); - assertNull(alog.getLevel()); - assertNull(alog.getName()); - assertNull(alog.getParent().getParent()); - assertNull(alog.getResourceBundle()); - assertNull(alog.getResourceBundleName()); - assertTrue(alog.getUseParentHandlers()); - // fail("Should throw SecurityException!"); - // } catch (SecurityException e) { - } finally { - System.setSecurityManager(oldMan); - } + Logger alog = Logger.getAnonymousLogger(); + assertNotSame(alog, Logger.getAnonymousLogger()); + assertNull(alog.getFilter()); + assertEquals(0, alog.getHandlers().length); + assertNull(alog.getLevel()); + assertNull(alog.getName()); + assertEquals("", alog.getParent().getName()); + assertNull(alog.getParent().getParent()); + assertNull(alog.getResourceBundle()); + assertNull(alog.getResourceBundleName()); + assertTrue(alog.getUseParentHandlers()); } /* * Test getAnonymousLogger(String resourceBundleName) with valid resource * bundle. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getAnonymousLogger(String resourceBundleName) " + + "with valid resource bundle.", + targets = { + @TestTarget( + methodName = "getAnonymousLogger", + methodArgs = {java.lang.String.class} + ) + }) public void testGetAnonymousLogger_ValidResourceBundle() { Logger alog = Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE); assertNotSame(alog, Logger.getAnonymousLogger(VALID_RESOURCE_BUNDLE)); @@ -213,6 +287,7 @@ public class LoggerTest extends TestCase { assertEquals(0, alog.getHandlers().length); assertNull(alog.getLevel()); assertNull(alog.getName()); + assertEquals("", alog.getParent().getName()); assertNull(alog.getParent().getParent()); assertEquals(VALID_VALUE, alog.getResourceBundle().getString(VALID_KEY)); assertEquals(alog.getResourceBundleName(), VALID_RESOURCE_BUNDLE); @@ -223,6 +298,16 @@ public class LoggerTest extends TestCase { * Test getAnonymousLogger(String resourceBundleName) with null resource * bundle. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getAnonymousLogger(String resourceBundleName) " + + "with null resource bundle.", + targets = { + @TestTarget( + methodName = "getAnonymousLogger", + methodArgs = {java.lang.String.class} + ) + }) public void testGetAnonymousLogger_NullResourceBundle() { Logger alog = Logger.getAnonymousLogger(null); assertNotSame(alog, Logger.getAnonymousLogger(null)); @@ -230,6 +315,7 @@ public class LoggerTest extends TestCase { assertEquals(0, alog.getHandlers().length); assertNull(alog.getLevel()); assertNull(alog.getName()); + assertEquals("", alog.getParent().getName()); assertNull(alog.getParent().getParent()); assertNull(alog.getResourceBundle()); assertNull(alog.getResourceBundleName()); @@ -240,6 +326,16 @@ public class LoggerTest extends TestCase { * Test getAnonymousLogger(String resourceBundleName) with invalid resource * bundle. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getAnonymousLogger(String resourceBundleName) " + + "with invalid resource bundle.", + targets = { + @TestTarget( + methodName = "getAnonymousLogger", + methodArgs = {java.lang.String.class} + ) + }) public void testGetAnonymousLogger_InvalidResourceBundle() { try { Logger.getAnonymousLogger(INVALID_RESOURCE_BUNDLE); @@ -257,6 +353,15 @@ public class LoggerTest extends TestCase { /* * Test getLogger(String), getting a logger with no parent. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String), getting a logger with no parent.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class} + ) + }) public void testGetLogger_Normal() throws Exception { // config the level Properties p = new Properties(); @@ -283,11 +388,23 @@ public class LoggerTest extends TestCase { assertNull(log.getResourceBundle()); assertNull(log.getResourceBundleName()); assertTrue(log.getUseParentHandlers()); + + } /* * Test getLogger(String), getting a logger with invalid level configured. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String), getting a logger with " + + "invalid level configured.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class} + ) + }) public void testGetLogger_InvalidLevel() throws Exception { // config the level Properties p = new Properties(); @@ -313,20 +430,42 @@ public class LoggerTest extends TestCase { /* * Test getLogger(String) with null name. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String) with null name.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class} + ) + }) public void testGetLogger_Null() { try { Logger.getLogger(null); fail("Should throw NullPointerException!"); } catch (NullPointerException e) { + // ok ! + } + try { + Logger.getLogger(null, null); + fail("Should throw NullPointerException!"); + } catch (NullPointerException e) { + // ok ! } - Logger logger = Logger.getLogger("", null); - assertNull(logger.getResourceBundleName()); - assertNull(logger.getResourceBundle()); } /* * Test getLogger(String) with invalid name. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String) with invalid name.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class} + ) + }) public void testGetLogger_Invalid() { Logger log = Logger.getLogger("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|"); assertEquals("...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|", log.getName()); @@ -335,7 +474,16 @@ public class LoggerTest extends TestCase { /* * Test getLogger(String) with empty name. */ - public void testGetLogger_Empty() { + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String) with empty name.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class} + ) + }) + public void _testGetLogger_Empty() { assertNotNull(LogManager.getLogManager().getLogger("")); Logger log = Logger.getLogger(""); assertSame(log, LogManager.getLogManager().getLogger("")); @@ -353,9 +501,22 @@ public class LoggerTest extends TestCase { /* * Test getLogger(String), getting a logger with existing parent. */ - public void testGetLogger_WithParentNormal() { + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies getLogger(String), getting a logger " + + "with existing parent.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void testGetLogger_WithParent() { assertNull(LogManager.getLogManager().getLogger( "testGetLogger_WithParent_ParentLogger")); + + // get root of hierarchy + Logger root = Logger.getLogger(""); // create the parent logger Logger pLog = Logger.getLogger("testGetLogger_WithParent_ParentLogger", VALID_RESOURCE_BUNDLE); @@ -363,38 +524,89 @@ public class LoggerTest extends TestCase { pLog.addHandler(new MockHandler()); pLog.setFilter(new MockFilter()); pLog.setUseParentHandlers(false); + // check root parent + assertEquals("testGetLogger_WithParent_ParentLogger", pLog.getName()); + assertSame(pLog.getParent(), root); + // child part assertNull(LogManager.getLogManager().getLogger( "testGetLogger_WithParent_ParentLogger.child")); // create the child logger - Logger log = Logger + Logger child = Logger .getLogger("testGetLogger_WithParent_ParentLogger.child"); - assertNull(log.getFilter()); - assertEquals(0, log.getHandlers().length); - assertNull(log.getLevel()); - assertEquals("testGetLogger_WithParent_ParentLogger.child", log + assertNull(child.getFilter()); + assertEquals(0, child.getHandlers().length); + assertNull(child.getLevel()); + assertEquals("testGetLogger_WithParent_ParentLogger.child", child .getName()); - assertSame(log.getParent(), pLog); - assertNull(log.getResourceBundle()); - assertNull(log.getResourceBundleName()); - assertTrue(log.getUseParentHandlers()); + assertSame(child.getParent(), pLog); + assertNull(child.getResourceBundle()); + assertNull(child.getResourceBundleName()); + assertTrue(child.getUseParentHandlers()); + + // create not valid child + Logger notChild = Logger + .getLogger("testGetLogger_WithParent_ParentLogger1.child"); + assertNull(notChild.getFilter()); + assertEquals(0, notChild.getHandlers().length); + assertNull(notChild.getLevel()); + assertEquals("testGetLogger_WithParent_ParentLogger1.child", notChild + .getName()); + assertNotSame(notChild.getParent(), pLog); + assertNull(notChild.getResourceBundle()); + assertNull(notChild.getResourceBundleName()); + assertTrue(notChild.getUseParentHandlers()); + // verify two level root.parent + assertEquals("testGetLogger_WithParent_ParentLogger.child", child + .getName()); + assertSame(child.getParent().getParent(), root); + + + // create three level child + Logger childOfChild = Logger + .getLogger("testGetLogger_WithParent_ParentLogger.child.child"); + assertNull(childOfChild.getFilter()); + assertEquals(0, childOfChild.getHandlers().length); + assertSame(child.getParent().getParent(), root); + assertNull(childOfChild.getLevel()); + assertEquals("testGetLogger_WithParent_ParentLogger.child.child", + childOfChild.getName()); + + assertSame(childOfChild.getParent(), child); + assertSame(childOfChild.getParent().getParent(), pLog); + assertSame(childOfChild.getParent().getParent().getParent(), root); + assertNull(childOfChild.getResourceBundle()); + assertNull(childOfChild.getResourceBundleName()); + assertTrue(childOfChild.getUseParentHandlers()); + + // abnormal case : lookup to root parent in a hierarchy without a logger + // parent created between + assertEquals("testGetLogger_WithParent_ParentLogger1.child", notChild + .getName()); + assertSame(child.getParent().getParent(), root); + assertNotSame(child.getParent(), root); + + // abnormal cases + assertNotSame(root.getParent(), root); + Logger twoDot = Logger.getLogger(".."); + assertSame(twoDot.getParent(), root); + } - // /* - // * Test getLogger(String), getting a logger with existing parent, using - // * abnormal names (containing '.'). - // */ - // public void testGetLogger_WithParentAbnormal() { - // Logger log = Logger.getLogger("."); - // assertSame(log.getParent(), Logger.getLogger("")); - // Logger log2 = Logger.getLogger(".."); - // assertSame(log2.getParent(), Logger.getLogger("")); - // //TODO: a lot more can be tested - // } /* * Test getLogger(String, String), getting a logger with no parent. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String, String), getting a logger " + + "with no parent.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testGetLoggerWithRes_Normal() throws Exception { // config the level Properties p = new Properties(); @@ -428,6 +640,15 @@ public class LoggerTest extends TestCase { /* * Test getLogger(String, String) with null parameters. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String, String) with null parameters.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testGetLoggerWithRes_Null() { Logger.getLogger("testGetLoggerWithRes_Null_ANewLogger", null); try { @@ -437,29 +658,71 @@ public class LoggerTest extends TestCase { } } + /* * Test getLogger(String, String) with invalid resource bundle. */ - public void testGetLoggerWithRes_InvalidRes() { + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String, String) with invalid " + + "resource bundle.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) + public void _testGetLoggerWithRes_InvalidResourceBundle() { + + assertNull(LogManager.getLogManager().getLogger( + "testMissingResourceException")); + try { - Logger.getLogger("", INVALID_RESOURCE_BUNDLE); + Logger.getLogger("testMissingResourceException", + INVALID_RESOURCE_BUNDLE); fail("Should throw MissingResourceException!"); } catch (MissingResourceException e) { + // correct } - assertNull(Logger.getLogger("").getResourceBundle()); - assertNull(Logger.getLogger("").getResourceBundleName()); + assertNull(Logger.getLogger("testMissingResourceException") + .getResourceBundle()); + assertNull(Logger.getLogger("testMissingResourceException") + .getResourceBundleName()); // try empty string try { - Logger.getLogger("", ""); + Logger.getLogger("testMissingResourceException", ""); fail("Should throw MissingResourceException!"); } catch (MissingResourceException e) { + // correct + } + + assertNull(LogManager.getLogManager().getLogger("")); + // The root logger always exists TODO + try { + Logger.getLogger("", INVALID_RESOURCE_BUNDLE); + } + catch (MissingResourceException e) { + //correct } + + } /* * Test getLogger(String, String) with valid resource bundle, to get an * existing logger with no associated resource bundle. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String, String) with valid resource " + + "bundle, to get an existing logger with no associated " + + "resource bundle.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testGetLoggerWithRes_ExistingLoggerWithNoRes() { assertNull(LogManager.getLogManager().getLogger( "testGetLoggerWithRes_ExistingLoggerWithNoRes_ANewLogger")); @@ -473,12 +736,24 @@ public class LoggerTest extends TestCase { assertSame(log1, log2); assertEquals(VALID_VALUE, log1.getResourceBundle().getString(VALID_KEY)); assertEquals(log1.getResourceBundleName(), VALID_RESOURCE_BUNDLE); + } /* * Test getLogger(String, String) with valid resource bundle, to get an * existing logger with the same associated resource bundle. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String, String) with valid resource " + + "bundle, to get an existing logger with the same associated " + + "resource bundle.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testGetLoggerWithRes_ExistingLoggerWithSameRes() { assertNull(LogManager.getLogManager().getLogger( "testGetLoggerWithRes_ExistingLoggerWithSameRes_ANewLogger")); @@ -499,6 +774,17 @@ public class LoggerTest extends TestCase { * Test getLogger(String, String) with valid resource bundle, to get an * existing logger with different associated resource bundle. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String, String) with valid resource " + + "bundle, to get an existing logger with different associated " + + "resource bundle.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testGetLoggerWithRes_ExistingLoggerWithDiffRes() { assertNull(LogManager.getLogManager().getLogger( "testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger")); @@ -509,14 +795,19 @@ public class LoggerTest extends TestCase { assertNotNull(log1); // get an existing logger try { - Logger.getLogger("testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger", - VALID_RESOURCE_BUNDLE2); + Logger + .getLogger( + "testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger", + VALID_RESOURCE_BUNDLE2); fail("Should throw IllegalArgumentException!"); } catch (IllegalArgumentException e) { } try { - Logger.getLogger("testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger", null); + Logger + .getLogger( + "testGetLoggerWithRes_ExistingLoggerWithDiffRes_ANewLogger", + null); fail("Should throw IllegalArgumentException!"); } catch (IllegalArgumentException e) { } @@ -525,6 +816,15 @@ public class LoggerTest extends TestCase { /* * Test getLogger(String, String) with invalid name. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String, String) with invalid name.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testGetLoggerWithRes_InvalidName() { Logger log = Logger.getLogger( "...#$%%^&&()-_+=!@~./,[]{};:'\\\"?|WithRes", @@ -536,6 +836,15 @@ public class LoggerTest extends TestCase { /* * Test getLogger(String, String) with empty name. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String, String) with empty name.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testGetLoggerWithRes_Empty() { Logger log = Logger.getLogger("", VALID_RESOURCE_BUNDLE); assertSame(log, LogManager.getLogManager().getLogger("")); @@ -553,6 +862,16 @@ public class LoggerTest extends TestCase { /* * Test getLogger(String, String), getting a logger with existing parent. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getLogger(String, String), getting a logger " + + "with existing parent.", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testGetLoggerWithRes_WithParentNormal() { assertNull(LogManager.getLogManager().getLogger( "testGetLoggerWithRes_WithParent_ParentLogger")); @@ -584,6 +903,15 @@ public class LoggerTest extends TestCase { /* * Test addHandler(Handler) for a named logger with sufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addHandler", + methodArgs = {java.util.logging.Handler.class} + ) + }) public void testAddHandler_NamedLoggerSufficientPrivilege() { Logger log = Logger .getLogger("testAddHandler_NamedLoggerSufficientPrivilege"); @@ -591,28 +919,48 @@ public class LoggerTest extends TestCase { assertEquals(log.getHandlers().length, 0); log.addHandler(h); assertEquals(log.getHandlers().length, 1); - assertSame(log.getHandlers()[0], h); + } /* * Test addHandler(Handler) for a named logger with sufficient privilege, * add duplicate handlers. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addHandler", + methodArgs = {java.util.logging.Handler.class} + ) + }) public void testAddHandler_NamedLoggerSufficientPrivilegeDuplicate() { Logger log = Logger .getLogger("testAddHandler_NamedLoggerSufficientPrivilegeDuplicate"); MockHandler h = new MockHandler(); assertEquals(log.getHandlers().length, 0); - log.addHandler(h); - log.addHandler(h); - assertEquals(log.getHandlers().length, 2); + for (int i = 0; i < 12; i++) { + log.addHandler(h); + } + assertEquals(log.getHandlers().length, 12); assertSame(log.getHandlers()[0], h); - assertSame(log.getHandlers()[1], h); + assertSame(log.getHandlers()[5], h); + assertSame(log.getHandlers()[11], h); } /* * Test addHandler(Handler) with a null handler. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies NullPointerException.", + targets = { + @TestTarget( + methodName = "addHandler", + methodArgs = {java.util.logging.Handler.class} + ) + }) public void testAddHandler_Null() { Logger log = Logger.getLogger("testAddHandler_Null"); try { @@ -626,6 +974,15 @@ public class LoggerTest extends TestCase { /* * Test addHandler(Handler) for a named logger with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addHandler", + methodArgs = {java.util.logging.Handler.class} + ) + }) public void testAddHandler_NamedLoggerInsufficientPrivilege() { Logger log = Logger .getLogger("testAddHandler_NamedLoggerInsufficientPrivilege"); @@ -646,6 +1003,15 @@ public class LoggerTest extends TestCase { * Test addHandler(Handler) for a named logger with insufficient privilege, * using a null handler. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addHandler", + methodArgs = {java.util.logging.Handler.class} + ) + }) public void testAddHandler_NamedLoggerInsufficientPrivilegeNull() { Logger log = Logger .getLogger("testAddHandler_NamedLoggerInsufficientPrivilege"); @@ -665,6 +1031,15 @@ public class LoggerTest extends TestCase { * Test addHandler(Handler) for an anonymous logger with sufficient * privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addHandler", + methodArgs = {java.util.logging.Handler.class} + ) + }) public void testAddHandler_AnonyLoggerSufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); MockHandler h = new MockHandler(); @@ -678,6 +1053,15 @@ public class LoggerTest extends TestCase { * Test addHandler(Handler) for an anonymous logger with insufficient * privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "addHandler", + methodArgs = {java.util.logging.Handler.class} + ) + }) public void testAddHandler_AnonyLoggerInsufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); MockHandler h = new MockHandler(); @@ -697,6 +1081,16 @@ public class LoggerTest extends TestCase { * Test addHandler(Handler) for a null-named mock logger with insufficient * privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies addHandler(Handler) for a null-named mock logger " + + "with insufficient privilege, SecurityException.", + targets = { + @TestTarget( + methodName = "addHandler", + methodArgs = {java.util.logging.Handler.class} + ) + }) public void testAddHandler_NullNamedMockLoggerInsufficientPrivilege() { MockLogger mlog = new MockLogger(null, null); MockHandler h = new MockHandler(); @@ -715,6 +1109,9 @@ public class LoggerTest extends TestCase { * Test removeHandler(Handler) for a named logger with sufficient privilege, * remove an existing handler. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "addHandler", methodArgs = {Handler.class})}) public void testRemoveHandler_NamedLoggerSufficientPrivilege() { Logger log = Logger .getLogger("testRemoveHandler_NamedLoggerSufficientPrivilege"); @@ -729,6 +1126,9 @@ public class LoggerTest extends TestCase { * Test removeHandler(Handler) for a named logger with sufficient privilege, * remove a non-existing handler. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "removeHandler", methodArgs = {Handler.class})}) public void testRemoveHandler_NamedLoggerSufficientPrivilegeNotExisting() { Logger log = Logger .getLogger("testRemoveHandler_NamedLoggerSufficientPrivilegeNotExisting"); @@ -741,6 +1141,9 @@ public class LoggerTest extends TestCase { /* * Test removeHandler(Handler) with a null handler. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "removeHandler", methodArgs = {Handler.class})}) public void testRemoveHandler_Null() { Logger log = Logger.getLogger("testRemoveHandler_Null"); log.removeHandler(null); @@ -751,6 +1154,9 @@ public class LoggerTest extends TestCase { * Test removeHandler(Handler) for a named logger with insufficient * privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "removeHandler", methodArgs = {Handler.class})}) public void testRemoveHandler_NamedLoggerInsufficientPrivilege() { Logger log = Logger .getLogger("testRemoveHandler_NamedLoggerInsufficientPrivilege"); @@ -771,6 +1177,9 @@ public class LoggerTest extends TestCase { * Test removeHandler(Handler) for a named logger with insufficient * privilege, using a null handler. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "removeHandler", methodArgs = {Handler.class})}) public void testRemoveHandler_NamedLoggerInsufficientPrivilegeNull() { Logger log = Logger .getLogger("testRemoveHandler_NamedLoggerInsufficientPrivilege"); @@ -790,6 +1199,9 @@ public class LoggerTest extends TestCase { * Test removeHandler(Handler) for an anonymous logger with sufficient * privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "removeHandler", methodArgs = {Handler.class})}) public void testRemoveHandler_AnonyLoggerSufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); MockHandler h = new MockHandler(); @@ -803,6 +1215,9 @@ public class LoggerTest extends TestCase { * Test removeHandler(Handler) for an anonymous logger with insufficient * privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "removeHandler", methodArgs = {Handler.class})}) public void testRemoveHandler_AnonyLoggerInsufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); MockHandler h = new MockHandler(); @@ -822,6 +1237,9 @@ public class LoggerTest extends TestCase { * Test removeHandler(Handler) for a null-named mock logger with * insufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "removeHandler", methodArgs = {Handler.class})}) public void testRemoveHandler_NullNamedMockLoggerInsufficientPrivilege() { MockLogger mlog = new MockLogger(null, null); MockHandler h = new MockHandler(); @@ -839,6 +1257,15 @@ public class LoggerTest extends TestCase { /* * Test getHandlers() when there's no handler. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getHandlers() when there's no handler.", + targets = { + @TestTarget( + methodName = "getHandlers", + methodArgs = {} + ) + }) public void testGetHandlers_None() { Logger log = Logger.getLogger("testGetHandlers_None"); assertEquals(log.getHandlers().length, 0); @@ -847,6 +1274,15 @@ public class LoggerTest extends TestCase { /* * Test getHandlers() when there are several handlers. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getHandlers() when there are several handlers.", + targets = { + @TestTarget( + methodName = "getHandlers", + methodArgs = {} + ) + }) public void testGetHandlers_Several() { Logger log = Logger.getLogger("testGetHandlers_None"); assertEquals(log.getHandlers().length, 0); @@ -865,12 +1301,27 @@ public class LoggerTest extends TestCase { assertEquals(log.getHandlers().length, 2); assertSame(log.getHandlers()[0], h1); assertSame(log.getHandlers()[1], h3); + } /* * Test getFilter & setFilter with normal value for a named logger, having * sufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies getFilter & setFilter with normal value " + + "for a named logger, having sufficient privilege.", + targets = { + @TestTarget( + methodName = "getFilter", + methodArgs = {} + ), + @TestTarget( + methodName = "setFilter", + methodArgs = {java.util.logging.Filter.class} + ) + }) public void testGetSetFilter_NamedLoggerSufficientPrivilege() { Logger log = Logger .getLogger("testGetSetFilter_NamedLoggerSufficientPrivilege"); @@ -884,6 +1335,20 @@ public class LoggerTest extends TestCase { /* * Test getFilter & setFilter with null value, having sufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies getFilter & setFilter with null value, " + + "having sufficient privilege.", + targets = { + @TestTarget( + methodName = "getFilter", + methodArgs = {} + ), + @TestTarget( + methodName = "setFilter", + methodArgs = {java.util.logging.Filter.class} + ) + }) public void testGetSetFilter_Null() { Logger log = Logger.getLogger("testGetSetFilter_Null"); @@ -899,6 +1364,18 @@ public class LoggerTest extends TestCase { * Test setFilter with normal value for a named logger, having insufficient * privilege. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies setFilter with normal value for a named logger, " + + "having insufficient privilege.", + targets = { + @TestTarget( + methodName = "getFilter", + methodArgs = {}), + @TestTarget( + methodName = "setFilter", + methodArgs = {Filter.class}) + }) public void testGetSetFilter_NamedLoggerInsufficientPrivilege() { Logger log = Logger .getLogger("testGetSetFilter_NamedLoggerInsufficientPrivilege"); @@ -917,6 +1394,10 @@ public class LoggerTest extends TestCase { /* * Test setFilter for an anonymous logger with sufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getFilter", methodArgs = {}), + @TestTarget(methodName = "setFilter", methodArgs = {Filter.class})}) public void testSetFilter_AnonyLoggerSufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); Filter f = new MockFilter(); @@ -928,6 +1409,10 @@ public class LoggerTest extends TestCase { /* * Test setFilter for an anonymous logger with insufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getFilter", methodArgs = {}), + @TestTarget(methodName = "setFilter", methodArgs = {Filter.class})}) public void testSetFilter_AnonyLoggerInsufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); Filter f = new MockFilter(); @@ -945,6 +1430,10 @@ public class LoggerTest extends TestCase { /* * Test setFilter for a null-named mock logger with insufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getFilter", methodArgs = {}), + @TestTarget(methodName = "setFilter", methodArgs = {Filter.class})}) public void testSetFilter_NullNamedMockLoggerInsufficientPrivilege() { MockLogger mlog = new MockLogger(null, null); Filter f = new MockFilter(); @@ -963,6 +1452,20 @@ public class LoggerTest extends TestCase { * Test getLevel & setLevel with normal value for a named logger, having * sufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies getLevel & setLevel with normal value for " + + "a named logger, having sufficient privilege.", + targets = { + @TestTarget( + methodName = "setLevel", + methodArgs = {java.util.logging.Level.class} + ), + @TestTarget( + methodName = "getLevel", + methodArgs = {} + ) + }) public void testGetSetLevel_NamedLoggerSufficientPrivilege() { Logger log = Logger .getLogger("testGetSetLevel_NamedLoggerSufficientPrivilege"); @@ -975,6 +1478,20 @@ public class LoggerTest extends TestCase { /* * Test getLevel & setLevel with null value, having sufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies getLevel & setLevel with null value, " + + "having sufficient privilege.", + targets = { + @TestTarget( + methodName = "getLevel", + methodArgs = {} + ), + @TestTarget( + methodName = "setLevel", + methodArgs = {java.util.logging.Level.class} + ) + }) public void testGetSetLevel_Null() { Logger log = Logger.getLogger("testGetSetLevel_Null"); @@ -990,6 +1507,20 @@ public class LoggerTest extends TestCase { * Test setLevel with normal value for a named logger, having insufficient * privilege. */ + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "Verifies setLevel with normal value for a named logger, " + + "having insufficient privilege.", + targets = { + @TestTarget( + methodName = "setLevel", + methodArgs = {java.util.logging.Level.class} + ), + @TestTarget( + methodName = "getLevel", + methodArgs = {} + ) + }) public void testGetSetLevel_NamedLoggerInsufficientPrivilege() { Logger log = Logger .getLogger("testGetSetLevel_NamedLoggerInsufficientPrivilege"); @@ -1007,6 +1538,10 @@ public class LoggerTest extends TestCase { /* * Test setLevel for an anonymous logger with sufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getLevel", methodArgs = {}), + @TestTarget(methodName = "setLevel", methodArgs = {Level.class})}) public void testSetLevel_AnonyLoggerSufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); assertNull(log.getLevel()); @@ -1017,6 +1552,10 @@ public class LoggerTest extends TestCase { /* * Test setLevel for an anonymous logger with insufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getLevel", methodArgs = {}), + @TestTarget(methodName = "setLevel", methodArgs = {Level.class})}) public void testSetLevel_AnonyLoggerInsufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); SecurityManager oldMan = System.getSecurityManager(); @@ -1033,6 +1572,10 @@ public class LoggerTest extends TestCase { /* * Test setLevel for a null-named mock logger with insufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getLevel", methodArgs = {}), + @TestTarget(methodName = "setLevel", methodArgs = {Level.class})}) public void testSetLevel_NullNamedMockLoggerInsufficientPrivilege() { MockLogger mlog = new MockLogger(null, null); SecurityManager oldMan = System.getSecurityManager(); @@ -1050,6 +1593,10 @@ public class LoggerTest extends TestCase { * Test getUseParentHandlers & setUseParentHandlers with normal value for a * named logger, having sufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getUseParentHandlers", methodArgs = {}), + @TestTarget(methodName = "setUseParentHandlers", methodArgs = {boolean.class})}) public void testGetSetUseParentHandlers_NamedLoggerSufficientPrivilege() { Logger log = Logger .getLogger("testGetSetUseParentHandlers_NamedLoggerSufficientPrivilege"); @@ -1063,6 +1610,10 @@ public class LoggerTest extends TestCase { * Test setUseParentHandlers with normal value for a named logger, having * insufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getUseParentHandlers", methodArgs = {}), + @TestTarget(methodName = "setUseParentHandlers", methodArgs = {boolean.class})}) public void testGetSetUseParentHandlers_NamedLoggerInsufficientPrivilege() { Logger log = Logger .getLogger("testGetSetUseParentHandlers_NamedLoggerInsufficientPrivilege"); @@ -1081,6 +1632,10 @@ public class LoggerTest extends TestCase { * Test setUseParentHandlers for an anonymous logger with sufficient * privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getUseParentHandlers", methodArgs = {}), + @TestTarget(methodName = "setUseParentHandlers", methodArgs = {boolean.class})}) public void testSetUseParentHandlers_AnonyLoggerSufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); assertTrue(log.getUseParentHandlers()); @@ -1092,6 +1647,10 @@ public class LoggerTest extends TestCase { * Test setUseParentHandlers for an anonymous logger with insufficient * privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getUseParentHandlers", methodArgs = {}), + @TestTarget(methodName = "setUseParentHandlers", methodArgs = {boolean.class})}) public void testSetUseParentHandlers_AnonyLoggerInsufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); SecurityManager oldMan = System.getSecurityManager(); @@ -1109,6 +1668,10 @@ public class LoggerTest extends TestCase { * Test setUseParentHandlers for a null-named mock logger with insufficient * privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "getUseParentHandlers", methodArgs = {}), + @TestTarget(methodName = "setUseParentHandlers", methodArgs = {boolean.class})}) public void testSetUseParentHandlers_NullNamedMockLoggerInsufficientPrivilege() { MockLogger mlog = new MockLogger(null, null); SecurityManager oldMan = System.getSecurityManager(); @@ -1125,6 +1688,15 @@ public class LoggerTest extends TestCase { /* * Test getParent() for root logger. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getParent() for root logger.", + targets = { + @TestTarget( + methodName = "getParent", + methodArgs = {} + ) + }) public void testGetParent_Root() { assertNull(Logger.getLogger("").getParent()); } @@ -1132,6 +1704,15 @@ public class LoggerTest extends TestCase { /* * Test getParent() for normal named loggers. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getParent() for normal named loggers.", + targets = { + @TestTarget( + methodName = "getParent", + methodArgs = {} + ) + }) public void testGetParent_NormalNamed() { Logger log = Logger.getLogger("testGetParent_NormalNamed"); assertSame(log.getParent(), Logger.getLogger("")); @@ -1144,6 +1725,15 @@ public class LoggerTest extends TestCase { /* * Test getParent() for anonymous loggers. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getParent() for anonymous loggers.", + targets = { + @TestTarget( + methodName = "getParent", + methodArgs = {} + ) + }) public void testGetParent_Anonymous() { assertSame(Logger.getAnonymousLogger().getParent(), Logger .getLogger("")); @@ -1153,6 +1743,9 @@ public class LoggerTest extends TestCase { * Test setParent(Logger) for the mock logger since it is advised not to * call this method on named loggers. Test normal conditions. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "setParent", methodArgs = {Logger.class})}) public void testSetParent_Normal() { Logger log = new MockLogger(null, null); Logger parent = new MockLogger(null, null); @@ -1164,6 +1757,9 @@ public class LoggerTest extends TestCase { /* * Test setParent(Logger) with null. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "setParent", methodArgs = {Logger.class})}) public void testSetParent_Null() { try { (new MockLogger(null, null)).setParent(null); @@ -1175,6 +1771,9 @@ public class LoggerTest extends TestCase { /* * Test setParent(Logger), having insufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "setParent", methodArgs = {Logger.class})}) public void testSetParent_InsufficientPrivilege() { MockLogger log = new MockLogger(null, null); SecurityManager oldMan = System.getSecurityManager(); @@ -1191,6 +1790,9 @@ public class LoggerTest extends TestCase { /* * Test setParent(Logger) with null, having insufficient privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "setParent", methodArgs = {Logger.class})}) public void testSetParent_InsufficientPrivilegeNull() { MockLogger log = new MockLogger(null, null); SecurityManager oldMan = System.getSecurityManager(); @@ -1208,6 +1810,9 @@ public class LoggerTest extends TestCase { * Test setParent(Logger) for an anonymous logger with insufficient * privilege. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "setParent", methodArgs = {Logger.class})}) public void testSetParent_AnonyLoggerInsufficientPrivilege() { Logger log = Logger.getAnonymousLogger(); SecurityManager oldMan = System.getSecurityManager(); @@ -1224,6 +1829,15 @@ public class LoggerTest extends TestCase { /* * Test getName() for normal names. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getName() for normal names.", + targets = { + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void testGetName_Normal() { Logger log = Logger.getLogger("testGetName_Normal"); assertEquals("testGetName_Normal", log.getName()); @@ -1235,6 +1849,15 @@ public class LoggerTest extends TestCase { /* * Test getName() for empty name. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getName() for empty name.", + targets = { + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void testGetName_Empty() { Logger log = Logger.getLogger(""); assertEquals("", log.getName()); @@ -1246,6 +1869,15 @@ public class LoggerTest extends TestCase { /* * Test getName() for null name. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getName() for null name.", + targets = { + @TestTarget( + methodName = "getName", + methodArgs = {} + ) + }) public void testGetName_Null() { Logger log = Logger.getAnonymousLogger(); assertNull(log.getName()); @@ -1257,6 +1889,15 @@ public class LoggerTest extends TestCase { /* * Test getResourceBundle() when it it not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getResourceBundle() when it it not null.", + targets = { + @TestTarget( + methodName = "getResourceBundle", + methodArgs = {} + ) + }) public void testGetResourceBundle_Normal() { Logger log = Logger.getLogger("testGetResourceBundle_Normal", VALID_RESOURCE_BUNDLE); @@ -1269,6 +1910,15 @@ public class LoggerTest extends TestCase { /* * Test getResourceBundle() when it it null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getResourceBundle() when it it null.", + targets = { + @TestTarget( + methodName = "getResourceBundle", + methodArgs = {} + ) + }) public void testGetResourceBundle_Null() { Logger log = Logger.getLogger("testGetResourceBundle_Null", null); assertNull(log.getResourceBundle()); @@ -1277,9 +1927,19 @@ public class LoggerTest extends TestCase { assertNull(mlog.getResourceBundle()); } + /* * Test getResourceBundleName() when it it not null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getResourceBundleName() when it it not null.", + targets = { + @TestTarget( + methodName = "getResourceBundleName", + methodArgs = {} + ) + }) public void testGetResourceBundleName_Normal() { Logger log = Logger.getLogger("testGetResourceBundleName_Normal", VALID_RESOURCE_BUNDLE); @@ -1292,6 +1952,15 @@ public class LoggerTest extends TestCase { /* * Test getResourceBundleName() when it it null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies getResourceBundleName() when it it null.", + targets = { + @TestTarget( + methodName = "getResourceBundleName", + methodArgs = {} + ) + }) public void testGetResourceBundleName_Null() { Logger log = Logger.getLogger("testGetResourceBundleName_Null", null); assertNull(log.getResourceBundleName()); @@ -1300,9 +1969,13 @@ public class LoggerTest extends TestCase { assertNull(mlog.getResourceBundleName()); } + /* * Test isLoggable(Level). */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "isLoggable", methodArgs = {Level.class}) + }) public void testIsLoggable() { MockLogger mlog = new MockLogger(null, null); assertNull(mlog.getLevel()); @@ -1336,6 +2009,10 @@ public class LoggerTest extends TestCase { /* * Test throwing(String, String, Throwable) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "throwing", methodArgs = { + String.class, String.class, Throwable.class}) + }) public void testThrowing_Normal() { Throwable t = new Throwable(); this.sharedLogger.setLevel(Level.FINER); @@ -1353,14 +2030,21 @@ public class LoggerTest extends TestCase { assertSame(r.getParameters(), null); assertSame(r.getThrown(), t); + this.sharedLogger.setLevel(Level.FINE); this.sharedLogger.throwing("sourceClass", "sourceMethod", t); + + // FINE is a level too low, message will be lost => empty assertTrue(CallVerificationStack.getInstance().empty()); } /* * Test throwing(String, String, Throwable) with null values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "throwing", methodArgs = { + String.class, String.class, Throwable.class}) + }) public void testThrowing_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1385,6 +2069,15 @@ public class LoggerTest extends TestCase { /* * Test entering(String, String) with normal values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies entering(String, String) with normal values.", + targets = { + @TestTarget( + methodName = "entering", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testEntering_StringString_Normal() { this.sharedLogger.setLevel(Level.FINER); this.sharedLogger.entering("sourceClass", "sourceMethod"); @@ -1409,6 +2102,15 @@ public class LoggerTest extends TestCase { /* * Test entering(String, String) with null values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies entering(String, String) with null values.", + targets = { + @TestTarget( + methodName = "entering", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testEntering_StringString_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1433,6 +2135,15 @@ public class LoggerTest extends TestCase { /* * Test entering(String, String, Object) with normal values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies entering(String, String, Object) with normal values.", + targets = { + @TestTarget( + methodName = "entering", + methodArgs = {java.lang.String.class, java.lang.String.class, java.lang.Object.class} + ) + }) public void testEntering_StringStringObject_Normal() { Object param = new Object(); this.sharedLogger.setLevel(Level.FINER); @@ -1459,6 +2170,15 @@ public class LoggerTest extends TestCase { /* * Test entering(String, String, Object) with null values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies entering(String, String, Object) with null values.", + targets = { + @TestTarget( + methodName = "entering", + methodArgs = {java.lang.String.class, java.lang.String.class, java.lang.Object.class} + ) + }) public void testEntering_StringStringObject_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1484,6 +2204,16 @@ public class LoggerTest extends TestCase { /* * Test entering(String, String, Object[]) with normal values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies entering(String, String, Object[]) with normal " + + "values.", + targets = { + @TestTarget( + methodName = "entering", + methodArgs = {java.lang.String.class, java.lang.String.class, java.lang.Object[].class} + ) + }) public void testEntering_StringStringObjects_Normal() { Object[] params = new Object[2]; params[0] = new Object(); @@ -1514,6 +2244,17 @@ public class LoggerTest extends TestCase { * Test entering(String, String, Object[]) with null class name and method * name and empty parameter array. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies entering(String, String, Object[]) with null class " + + "name and method name and empty parameter array.", + targets = { + @TestTarget( + methodName = "entering", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.lang.Object[].class} + ) + }) public void testEntering_StringStringObjects_NullEmpty() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1539,6 +2280,17 @@ public class LoggerTest extends TestCase { * Test entering(String, String, Object[]) with null values with appropriate * logging level set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies entering(String, String, Object[]) with null " + + "values with appropriate logging level set.", + targets = { + @TestTarget( + methodName = "entering", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.lang.Object[].class} + ) + }) public void testEntering_StringStringObjects_Null() { sharedLogger.setLevel(Level.FINER); sharedLogger.entering(null, null, (Object[]) null); @@ -1561,6 +2313,17 @@ public class LoggerTest extends TestCase { * Test entering(String, String, Object[]) with null values with * inappropriate logging level set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies entering(String, String, Object[]) with null " + + "values with inappropriate logging level set.", + targets = { + @TestTarget( + methodName = "entering", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.lang.Object[].class} + ) + }) public void testEntering_StringStringObjects_NullDisabled() { this.sharedLogger.setLevel(Level.FINE); this.sharedLogger.entering(null, null, (Object[]) null); @@ -1570,6 +2333,15 @@ public class LoggerTest extends TestCase { /* * Test exiting(String, String) with normal values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies exiting(String, String) with normal values.", + targets = { + @TestTarget( + methodName = "entering", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testExiting_StringString_Normal() { this.sharedLogger.setLevel(Level.FINER); this.sharedLogger.exiting("sourceClass", "sourceMethod"); @@ -1594,6 +2366,15 @@ public class LoggerTest extends TestCase { /* * Test exiting(String, String) with null values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies exiting(String, String) with null values.", + targets = { + @TestTarget( + methodName = "exiting", + methodArgs = {java.lang.String.class, java.lang.String.class} + ) + }) public void testExiting_StringString_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1618,6 +2399,16 @@ public class LoggerTest extends TestCase { /* * Test exiting(String, String, Object) with normal values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies exiting(String, String, Object) with normal values.", + targets = { + @TestTarget( + methodName = "exiting", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.lang.Object.class} + ) + }) public void testExiting_StringStringObject_Normal() { Object param = new Object(); this.sharedLogger.setLevel(Level.FINER); @@ -1644,6 +2435,16 @@ public class LoggerTest extends TestCase { /* * Test exiting(String, String, Object) with null values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies exiting(String, String, Object) with null values.", + targets = { + @TestTarget( + methodName = "exiting", + methodArgs = {java.lang.String.class, java.lang.String.class, + java.lang.Object.class} + ) + }) public void testExiting_StringStringObject_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1669,6 +2470,15 @@ public class LoggerTest extends TestCase { /* * Test config(String) with normal values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "config", + methodArgs = {java.lang.String.class} + ) + }) public void testConfig_Normal() { this.sharedLogger.setLevel(Level.CONFIG); this.sharedLogger.config("config msg"); @@ -1693,6 +2503,15 @@ public class LoggerTest extends TestCase { /* * Test config(String) with null values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies null as a parameter.", + targets = { + @TestTarget( + methodName = "config", + methodArgs = {java.lang.String.class} + ) + }) public void testConfig_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1721,6 +2540,15 @@ public class LoggerTest extends TestCase { /* * Test fine(String) with normal values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "fine", + methodArgs = {java.lang.String.class} + ) + }) public void testFine_Normal() { this.sharedLogger.setLevel(Level.FINE); this.sharedLogger.fine("fine msg"); @@ -1745,6 +2573,15 @@ public class LoggerTest extends TestCase { /* * Test fine(String) with null values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies fine(String) with null values.", + targets = { + @TestTarget( + methodName = "fine", + methodArgs = {java.lang.String.class} + ) + }) public void testFine_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1773,6 +2610,15 @@ public class LoggerTest extends TestCase { /* * Test finer(String) with normal values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies finer(String) with normal values.", + targets = { + @TestTarget( + methodName = "finer", + methodArgs = {java.lang.String.class} + ) + }) public void testFiner_Normal() { this.sharedLogger.setLevel(Level.FINER); this.sharedLogger.finer("finer msg"); @@ -1797,6 +2643,15 @@ public class LoggerTest extends TestCase { /* * Test finer(String) with null values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies finer(String) with null values.", + targets = { + @TestTarget( + methodName = "finer", + methodArgs = {java.lang.String.class} + ) + }) public void testFiner_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1825,6 +2680,15 @@ public class LoggerTest extends TestCase { /* * Test finest(String) with normal values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies finest(String) with normal values.", + targets = { + @TestTarget( + methodName = "finest", + methodArgs = {java.lang.String.class} + ) + }) public void testFinest_Normal() { this.sharedLogger.setLevel(Level.FINEST); this.sharedLogger.finest("finest msg"); @@ -1849,6 +2713,15 @@ public class LoggerTest extends TestCase { /* * Test finest(String) with null values. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies finest(String) with null values.", + targets = { + @TestTarget( + methodName = "finest", + methodArgs = {java.lang.String.class} + ) + }) public void testFinest_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1877,6 +2750,9 @@ public class LoggerTest extends TestCase { /* * Test info(String) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "info", methodArgs = {String.class})}) public void testInfo_Normal() { this.sharedLogger.setLevel(Level.INFO); this.sharedLogger.info("info msg"); @@ -1901,6 +2777,9 @@ public class LoggerTest extends TestCase { /* * Test info(String) with null values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "info", methodArgs = {String.class})}) public void testInfo_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1929,6 +2808,9 @@ public class LoggerTest extends TestCase { /* * Test warning(String) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "warning", methodArgs = {String.class})}) public void testWarning_Normal() { this.sharedLogger.setLevel(Level.WARNING); this.sharedLogger.warning("warning msg"); @@ -1953,6 +2835,9 @@ public class LoggerTest extends TestCase { /* * Test warning(String) with null values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "warning", methodArgs = {String.class})}) public void testWarning_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -1981,6 +2866,9 @@ public class LoggerTest extends TestCase { /* * Test severe(String) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "severe", methodArgs = {String.class})}) public void testSevere_Normal() { this.sharedLogger.setLevel(Level.SEVERE); this.sharedLogger.severe("severe msg"); @@ -2005,6 +2893,9 @@ public class LoggerTest extends TestCase { /* * Test severe(String) with null values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "severe", methodArgs = {String.class})}) public void testSevere_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -2033,6 +2924,9 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {Level.class, String.class})}) public void testLog_LevelString_Normal() { this.sharedLogger.setLevel(Level.INFO); this.sharedLogger.log(Level.INFO, "log(Level, String) msg"); @@ -2059,6 +2953,9 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String) with null message. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {Level.class, String.class})}) public void testLog_LevelString_NullMsg() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -2083,6 +2980,9 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String) with null level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {Level.class, String.class})}) public void testLog_LevelString_NullLevel() { // this.sharedLogger.setLevel(Level.OFF); try { @@ -2095,6 +2995,10 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String, Object) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = { + Level.class, String.class, Object.class})}) public void testLog_LevelStringObject_Normal() { Object param = new Object(); this.sharedLogger.setLevel(Level.INFO); @@ -2126,6 +3030,10 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String, Object) with null message and object. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = { + Level.class, String.class, Object.class})}) public void testLog_LevelStringObject_NullMsgObj() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -2151,6 +3059,10 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String, Object) with null level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = { + Level.class, String.class, Object.class})}) public void testLog_LevelStringObject_NullLevel() { // this.sharedLogger.setLevel(Level.OFF); try { @@ -2164,6 +3076,11 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String, Object[]) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "log", methodArgs = { + Level.class, String.class, Object[].class}) + }) + public void testLog_LevelStringObjects_Normal() { Object[] params = new Object[2]; params[0] = new Object(); @@ -2198,6 +3115,10 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String, Object[]) with null message and object. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = { + Level.class, String.class, Object[].class})}) public void testLog_LevelStringObjects_NullMsgObj() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -2222,8 +3143,11 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String, Object[]) with null level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = { + Level.class, String.class, Object[].class})}) public void testLog_LevelStringObjects_NullLevel() { - // this.sharedLogger.setLevel(Level.OFF); try { this.sharedLogger.log(null, "log(Level, String, Object[]) msg", new Object[0]); @@ -2235,6 +3159,10 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String, Throwable) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "log", methodArgs = { + Level.class, String.class, Throwable.class}) + }) public void testLog_LevelStringThrowable_Normal() { Throwable t = new Throwable(); this.sharedLogger.setLevel(Level.INFO); @@ -2265,6 +3193,10 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String, Throwable) with null message and throwable. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "log", methodArgs = { + Level.class, String.class, Throwable.class}) + }) public void testLog_LevelStringThrowable_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -2289,6 +3221,10 @@ public class LoggerTest extends TestCase { /* * Test log(Level, String, Throwable) with null level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "log", methodArgs = { + Level.class, String.class, Throwable.class}) + }) public void testLog_LevelStringThrowable_NullLevel() { // this.sharedLogger.setLevel(Level.OFF); try { @@ -2302,6 +3238,9 @@ public class LoggerTest extends TestCase { /* * Test logp(Level, String, String, String) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class})}) public void testLogp_LevelStringStringString_Normal() { this.sharedLogger.setLevel(Level.INFO); this.sharedLogger.logp(Level.INFO, "sourceClass", "sourceMethod", @@ -2331,6 +3270,9 @@ public class LoggerTest extends TestCase { /* * Test logp(Level, String, String, String) with null message. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class})}) public void testLogp_LevelStringStringString_NullMsg() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -2355,6 +3297,9 @@ public class LoggerTest extends TestCase { /* * Test logp(Level, String, String, String) with null level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class})}) public void testLogp_LevelStringStringString_NullLevel() { // this.sharedLogger.setLevel(Level.OFF); try { @@ -2368,6 +3313,9 @@ public class LoggerTest extends TestCase { /* * Test logp(Level, String, String, String, Object) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class, Object.class})}) public void testLogp_LevelStringStringStringObject_Normal() { Object param = new Object(); this.sharedLogger.setLevel(Level.INFO); @@ -2401,6 +3349,9 @@ public class LoggerTest extends TestCase { * Test logp(Level, String, String, String, Object) with null message and * object. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class, Object.class})}) public void testLogp_LevelStringStringStringObject_NullMsgObj() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -2426,6 +3377,10 @@ public class LoggerTest extends TestCase { /* * Test logp(Level, String, String, String, Object) with null level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class, Object.class})}) + public void testLogp_LevelStringStringStringObject_NullLevel() { // this.sharedLogger.setLevel(Level.OFF); try { @@ -2440,6 +3395,11 @@ public class LoggerTest extends TestCase { /* * Test logp(Level, String, String, String, Object[]) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class, Object[].class}) + }) + public void testLogp_LevelStringStringStringObjects_Normal() { Object[] params = new Object[2]; params[0] = new Object(); @@ -2476,6 +3436,10 @@ public class LoggerTest extends TestCase { * Test logp(Level, String, String, String, Object[]) with null message and * object. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class, Object[].class}) + }) public void testLogp_LevelStringStringStringObjects_NullMsgObj() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -2500,6 +3464,10 @@ public class LoggerTest extends TestCase { /* * Test logp(Level, String, String, String, Object[]) with null level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class, Object[].class}) + }) public void testLogp_LevelStringStringStringObjects_NullLevel() { // this.sharedLogger.setLevel(Level.OFF); try { @@ -2514,6 +3482,10 @@ public class LoggerTest extends TestCase { /* * Test logp(Level, String, String, String, Throwable) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class, + Throwable.class})}) public void testLogp_LevelStringStringStringThrowable_Normal() { Throwable t = new Throwable(); this.sharedLogger.setLevel(Level.INFO); @@ -2546,7 +3518,11 @@ public class LoggerTest extends TestCase { * Test logp(Level, String, String, String, Throwable) with null message and * throwable. */ - public void testLogp_LevelStringTStringStringhrowable_Null() { + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class, + Throwable.class})}) + public void testLogp_LevelStringStringStringThrowable_Null() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); child.addHandler(new MockHandler()); @@ -2570,6 +3546,10 @@ public class LoggerTest extends TestCase { /* * Test logp(Level, String, String, String, Throwable) with null level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logp", methodArgs = { + Level.class, String.class, String.class, String.class, + Throwable.class})}) public void testLogp_LevelStringStringStringThrowable_NullLevel() { // this.sharedLogger.setLevel(Level.OFF); try { @@ -2584,6 +3564,9 @@ public class LoggerTest extends TestCase { /* * Test logrb(Level, String, String, String, String) with normal values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, String.class})}) public void testLogrb_LevelStringStringString_Normal() { this.sharedLogger.setLevel(Level.INFO); this.sharedLogger.logrb(Level.INFO, "sourceClass", "sourceMethod", @@ -2616,6 +3599,9 @@ public class LoggerTest extends TestCase { /* * Test logrb(Level, String, String, String, String) with null message. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, String.class})}) public void testLogrb_LevelStringStringString_NullMsg() { this.sharedLogger.setLevel(Level.INFO); this.sharedLogger.logrb(Level.INFO, null, null, null, null); @@ -2634,8 +3620,10 @@ public class LoggerTest extends TestCase { /* * Test logrb(Level, String, String, String) with null level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, String.class})}) public void testLogrb_LevelStringStringString_NullLevel() { - // this.sharedLogger.setLevel(Level.OFF); try { this.sharedLogger.logrb(null, "sourceClass", "sourceMethod", VALID_RESOURCE_BUNDLE2, @@ -2649,6 +3637,9 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String) with invalid resource * bundle. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, String.class})}) public void testLogrb_LevelStringStringString_InvalidRes() { this.sharedLogger.setLevel(Level.ALL); this.sharedLogger.logrb(Level.ALL, "sourceClass", "sourceMethod", @@ -2672,6 +3663,10 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Object) with normal * values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Object.class})}) public void testLogrb_LevelStringStringStringObject_Normal() { Object param = new Object(); this.sharedLogger.setLevel(Level.INFO); @@ -2709,6 +3704,10 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Object) with null * message and object. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Object.class})}) public void testLogrb_LevelStringStringStringObject_NullMsgObj() { this.sharedLogger.setLevel(Level.INFO); this.sharedLogger.logrb(Level.INFO, null, null, null, null, @@ -2725,11 +3724,22 @@ public class LoggerTest extends TestCase { assertNull(r.getParameters()[0]); assertSame(r.getThrown(), null); } - + /** - * @tests java.util.logging.Logger#logrb(Level, String, String, String, - * String, Object) - */ + * java.util.logging.Logger#logrb(Level, String, String, String, String, + * Object) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Regression test.", + targets = { + @TestTarget( + methodName = "logrb", + methodArgs = {java.util.logging.Level.class, java.lang.String.class, + java.lang.String.class, java.lang.String.class, + java.lang.String.class} + ) + }) public void test_logrbLLevel_LString_LString_LObject_Security() throws Exception { // regression test for Harmony-1290 @@ -2746,6 +3756,10 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Object) with null * level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Object.class})}) public void testLogrb_LevelStringStringStringObject_NullLevel() { // this.sharedLogger.setLevel(Level.OFF); try { @@ -2762,6 +3776,10 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Object) with invalid * resource bundle. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Object.class})}) public void testLogrb_LevelStringStringStringObject_InvalidRes() { Object param = new Object(); this.sharedLogger.setLevel(Level.ALL); @@ -2787,6 +3805,11 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Object[]) with normal * values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Object[].class}) + }) public void testLogrb_LevelStringStringStringObjects_Normal() { Object[] params = new Object[2]; params[0] = new Object(); @@ -2827,6 +3850,11 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Object[]) with null * message and object. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Object[].class})}) public void testLogrb_LevelStringStringStringObjects_NullMsgObj() { this.sharedLogger.setLevel(Level.INFO); this.sharedLogger.logrb(Level.INFO, null, null, null, null, @@ -2847,17 +3875,20 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Object[]) with null * level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Object[].class}) + }) public void testLogrb_LevelStringStringStringObjects_NullLevel() { - // this.sharedLogger.setLevel(Level.OFF); try { - this.sharedLogger - .logrb( - null, - "sourceClass", - "sourceMethod", - VALID_RESOURCE_BUNDLE2, - "logrb(Level, String, String, String, String, Object[]) msg", - new Object[0]); + this.sharedLogger.logrb( + null, + "sourceClass", + "sourceMethod", + VALID_RESOURCE_BUNDLE2, + "logrb(Level, String, String, String, String, Object[]) msg", + new Object[0]); fail("Should throw NullPointerException!"); } catch (NullPointerException e) { } @@ -2867,6 +3898,11 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Object[]) with invalid * resource bundle. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Object[].class})}) public void testLogrb_LevelStringStringStringObjects_InvalidRes() { Object[] params = new Object[2]; params[0] = new Object(); @@ -2895,6 +3931,11 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Throwable) with normal * values. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Throwable.class})}) public void testLogrb_LevelStringStringStringThrowable_Normal() { Throwable t = new Throwable(); this.sharedLogger.setLevel(Level.INFO); @@ -2932,6 +3973,11 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Throwable) with null * message and throwable. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Throwable.class})}) public void testLogrb_LevelStringTStringStringhrowable_NullMsgObj() { this.sharedLogger.setLevel(Level.INFO); this.sharedLogger.logrb(Level.INFO, null, null, null, null, @@ -2952,17 +3998,21 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Throwable) with null * level. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Throwable.class}) + }) public void testLogrb_LevelStringStringStringThrowable_NullLevel() { // this.sharedLogger.setLevel(Level.OFF); try { - this.sharedLogger - .logrb( - null, - "sourceClass", - "sourceMethod", - VALID_RESOURCE_BUNDLE2, - "log(Level, String, String, String, String, Throwable) msg", - new Throwable()); + this.sharedLogger.logrb( + null, + "sourceClass", + "sourceMethod", + VALID_RESOURCE_BUNDLE2, + "log(Level, String, String, String, String, Throwable) msg", + new Throwable()); fail("Should throw NullPointerException!"); } catch (NullPointerException e) { } @@ -2972,6 +4022,11 @@ public class LoggerTest extends TestCase { * Test logrb(Level, String, String, String, String, Throwable) with invalid * resource bundle. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "logrb", methodArgs = { + Level.class, String.class, String.class, String.class, + String.class, Throwable.class}) + }) public void testLogrb_LevelStringStringStringThrowable_InvalidRes() { Throwable t = new Throwable(); this.sharedLogger.setLevel(Level.ALL); @@ -2982,7 +4037,7 @@ public class LoggerTest extends TestCase { assertTrue(CallVerificationStack.getInstance().empty()); assertSame(r.getLoggerName(), this.sharedLogger.getName()); assertEquals(r.getMessage(), - "logrb(Level, String, String, String, String) msg"); + "logrb(Level, String, String, String, String) msg"); assertSame(r.getResourceBundleName(), INVALID_RESOURCE_BUNDLE); assertSame(r.getResourceBundle(), null); assertSame(r.getSourceClassName(), "sourceClass"); @@ -2996,9 +4051,12 @@ public class LoggerTest extends TestCase { * Test log(LogRecord) for a normal log record. Meanwhile the logger has an * appropriate level, no filter, no parent. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "log", methodArgs = {LogRecord.class}) + }) public void testLog_LogRecord_AppropriateLevelNoFilterNoParent() { LogRecord r = new LogRecord(Level.INFO, - "testLog_LogRecord_AppropriateLevelNoFilterNoParent"); + "testLog_LogRecord_AppropriateLevelNoFilterNoParent"); this.sharedLogger.setLevel(Level.INFO); this.sharedLogger.log(r); @@ -3007,7 +4065,7 @@ public class LoggerTest extends TestCase { assertTrue(CallVerificationStack.getInstance().empty()); assertSame(r.getLoggerName(), null); assertEquals(r.getMessage(), - "testLog_LogRecord_AppropriateLevelNoFilterNoParent"); + "testLog_LogRecord_AppropriateLevelNoFilterNoParent"); assertSame(r.getResourceBundleName(), null); assertSame(r.getSourceClassName(), null); assertSame(r.getSourceMethodName(), null); @@ -3019,6 +4077,9 @@ public class LoggerTest extends TestCase { /* * Test log(LogRecord) with null log record. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + @TestTarget(methodName = "log", methodArgs = {LogRecord.class}) + }) public void testLog_LogRecord_Null() { this.sharedLogger.setLevel(Level.INFO); try { @@ -3032,6 +4093,9 @@ public class LoggerTest extends TestCase { * Test log(LogRecord) for a normal log record. Meanwhile the logger has an * inappropriate level, no filter, no parent. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_LogRecord_InppropriateLevelNoFilterNoParent() { LogRecord r = new LogRecord(Level.INFO, "testLog_LogRecord_InppropriateLevelNoFilterNoParent"); @@ -3050,6 +4114,9 @@ public class LoggerTest extends TestCase { * Test log(LogRecord) for a normal log record. Meanwhile the logger has an * appropriate level, a filter that accepts the fed log record, no parent. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_LogRecord_AppropriateLevelTrueFilterNoParent() { LogRecord r = new LogRecord(Level.INFO, "testLog_LogRecord_AppropriateLevelTrueFilterNoParent"); @@ -3078,6 +4145,9 @@ public class LoggerTest extends TestCase { * Test log(LogRecord) for a normal log record. Meanwhile the logger has an * appropriate level, a filter that rejects the fed log record, no parent. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_LogRecord_AppropriateLevelFalseFilterNoParent() { LogRecord r = new LogRecord(Level.INFO, "testLog_LogRecord_AppropriateLevelFalseFilterNoParent"); @@ -3105,6 +4175,9 @@ public class LoggerTest extends TestCase { * Test that the parent's handler is notified for a new log record when * getUseParentHandlers() is true. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_ParentInformed() { Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE); Logger parent = new MockParentLogger("parentLogger", @@ -3157,6 +4230,9 @@ public class LoggerTest extends TestCase { * Test that the ancestor's handler is notified for a new log record when * getUseParentHandlers() is true. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_AncestorInformed() { Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE); Logger parent = new MockParentLogger("parentLogger", @@ -3203,6 +4279,9 @@ public class LoggerTest extends TestCase { * Test that the parent's handler is notified for a new log record when * getUseParentHandlers() is false. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_ParentNotInformed() { Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE); Logger parent = new MockParentLogger("parentLogger", @@ -3223,6 +4302,9 @@ public class LoggerTest extends TestCase { * Test that a logger with null level and no parent. Defaulted to * Level.INFO. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_NullLevelNoParent() { LogRecord r = new LogRecord(Level.INFO, "testLog_NullLevelNoParent"); assertNull(this.sharedLogger.getLevel()); @@ -3248,6 +4330,9 @@ public class LoggerTest extends TestCase { /* * Test that a logger inherits its parent level when its level is null. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_NullLevelHasParent() { Logger child = new MockLogger("childLogger", VALID_RESOURCE_BUNDLE); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -3300,6 +4385,9 @@ public class LoggerTest extends TestCase { * Test that a logger with null resource bundle and no parent. Defaulted to * null. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_NullResNoParent() { Logger log = new MockLogger("Logger", null); log.addHandler(new MockHandler()); @@ -3321,6 +4409,9 @@ public class LoggerTest extends TestCase { * Test that a logger inherits its parent resource bundle when its resource * bundle is null. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_NullResHasParent() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", VALID_RESOURCE_BUNDLE2); @@ -3351,6 +4442,9 @@ public class LoggerTest extends TestCase { * Test that a logger inherits its ancestor's resource bundle when its * resource bundle and its parent's resource bundle are both null. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_NullResHasAncestor() { Logger child = new MockLogger("childLogger", null); Logger parent = new MockLogger("parentLogger", null); @@ -3383,6 +4477,9 @@ public class LoggerTest extends TestCase { /* * Test when one handler throws an exception. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", targets = { + + @TestTarget(methodName = "log", methodArgs = {LogRecord.class})}) public void testLog_ExceptionalHandler() { MockLogger l = new MockLogger("testLog_ExceptionalHandler", null); l.addHandler(new MockExceptionalHandler()); @@ -3398,6 +4495,10 @@ public class LoggerTest extends TestCase { /* * Test whether privileged code is used to load resource bundles. */ + @TestInfo(level = TestLevel.COMPLETE, purpose = "", + targets = { + @TestTarget(methodName = "getAnonymousLogger", methodArgs = {String.class}) + }) public void testLoadResourceBundle() { // SecurityManager oldMan = System.getSecurityManager(); @@ -3408,24 +4509,22 @@ public class LoggerTest extends TestCase { System.setSecurityManager(oldMan); } } - - public void testLoadResourceBundleNonExistent() { - try { - // Try a load a non-existent resource bundle. - LoggerExtension.loadResourceBundle("missinglogger.properties"); - fail("Expected an exception."); - } catch (MissingResourceException ex) { - // Expected exception is precisely a MissingResourceException - assertTrue(ex.getClass() == MissingResourceException.class); - } - } - + + /** - * @tests java.util.logging.Logger#logrb(Level, String, String, String, - * String, Object) - */ - public void test_init_logger() - throws Exception { + * java.util.logging.Logger#logrb(Level, String, String, String, String, + * Object) + */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "", + targets = { + @TestTarget( + methodName = "getLogger", + methodArgs = {java.lang.String.class} + ) + }) + public void _test_init_logger() throws Exception { Properties p = new Properties(); p.put("testGetLogger_Normal_ANewLogger2.level", "ALL"); LogManager.getLogManager().readConfiguration( @@ -3435,40 +4534,28 @@ public class LoggerTest extends TestCase { "testGetLogger_Normal_ANewLogger2")); SecurityManager originalSecurityManager = System.getSecurityManager(); try { - System.setSecurityManager(new MockSecurityManagerOtherPermission()); + System.setSecurityManager(new MockSecurityManager()); // should not throw expection - Logger logger = Logger.getLogger("testGetLogger_Normal_ANewLogger2"); + Logger logger = Logger + .getLogger("testGetLogger_Normal_ANewLogger2"); // should throw exception - try{ + try { logger.setLevel(Level.ALL); fail("should throw SecurityException"); - } catch (SecurityException e){ + } catch (SecurityException e) { // expected } - try{ - logger.setParent(Logger.getLogger("root")); + try { + logger.setParent(Logger.getLogger("")); fail("should throw SecurityException"); - } catch (SecurityException e){ + } catch (SecurityException e) { // expected } } finally { System.setSecurityManager(originalSecurityManager); } } - - /* - * test initHandler - */ - public void test_initHandler() throws Exception { - File logProps = new File(LOGGING_CONFIG_FILE); - LogManager lm = LogManager.getLogManager(); - lm.readConfiguration(new FileInputStream(logProps)); - Logger log = Logger.getLogger(""); - // can log properly - Handler[] handlers = log.getHandlers(); - assertEquals(2, handlers.length); - } /* * A mock logger, used to test the protected constructors and fields. @@ -3584,35 +4671,6 @@ public class LoggerTest extends TestCase { } } - public static class MockSecurityManagerOtherPermission extends - SecurityManager { - - public void checkPermission(Permission permission, Object context) { - if (permission instanceof LoggingPermission) { - if (!permission.getName().equals("control")) { - throw new SecurityException(); - } - return; - } - if (permission.getName().equals("setSecurityManager")) { - return; - } - throw new SecurityException(); - } - - public void checkPermission(Permission permission) { - if (permission instanceof LoggingPermission) { - if (!permission.getName().equals("control")) { - throw new SecurityException(); - } - return; - } - if (permission.getName().equals("setSecurityManager")) { - return; - } - throw new SecurityException(); - } - } /* * A mock filter, always return false. diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggingMXBeanTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggingMXBeanTest.java new file mode 100644 index 0000000..cfbf213 --- /dev/null +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggingMXBeanTest.java @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.harmony.logging.tests.java.util.logging; + +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestLevel; + +import junit.framework.TestCase; + +import tests.util.CallVerificationStack; + +import java.util.List; +import java.util.logging.LoggingMXBean; +/** + * This testcase verifies the signature of the interface Filter. + * + */ +@TestTargetClass(LoggingMXBean.class) +public class LoggingMXBeanTest extends TestCase { + + private MockLoggingMXBean m = null; + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + m = new MockLoggingMXBean(); + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + + + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getLoggerLevel", + methodArgs = {String.class} + ) + }) + public void testGetLoggerLevel() { + assertNull(m.getLoggerLevel(null)); + } + + + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getLoggerNames", + methodArgs = {} + ) + }) + public void testGetLoggerNames() { + assertNull(m.getLoggerNames()); + } + + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "getParentLoggerName", + methodArgs = {String.class} + ) + }) + public void testGetParentLoggerName() { + assertNull(m.getParentLoggerName(null)); + } + + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "setLoggerLevel", + methodArgs = {String.class, String.class} + ) + }) + public void testSetLoggerLevel() { + try{ + m.setLoggerLevel(null,null); + } + catch (Exception e){ + throw new AssertionError(); + } + } + + /* + * This inner class implements the interface Filter to verify the signature. + */ + private class MockLoggingMXBean implements LoggingMXBean { + + public String getLoggerLevel(String loggerName) { + return null; + } + + public List<String> getLoggerNames() { + return null; + } + + public String getParentLoggerName(String loggerName) { + return null; + } + + public void setLoggerLevel(String loggerName, String levelName) { + + } + + + } +} diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.java index cd3eee9..bc82d65 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LoggingPermissionTest.java @@ -17,17 +17,33 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + import java.util.logging.LoggingPermission; import junit.framework.TestCase; import org.apache.harmony.testframework.serialization.SerializationTest; +@TestTargetClass(LoggingPermission.class) public class LoggingPermissionTest extends TestCase { /** * @tests serialization/deserialization compatibility. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + + @TestTarget( + methodName = "!SerializationSelf", + methodArgs = {} + ) + }) public void testSerializationSelf() throws Exception { SerializationTest.verifySelf(new LoggingPermission("control", "")); } @@ -35,12 +51,32 @@ public class LoggingPermissionTest extends TestCase { /** * @tests serialization/deserialization compatibility with RI. */ + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + + @TestTarget( + methodName = "!SerializationGolden", + methodArgs = {} + ) + }) public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new LoggingPermission("control", "")); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + + @TestTarget( + methodName = "LoggingPermission", + methodArgs = {String.class, String.class} + ) + }) public void testLoggingPermission() { try { new LoggingPermission(null, null); diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/MemoryHandlerTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/MemoryHandlerTest.java index 4a6b52c..eda7514 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/MemoryHandlerTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/MemoryHandlerTest.java @@ -17,12 +17,18 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.io.StringWriter; import java.security.Permission; import java.util.Properties; +import java.util.ResourceBundle; import java.util.logging.Filter; import java.util.logging.Formatter; import java.util.logging.Handler; @@ -41,6 +47,7 @@ import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper /** * */ +@TestTargetClass(MemoryHandler.class) public class MemoryHandlerTest extends TestCase { final static LogManager manager = LogManager.getLogManager(); @@ -100,7 +107,41 @@ public class MemoryHandlerTest extends TestCase { System.setErr(err); } - public void testSecurity() { + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "SecurityException", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ), + @TestTarget( + methodName = "setPushLevel", + methodArgs = {Level.class} + ), + @TestTarget( + methodName = "flush", + methodArgs = {} + ), + @TestTarget( + methodName = "push", + methodArgs = {} + ), + @TestTarget( + methodName = "getPushLevel", + methodArgs = {} + ), + @TestTarget( + methodName = "isLoggable", + methodArgs = {LogRecord.class} + ), + @TestTarget( + methodName = "publish", + methodArgs = {LogRecord.class} + ) + + }) + public void testGlobalSecurity() { SecurityManager currentManager = System.getSecurityManager(); System.setSecurityManager(securityManager); try { @@ -125,6 +166,15 @@ public class MemoryHandlerTest extends TestCase { } + @TestInfo( + level = TestLevel.PARTIAL, + purpose = "not a good test, try to improve", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) public void testClose() { Filter filter = handler.getFilter(); Formatter formatter = handler.getFormatter(); @@ -140,6 +190,15 @@ public class MemoryHandlerTest extends TestCase { assertFalse(handler.isLoggable(new LogRecord(Level.SEVERE, "test"))); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "not a good test, try to improve", + targets = { + @TestTarget( + methodName = "flush", + methodArgs = {} + ) + }) public void testFlush() { Filter filter = handler.getFilter(); Formatter formatter = handler.getFormatter(); @@ -155,6 +214,15 @@ public class MemoryHandlerTest extends TestCase { assertTrue(handler.isLoggable(new LogRecord(Level.SEVERE, "test"))); } + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "", + targets = { + @TestTarget( + methodName = "isLoggable", + methodArgs = {LogRecord.class} + ) + }) public void testIsLoggable() { try { handler.isLoggable(null); @@ -165,9 +233,13 @@ public class MemoryHandlerTest extends TestCase { LogRecord record = new LogRecord(Level.FINER, "MSG1"); assertFalse(handler.isLoggable(record)); + record = new LogRecord(Level.FINE, "MSG2"); assertTrue(handler.isLoggable(record)); - + assertTrue(handler.isLoggable(new LogRecord(Level.INFO, "1"))); + assertTrue(handler.isLoggable(new LogRecord(Level.WARNING, "2"))); + assertTrue(handler.isLoggable(new LogRecord(Level.SEVERE, "3"))); + record = new LogRecord(Level.CONFIG, "MSG3"); assertTrue(handler.isLoggable(record)); @@ -182,7 +254,15 @@ public class MemoryHandlerTest extends TestCase { /* * Class under test for void MemoryHandler() */ - public void testMemoryHandler() { + @TestInfo + (level = TestLevel.PARTIAL, + purpose = "check errors", + targets = + { + @TestTarget(methodName = "MemoryHandler", methodArgs = {}) + } + ) + public void testMemoryHandler() throws IOException { assertNotNull("Filter should not be null", handler.getFilter()); assertNotNull("Formatter should not be null", handler.getFormatter()); assertNull("character encoding should be null", handler.getEncoding()); @@ -191,8 +271,31 @@ public class MemoryHandlerTest extends TestCase { assertEquals("Level should be FINE", Level.FINE, handler.getLevel()); assertEquals("Level should be WARNING", Level.WARNING, handler .getPushLevel()); + + props.clear(); + props.put("java.util.logging.MemoryHandler.target", baseClassName + + "$MockHandler"); + + manager.readConfiguration(EnvironmentHelper + .PropertiesToInputStream(props)); + handler = new MemoryHandler(); + assertNull(handler.getFilter()); + assertTrue(handler.getFormatter() instanceof SimpleFormatter); + assertNull(handler.getEncoding()); + assertNotNull(handler.getErrorManager()); + assertEquals(handler.getLevel(), Level.ALL); + assertEquals(handler.getPushLevel(), Level.SEVERE); + } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "MemoryHandler", methodArgs = {}) + } + ) public void testMemoryHandlerInvalidProps() throws IOException { // null target try { @@ -260,6 +363,14 @@ public class MemoryHandlerTest extends TestCase { } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "MemoryHandler", methodArgs = {}) + } + ) public void testMemoryHandlerDefaultValue() throws SecurityException, IOException { props.clear(); @@ -280,6 +391,14 @@ public class MemoryHandlerTest extends TestCase { /* * Class under test for void MemoryHandler(Handler, int, Level) */ + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "MemoryHandler", methodArgs = {Handler.class, int.class, Level.class}) + } + ) public void testMemoryHandlerHandlerintLevel() { handler = new MemoryHandler(target, 2, Level.FINEST); assertNotNull("Filter should not be null", handler.getFilter()); @@ -314,6 +433,14 @@ public class MemoryHandlerTest extends TestCase { } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "getPushLevel", methodArgs = {}) + } + ) public void testGetPushLevel() { try { handler.setPushLevel(null); @@ -324,6 +451,14 @@ public class MemoryHandlerTest extends TestCase { assertEquals(handler.getPushLevel(), Level.parse("123")); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "setPushLevel", methodArgs = {Level.class}) + } + ) public void testSetPushLevel() { // change push level don't trigger push action writer.getBuffer().setLength(0); @@ -331,7 +466,6 @@ public class MemoryHandlerTest extends TestCase { assertTrue(handler.isLoggable(lr)); handler.publish(lr); assertEquals(writer.toString(), ""); - // assertEquals(writer.toString(), "flush"); writer.getBuffer().setLength(0); handler.setPushLevel(Level.FINE); assertEquals(writer.toString(), ""); @@ -339,6 +473,14 @@ public class MemoryHandlerTest extends TestCase { assertEquals(writer.toString(), lr.getMessage() + lr.getMessage()); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "push", methodArgs = {}) + } + ) public void testPushPublic() { writer.getBuffer().setLength(0); // loggable but don't trig push diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/MessagesTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/MessagesTest.java new file mode 100644 index 0000000..ff6c0ce --- /dev/null +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/MessagesTest.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + + +package org.apache.harmony.logging.tests.java.util.logging; + +import junit.framework.TestCase; + +import org.apache.harmony.logging.internal.nls.Messages; + +import java.io.OutputStream; +import java.io.PrintStream; +import java.util.logging.ErrorManager; + +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + + + +@TestTargetClass(Messages.class) +public class MessagesTest extends TestCase{ + + + private Messages m = null; + + public void setUp() throws Exception{ + super.setUp(); + m = new Messages(); + + } + + public void tearDown() throws Exception{ + super.tearDown(); + } + + + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Just check signature, cannot make use of mock, " + + "method depend on luni", + targets = { + @TestTarget( + methodName = "getString", + methodArgs = {java.lang.String.class} + ) + }) + public void testGetString_String() { + m.getString(new String()); + } + + @TestInfo( + level = TestLevel.COMPLETE, + purpose = "Juste check signature, cannot make use of mock, depend on luni", + targets = { + @TestTarget( + methodName = "getString", + methodArgs = {java.lang.String.class, Object.class} + ) + }) + public void testGetString_StringObject() { + m.getString(new String(),new Object()); + + } + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Juste check signature, cannot make use of mock, depend on luni", + targets = { + @TestTarget( + methodName = "getString", + methodArgs = {java.lang.String.class, int.class} + ) + }) + public void testGetString_StringInt() { + m.getString(new String(),0); + } + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Juste check signature, cannot make use of mock, depend on luni", + targets = { + @TestTarget( + methodName = "getString", + methodArgs = {java.lang.String.class, char.class} + ) + }) + public void testGetString_StringChar() { + m.getString(new String(), 'a'); + } + + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Juste check signature, cannot make use of mock, depend on luni", + targets = { + @TestTarget( + methodName = "getString", + methodArgs = {java.lang.String.class, Object.class, Object.class} + ) + }) + public void testGetString_StringObjectObject() { + m.getString(new String(), new Object(), new Object() ); + } + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Juste check signature, cannot make use of mock, depend on luni", + targets = { + @TestTarget( + methodName = "getString", + methodArgs = {java.lang.String.class, Object[].class} + ) + }) + public void testGetString_StringObjectArray() { + m.getString(new String(), new Object[1]); + } + + + +} diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/SimpleFormatterTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/SimpleFormatterTest.java index 65111af..bc9990c 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/SimpleFormatterTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/SimpleFormatterTest.java @@ -17,10 +17,17 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + import java.util.Calendar; import java.util.ResourceBundle; +import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; +import java.util.logging.MemoryHandler; import java.util.logging.SimpleFormatter; import junit.framework.TestCase; @@ -28,6 +35,7 @@ import junit.framework.TestCase; /** * */ +@TestTargetClass(SimpleFormatter.class) public class SimpleFormatterTest extends TestCase { SimpleFormatter sf; @@ -48,13 +56,30 @@ public class SimpleFormatterTest extends TestCase { /* * test for constructor protected SimpleFormatter */ + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "SimpleFormatter", methodArgs = {}), + @TestTarget(methodName = "getHead", methodArgs = {Handler.class}), + @TestTarget(methodName = "getTail", methodArgs = {Handler.class}) + } + ) public void testSimpleFormatter() { assertEquals("Head for this SimpleFormatter should be empty", "", sf .getHead(null)); assertEquals("Tail for this SimpleFormatter should be empty", "", sf .getTail(null)); } - + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "format", methodArgs = {LogRecord.class}) + } + ) public void testFormatNull() { try { sf.format(null); @@ -64,6 +89,14 @@ public class SimpleFormatterTest extends TestCase { sf.format(new LogRecord(Level.SEVERE, null)); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "format", methodArgs = {LogRecord.class}) + } + ) public void testLocalizedFormat() { // if bundle set, should use localized message ResourceBundle rb = ResourceBundle @@ -83,6 +116,14 @@ public class SimpleFormatterTest extends TestCase { assertTrue(str.indexOf(localeMsg) < 0); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "format", methodArgs = {LogRecord.class}) + } + ) public void testFormat() { String str = sf.format(lr); Throwable t; @@ -114,10 +155,26 @@ public class SimpleFormatterTest extends TestCase { assertTrue(str.indexOf(Level.FINE.getLocalizedName()) > 0); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "getHead", methodArgs = {Handler.class}) + } + ) public void testGetHead() { assertEquals("", sf.getHead(null)); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "getTail", methodArgs = {Handler.class}) + } + ) public void testGetTail() { assertEquals("", sf.getTail(null)); } diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/SocketHandlerTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/SocketHandlerTest.java index 75915e7..6d5f280 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/SocketHandlerTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/SocketHandlerTest.java @@ -17,6 +17,11 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -33,6 +38,7 @@ import java.util.logging.Level; import java.util.logging.LogManager; import java.util.logging.LogRecord; import java.util.logging.LoggingPermission; +import java.util.logging.SimpleFormatter; import java.util.logging.SocketHandler; import java.util.logging.XMLFormatter; @@ -46,6 +52,7 @@ import tests.util.CallVerificationStack; /** * Test class java.util.logging.ConsoleHandler */ +@TestTargetClass(SocketHandler.class) public class SocketHandlerTest extends TestCase { private static final LogManager LOG_MANAGER = LogManager.getLogManager(); @@ -75,21 +82,7 @@ public class SocketHandlerTest extends TestCase { * @see TestCase#tearDown() */ protected void tearDown() throws Exception { - initProps(); - LOG_MANAGER.reset(); - LOG_MANAGER.readConfiguration(EnvironmentHelper - .PropertiesToInputStream(props)); - CallVerificationStack.getInstance().clear(); - if (null != h) { - h.close(); - h = null; - } - System.setErr(err); - super.tearDown(); - } - - - private void initProps() throws Exception { + //initProps props = new Properties(); props.put("handlers", className + "$MockHandler " + className + "$MockHandler"); @@ -105,11 +98,38 @@ public class SocketHandlerTest extends TestCase { props.put("foo.handlers", "java.util.logging.ConsoleHandler"); props.put("foo.level", "WARNING"); props.put("com.xyz.foo.level", "SEVERE"); + + + LOG_MANAGER.reset(); + LOG_MANAGER.readConfiguration(EnvironmentHelper + .PropertiesToInputStream(props)); + CallVerificationStack.getInstance().clear(); + if (null != h) { + h.close(); + h = null; + } + System.setErr(err); + super.tearDown(); } + /* * Test the constructor with no relevant log manager properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with no relevant log manager " + + "properties are set.", + targets = { + @TestTarget( + methodName = "SocketHandler", + methodArgs = {} + ), + @TestTarget( + methodName = "SocketHandler", + methodArgs = {java.lang.String.class, int.class} + ) + }) public void testConstructor_NoProperties() throws Exception { assertNull(LOG_MANAGER.getProperty( "java.util.logging.SocketHandler.level")); @@ -185,6 +205,20 @@ public class SocketHandlerTest extends TestCase { * Test the constructor with no relevant log manager properties are set * except host and port. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with no relevant log manager " + + "properties are set except host and port.", + targets = { + @TestTarget( + methodName = "SocketHandler", + methodArgs = {} + ), + @TestTarget( + methodName = "SocketHandler", + methodArgs = {java.lang.String.class, int.class} + ) + }) public void testConstructor_NoBasicProperties() throws Exception { assertNull(LOG_MANAGER.getProperty( "java.util.logging.SocketHandler.level")); @@ -224,6 +258,19 @@ public class SocketHandlerTest extends TestCase { /* * Test the constructor with insufficient privilege for connection. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies SecurityException.", + targets = { + @TestTarget( + methodName = "SocketHandler", + methodArgs = {} + ), + @TestTarget( + methodName = "SocketHandler", + methodArgs = {java.lang.String.class, int.class} + ) + }) public void testConstructor_InsufficientPrivilege() throws Exception { SecurityManager oldMan = null; Properties p = new Properties(); @@ -260,6 +307,20 @@ public class SocketHandlerTest extends TestCase { /* * Test the constructor with valid relevant log manager properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with valid relevant log manager " + + "properties are set.", + targets = { + @TestTarget( + methodName = "SocketHandler", + methodArgs = {} + ), + @TestTarget( + methodName = "SocketHandler", + methodArgs = {java.lang.String.class, int.class} + ) + }) public void testConstructor_ValidProperties() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.level", "FINE"); @@ -306,6 +367,20 @@ public class SocketHandlerTest extends TestCase { * Test the constructor with invalid relevant log manager properties are set * except host and port. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with invalid relevant log manager " + + "properties are set except host and port.", + targets = { + @TestTarget( + methodName = "SocketHandler", + methodArgs = {} + ), + @TestTarget( + methodName = "SocketHandler", + methodArgs = {java.lang.String.class, int.class} + ) + }) public void testConstructor_InvalidBasicProperties() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.level", INVALID_LEVEL); @@ -354,6 +429,15 @@ public class SocketHandlerTest extends TestCase { * Test the constructor with valid relevant log manager properties are set * except port. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IllegalArgumentException.", + targets = { + @TestTarget( + methodName = "SocketHandler", + methodArgs = {} + ) + }) public void testConstructor_InvalidPort() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.level", "FINE"); @@ -379,6 +463,20 @@ public class SocketHandlerTest extends TestCase { * Test the constructor with valid relevant log manager properties are set, * but the port is not open. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that the constructor with valid relevant log manager " + + "properties are set, but the port is not open.", + targets = { + @TestTarget( + methodName = "SocketHandler", + methodArgs = {} + ), + @TestTarget( + methodName = "SocketHandler", + methodArgs = {java.lang.String.class, int.class} + ) + }) public void testConstructor_NotOpenPort() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.level", "FINE"); @@ -411,6 +509,19 @@ public class SocketHandlerTest extends TestCase { * Test the constructor with valid relevant log manager properties are set * except port. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies IOException.", + targets = { + @TestTarget( + methodName = "SocketHandler", + methodArgs = {} + ), + @TestTarget( + methodName = "SocketHandler", + methodArgs = {java.lang.String.class, int.class} + ) + }) public void testConstructor_InvalidHost() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.level", "FINE"); @@ -443,6 +554,16 @@ public class SocketHandlerTest extends TestCase { * Test close() when having sufficient privilege, and a record has been * written to the output stream. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies close() when having sufficient privilege, " + + "and a record has been written to the output stream.", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) public void testClose_SufficientPrivilege_NormalClose() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.formatter", className @@ -471,6 +592,15 @@ public class SocketHandlerTest extends TestCase { * Test close() when having sufficient privilege, and no record has been * written to the output stream. */ + @TestInfo + (level = TestLevel.PARTIAL_OK, + purpose = "Verifies close() when having sufficient privilege, " + + "and no record has been written to the output stream.", + targets = + { + @TestTarget(methodName = "close", methodArgs = {}) + } + ) public void testClose_SufficientPrivilege_DirectClose() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.formatter", className @@ -496,6 +626,14 @@ public class SocketHandlerTest extends TestCase { /* * Test close() when having insufficient privilege. */ + @TestInfo + (level = TestLevel.PARTIAL_OK, + purpose = "Verifies close() when having insufficient privilege.", + targets = + { + @TestTarget(methodName = "close", methodArgs = {}) + } + ) public void testClose_InsufficientPrivilege() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.formatter", className @@ -530,6 +668,16 @@ public class SocketHandlerTest extends TestCase { /* * Test publish(), use no filter, having output stream, normal log record. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), use no filter, having output stream, " + + "normal log record.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_NoFilter() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.formatter", className @@ -569,6 +717,16 @@ public class SocketHandlerTest extends TestCase { /* * Test publish(), use a filter, having output stream, normal log record. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), use a filter, having output stream, " + + "normal log record.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_WithFilter() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.formatter", className @@ -599,6 +757,15 @@ public class SocketHandlerTest extends TestCase { /* * Test publish(), null log record, having output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), null log record, having output stream.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_Null() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.formatter", className @@ -626,6 +793,16 @@ public class SocketHandlerTest extends TestCase { /* * Test publish(), a log record with empty msg, having output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish() method, a log record with empty msg, " + + "having output stream.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_EmptyMsg() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.formatter", className @@ -651,6 +828,16 @@ public class SocketHandlerTest extends TestCase { /* * Test publish(), a log record with null msg, having output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), a log record with null msg, " + + "having output stream.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_NullMsg() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.formatter", className @@ -676,6 +863,15 @@ public class SocketHandlerTest extends TestCase { /* * Test publish(), after close. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish() method after close.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_AfterClose() throws Exception { Properties p = new Properties(); p.put("java.util.logging.SocketHandler.formatter", className diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/StreamHandlerTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/StreamHandlerTest.java index ba9d775..6149f06 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/StreamHandlerTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/StreamHandlerTest.java @@ -17,6 +17,8 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.*; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -37,6 +39,7 @@ import java.util.logging.LogManager; import java.util.logging.LogRecord; import java.util.logging.LoggingPermission; import java.util.logging.SimpleFormatter; +import java.util.logging.SocketHandler; import java.util.logging.StreamHandler; import junit.framework.TestCase; @@ -48,6 +51,7 @@ import tests.util.CallVerificationStack; /** * Test the class StreamHandler. */ +@TestTargetClass(StreamHandler.class) public class StreamHandlerTest extends TestCase { private final static String INVALID_LEVEL = "impossible_level"; @@ -89,6 +93,16 @@ public class StreamHandlerTest extends TestCase { * Test the constructor with no parameter, and no relevant log manager * properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with no parameter, " + + "and no relevant log manager properties are set.", + targets = { + @TestTarget( + methodName = "StreamHandler", + methodArgs = {} + ) + }) public void testConstructor_NoParameter_NoProperties() { assertNull(LogManager.getLogManager().getProperty( "java.util.logging.StreamHandler.level")); @@ -109,6 +123,15 @@ public class StreamHandlerTest extends TestCase { /* * Test the constructor with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with insufficient privilege.", + targets = { + @TestTarget( + methodName = "StreamHandler", + methodArgs = {java.io.OutputStream.class, java.util.logging.Formatter.class} + ) + }) public void testConstructor_NoParameter_InsufficientPrivilege() { assertNull(LogManager.getLogManager().getProperty( "java.util.logging.StreamHandler.level")); @@ -137,6 +160,16 @@ public class StreamHandlerTest extends TestCase { * Test the constructor with no parameter, and valid relevant log manager * properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with no parameter, and valid " + + "relevant log manager properties are set.", + targets = { + @TestTarget( + methodName = "StreamHandler", + methodArgs = {} + ) + }) public void testConstructor_NoParameter_ValidProperties() throws Exception { Properties p = new Properties(); p.put("java.util.logging.StreamHandler.level", "FINE"); @@ -163,6 +196,16 @@ public class StreamHandlerTest extends TestCase { * Test the constructor with no parameter, and invalid relevant log manager * properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with no parameter, and invalid " + + "relevant log manager properties are set.", + targets = { + @TestTarget( + methodName = "StreamHandler", + methodArgs = {} + ) + }) public void testConstructor_NoParameter_InvalidProperties() throws Exception { Properties p = new Properties(); @@ -191,6 +234,17 @@ public class StreamHandlerTest extends TestCase { * Test the constructor with normal parameter values, and no relevant log * manager properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with normal parameter values, " + + "and no relevant log manager properties are set.", + targets = { + @TestTarget( + methodName = "StreamHandler", + methodArgs = {java.io.OutputStream.class, + java.util.logging.Formatter.class} + ) + }) public void testConstructor_HasParameters_NoProperties() { assertNull(LogManager.getLogManager().getProperty( "java.util.logging.StreamHandler.level")); @@ -212,6 +266,16 @@ public class StreamHandlerTest extends TestCase { /* * Test the constructor with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with insufficient privilege.", + targets = { + @TestTarget( + methodName = "StreamHandler", + methodArgs = {java.io.OutputStream.class, + java.util.logging.Formatter.class} + ) + }) public void testConstructor_HasParameter_InsufficientPrivilege() { assertNull(LogManager.getLogManager().getProperty( "java.util.logging.StreamHandler.level")); @@ -241,6 +305,16 @@ public class StreamHandlerTest extends TestCase { * Test the constructor with normal parameter values, and valid relevant log * manager properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with normal parameter values, " + + "and valid relevant log manager properties are set.", + targets = { + @TestTarget( + methodName = "StreamHandler", + methodArgs = {java.io.OutputStream.class, java.util.logging.Formatter.class} + ) + }) public void testConstructor_HasParameters_ValidProperties() throws Exception { Properties p = new Properties(); @@ -269,6 +343,16 @@ public class StreamHandlerTest extends TestCase { * Test the constructor with normal parameter, and invalid relevant log * manager properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with normal parameter, " + + "and invalid relevant log manager properties are set.", + targets = { + @TestTarget( + methodName = "StreamHandler", + methodArgs = {java.io.OutputStream.class, java.util.logging.Formatter.class} + ) + }) public void testConstructor_HasParameters_InvalidProperties() throws Exception { Properties p = new Properties(); @@ -295,6 +379,16 @@ public class StreamHandlerTest extends TestCase { * Test the constructor with null formatter, and invalid relevant log manager * properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with null formatter, " + + "and invalid relevant log manager properties are set.", + targets = { + @TestTarget( + methodName = "StreamHandler", + methodArgs = {java.io.OutputStream.class, java.util.logging.Formatter.class} + ) + }) public void testConstructor_HasParameters_ValidPropertiesNullStream() throws Exception { Properties p = new Properties(); @@ -323,6 +417,16 @@ public class StreamHandlerTest extends TestCase { * Test the constructor with null output stream, and invalid relevant log * manager properties are set. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies the constructor with null output stream, " + + "and invalid relevant log manager properties are set.", + targets = { + @TestTarget( + methodName = "StreamHandler", + methodArgs = {java.io.OutputStream.class, java.util.logging.Formatter.class} + ) + }) public void testConstructor_HasParameters_ValidPropertiesNullFormatter() throws Exception { Properties p = new Properties(); @@ -351,6 +455,16 @@ public class StreamHandlerTest extends TestCase { * Test close() when having sufficient privilege, and a record has been * written to the output stream. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies close() when having sufficient privilege, " + + "and a record has been written to the output stream.", + targets = { + @TestTarget( + methodName = "close", + methodArgs = {} + ) + }) public void testClose_SufficientPrivilege_NormalClose() { ByteArrayOutputStream aos = new MockOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); @@ -371,6 +485,15 @@ public class StreamHandlerTest extends TestCase { * Test close() when having sufficient privilege, and an output stream that * always throws exceptions. */ + @TestInfo + (level = TestLevel.PARTIAL_OK, + purpose = "Verifies close() when having sufficient privilege, " + + "and an output stream that always throws exceptions.", + targets = {@TestTarget( + methodName = "close", + methodArgs = {}) + } + ) public void testClose_SufficientPrivilege_Exception() { ByteArrayOutputStream aos = new MockExceptionOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); @@ -384,6 +507,15 @@ public class StreamHandlerTest extends TestCase { * Test close() when having sufficient privilege, and no record has been * written to the output stream. */ + @TestInfo + (level = TestLevel.PARTIAL_OK, + purpose = "Verifies close() method when having sufficient privilege, " + + "and no record has been written to the output stream.", + targets = + { + @TestTarget(methodName = "close", methodArgs = {}) + } + ) public void testClose_SufficientPrivilege_DirectClose() { ByteArrayOutputStream aos = new MockOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); @@ -394,19 +526,27 @@ public class StreamHandlerTest extends TestCase { assertEquals("flush", CallVerificationStack.getInstance() .getCurrentSourceMethod()); CallVerificationStack.getInstance().clear(); - assertEquals("MockFormatter_HeadMockFormatter_Tail", aos.toString() - ); + assertEquals("MockFormatter_HeadMockFormatter_Tail", aos.toString()); } /* * Test close() when having insufficient privilege. */ - public void testClose_InsufficientPrivilege() { + @TestInfo + (level = TestLevel.PARTIAL_OK, + purpose = "Verifies SecurityException.", + targets = + { + @TestTarget(methodName = "close", methodArgs = {}) + } + ) + public void testClose_InsufficientPrivilege() { + StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), + new MockFormatter()); + SecurityManager oldMan = System.getSecurityManager(); System.setSecurityManager(new MockSecurityManager()); try { - StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), - new MockFormatter()); h.close(); fail("Should throw SecurityException!"); } catch (SecurityException e) { @@ -419,6 +559,14 @@ public class StreamHandlerTest extends TestCase { /* * Test close() when having no output stream. */ + @TestInfo + (level = TestLevel.PARTIAL_OK, + purpose = "Verifies close() method when having no output stream.", + targets = + { + @TestTarget(methodName = "close", methodArgs = {}) + } + ) public void testClose_NoOutputStream() { StreamHandler h = new StreamHandler(); h.close(); @@ -427,12 +575,20 @@ public class StreamHandlerTest extends TestCase { /* * Test flush(). */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies flush() method.", + targets = { + @TestTarget( + methodName = "flush", + methodArgs = {} + ) + }) public void testFlush_Normal() { ByteArrayOutputStream aos = new MockOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); h.flush(); - assertEquals("flush", CallVerificationStack.getInstance() - .getCurrentSourceMethod()); + assertEquals("flush", CallVerificationStack.getInstance().getCurrentSourceMethod()); assertNull(CallVerificationStack.getInstance().pop()); CallVerificationStack.getInstance().clear(); } @@ -440,14 +596,32 @@ public class StreamHandlerTest extends TestCase { /* * Test flush() when having no output stream. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies flush() when having no output stream.", + targets = { + @TestTarget( + methodName = "flush", + methodArgs = {} + ) + }) public void testFlush_NoOutputStream() { StreamHandler h = new StreamHandler(); h.flush(); } /* - * Test isLoggable(), use no filter, having output stream + * Test isLoggable(), use no filter, having no output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies isLoggable(), use no filter, having no output stream.", + targets = { + @TestTarget( + methodName = "isLoggable", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testIsLoggable_NoOutputStream() { StreamHandler h = new StreamHandler(); LogRecord r = new LogRecord(Level.INFO, null); @@ -467,6 +641,15 @@ public class StreamHandlerTest extends TestCase { /* * Test isLoggable(), use no filter, having output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies isLoggable(), use no filter, having output stream.", + targets = { + @TestTarget( + methodName = "isLoggable", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testIsLoggable_NoFilter() { StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), new SimpleFormatter()); @@ -487,6 +670,15 @@ public class StreamHandlerTest extends TestCase { /* * Test isLoggable(), use a filter, having output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies isLoggable(), use a filter, having output stream.", + targets = { + @TestTarget( + methodName = "isLoggable", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testIsLoggable_WithFilter() { StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), new SimpleFormatter()); @@ -500,7 +692,7 @@ public class StreamHandlerTest extends TestCase { assertSame(r, CallVerificationStack.getInstance().pop()); h.setLevel(Level.WARNING); - assertFalse(h.isLoggable(r)); + assertFalse(h.isLoggable(r)); //level to high, data will not reach the filter assertTrue(CallVerificationStack.getInstance().empty()); } @@ -508,6 +700,16 @@ public class StreamHandlerTest extends TestCase { * Test isLoggable(), null log record, having output stream. Handler should * call ErrorManager to handle exceptional case */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies isLoggable(), null log record, having output stream. " + + "Handler should call ErrorManager to handle exceptional case.", + targets = { + @TestTarget( + methodName = "isLoggable", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testIsLoggable_Null() { StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), new SimpleFormatter()); @@ -517,6 +719,15 @@ public class StreamHandlerTest extends TestCase { /* * Test isLoggable(), null log record, without output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies isLoggable(), null log record, without output stream.", + targets = { + @TestTarget( + methodName = "isLoggable", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testIsLoggable_Null_NoOutputStream() { StreamHandler h = new StreamHandler(); assertFalse(h.isLoggable(null)); @@ -525,8 +736,18 @@ public class StreamHandlerTest extends TestCase { /* * Test publish(), use no filter, having output stream, normal log record. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), use no filter, having output stream, " + + "normal log record.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_NoOutputStream() { - StreamHandler h = new StreamHandler(); + StreamHandler h = new StreamHandler(); LogRecord r = new LogRecord(Level.INFO, "testPublish_NoOutputStream"); h.publish(r); @@ -544,6 +765,16 @@ public class StreamHandlerTest extends TestCase { /* * Test publish(), use no filter, having output stream, normal log record. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), use no filter, having output stream, " + + "normal log record.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_NoFilter() { ByteArrayOutputStream aos = new ByteArrayOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); @@ -578,6 +809,16 @@ public class StreamHandlerTest extends TestCase { /* * Test publish(), use a filter, having output stream, normal log record. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), use a filter, having output stream, " + + "normal log record.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_WithFilter() { ByteArrayOutputStream aos = new ByteArrayOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); @@ -614,6 +855,16 @@ public class StreamHandlerTest extends TestCase { * Test publish(), null log record, handler should call ErrorManager to * handle exceptional case */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), null log record, handler should call " + + "ErrorManager to handle exceptional case.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_Null() { StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), new SimpleFormatter()); @@ -623,6 +874,15 @@ public class StreamHandlerTest extends TestCase { /* * Test publish(), null log record, without output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), null log record, without output stream.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_Null_NoOutputStream() { StreamHandler h = new StreamHandler(); h.publish(null); @@ -640,6 +900,16 @@ public class StreamHandlerTest extends TestCase { /* * Test publish(), a log record with empty msg, having output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), a log record with empty msg, " + + "having output stream.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_EmptyMsg() { ByteArrayOutputStream aos = new ByteArrayOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); @@ -652,6 +922,16 @@ public class StreamHandlerTest extends TestCase { /* * Test publish(), a log record with null msg, having output stream */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), a log record with null msg, " + + "having output stream.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_NullMsg() { ByteArrayOutputStream aos = new ByteArrayOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); @@ -664,6 +944,15 @@ public class StreamHandlerTest extends TestCase { /* * Test publish(), after close. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies publish(), after close.", + targets = { + @TestTarget( + methodName = "publish", + methodArgs = {java.util.logging.LogRecord.class} + ) + }) public void testPublish_AfterClose() throws Exception { Properties p = new Properties(); p.put("java.util.logging.StreamHandler.level", "FINE"); @@ -685,6 +974,15 @@ public class StreamHandlerTest extends TestCase { /* * Test setEncoding() method with supported encoding. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies setEncoding() method with supported encoding.", + targets = { + @TestTarget( + methodName = "setEncoding", + methodArgs = {java.lang.String.class} + ) + }) public void testSetEncoding_Normal() throws Exception { ByteArrayOutputStream aos = new ByteArrayOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); @@ -704,6 +1002,16 @@ public class StreamHandlerTest extends TestCase { * Test setEncoding() method with supported encoding, after a log record * has been written. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies setEncoding() method with supported encoding, " + + "after a log record has been written.", + targets = { + @TestTarget( + methodName = "setEncoding", + methodArgs = {java.lang.String.class} + ) + }) public void testSetEncoding_AfterPublish() throws Exception { ByteArrayOutputStream aos = new ByteArrayOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); @@ -739,6 +1047,15 @@ public class StreamHandlerTest extends TestCase { /* * Test setEncoding() methods with null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies setEncoding() methods with null.", + targets = { + @TestTarget( + methodName = "setEncoding", + methodArgs = {java.lang.String.class} + ) + }) public void testSetEncoding_Null() throws Exception { StreamHandler h = new StreamHandler(); h.setEncoding(null); @@ -748,6 +1065,15 @@ public class StreamHandlerTest extends TestCase { /* * Test setEncoding() methods with unsupported encoding. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies setEncoding() methods with unsupported encoding.", + targets = { + @TestTarget( + methodName = "setEncoding", + methodArgs = {java.lang.String.class} + ) + }) public void testSetEncoding_Unsupported() { StreamHandler h = new StreamHandler(); try { @@ -762,6 +1088,15 @@ public class StreamHandlerTest extends TestCase { /* * Test setEncoding() with insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies setEncoding() method with insufficient privilege.", + targets = { + @TestTarget( + methodName = "setEncoding", + methodArgs = {java.lang.String.class} + ) + }) public void testSetEncoding_InsufficientPrivilege() throws Exception { StreamHandler h = new StreamHandler(); SecurityManager oldMan = System.getSecurityManager(); @@ -793,6 +1128,16 @@ public class StreamHandlerTest extends TestCase { /* * Test setEncoding() methods will flush a stream before setting. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies that setEncoding() method will flush a stream " + + "before setting.", + targets = { + @TestTarget( + methodName = "setEncoding", + methodArgs = {java.lang.String.class} + ) + }) public void testSetEncoding_FlushBeforeSetting() throws Exception { ByteArrayOutputStream aos = new ByteArrayOutputStream(); StreamHandler h = new StreamHandler(aos, new MockFormatter()); @@ -806,6 +1151,15 @@ public class StreamHandlerTest extends TestCase { /* * Test setOutputStream() with null. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies setOutputStream() method with null.", + targets = { + @TestTarget( + methodName = "setOutputStream", + methodArgs = {java.io.OutputStream.class} + ) + }) public void testSetOutputStream_null() { MockStreamHandler h = new MockStreamHandler( new ByteArrayOutputStream(), new SimpleFormatter()); @@ -820,6 +1174,15 @@ public class StreamHandlerTest extends TestCase { /* * Test setOutputStream() under normal condition. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies setOutputStream() method under normal condition.", + targets = { + @TestTarget( + methodName = "setOutputStream", + methodArgs = {java.io.OutputStream.class} + ) + }) public void testSetOutputStream_Normal() { ByteArrayOutputStream aos = new ByteArrayOutputStream(); MockStreamHandler h = new MockStreamHandler(aos, new MockFormatter()); @@ -850,6 +1213,15 @@ public class StreamHandlerTest extends TestCase { /* * Test setOutputStream() after close. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies setOutputStream() method after close.", + targets = { + @TestTarget( + methodName = "setOutputStream", + methodArgs = {java.io.OutputStream.class} + ) + }) public void testSetOutputStream_AfterClose() { ByteArrayOutputStream aos = new ByteArrayOutputStream(); MockStreamHandler h = new MockStreamHandler(aos, new MockFormatter()); @@ -881,6 +1253,16 @@ public class StreamHandlerTest extends TestCase { /* * Test setOutputStream() when having insufficient privilege. */ + @TestInfo( + level = TestLevel.PARTIAL_OK, + purpose = "Verifies setOutputStream() method when having insufficient " + + "privilege.", + targets = { + @TestTarget( + methodName = "setOutputStream", + methodArgs = {java.io.OutputStream.class} + ) + }) public void testSetOutputStream_InsufficientPrivilege() { MockStreamHandler h = new MockStreamHandler(); SecurityManager oldMan = System.getSecurityManager(); @@ -1009,7 +1391,6 @@ public class StreamHandlerTest extends TestCase { * @see java.io.OutputStream#write(int) */ public void write(int oneByte) { - // TODO Auto-generated method stub super.write(oneByte); } } diff --git a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/XMLFormatterTest.java b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/XMLFormatterTest.java index 54582d1..4d1567a 100644 --- a/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/XMLFormatterTest.java +++ b/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/XMLFormatterTest.java @@ -17,6 +17,13 @@ package org.apache.harmony.logging.tests.java.util.logging; +import dalvik.annotation.TestInfo; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTarget; +import dalvik.annotation.TestTargetClass; + +import junit.framework.TestCase; + import java.io.UnsupportedEncodingException; import java.util.ResourceBundle; import java.util.logging.Handler; @@ -24,8 +31,7 @@ import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.XMLFormatter; -import junit.framework.TestCase; - +@TestTargetClass(XMLFormatter.class) public class XMLFormatterTest extends TestCase { XMLFormatter formatter = null; @@ -43,7 +49,16 @@ public class XMLFormatterTest extends TestCase { /* * test for constructor public XMLFormatter() + * */ + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "XMLFormatter", methodArgs = {}) + } + ) public void testXMLFormatter() { String result = formatter.getHead(handler); int headPos = result @@ -61,6 +76,14 @@ public class XMLFormatterTest extends TestCase { .getTail(handler).indexOf("/log>") > 0); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "format", methodArgs = {LogRecord.class}) + } + ) public void testLocalFormat() { // if set resource bundle, output will use localized message, // but put the original message into the key element @@ -92,6 +115,14 @@ public class XMLFormatterTest extends TestCase { assertTrue(result.indexOf("<key>") < 0); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "format", methodArgs = {LogRecord.class}) + } + ) public void testFullFormat() { lr.setSourceClassName("source class"); lr.setSourceMethodName("source method"); @@ -124,6 +155,14 @@ public class XMLFormatterTest extends TestCase { assertTrue(output.indexOf("<key>pattern</key>") > 0); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "format", methodArgs = {LogRecord.class}) + } + ) public void testFormat() { String output = formatter.format(lr); // System.out.println(output); @@ -143,6 +182,14 @@ public class XMLFormatterTest extends TestCase { assertTrue(output.indexOf("<key>") < 0); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "getHead", methodArgs = {Handler.class}) + } + ) public void testGetHead() throws SecurityException, UnsupportedEncodingException { String result = formatter.getHead(handler); @@ -165,9 +212,7 @@ public class XMLFormatterTest extends TestCase { handler.setEncoding(null); result = formatter.getHead(handler); assertNull(handler.getEncoding()); - // assertTrue(result.indexOf(defaultEncoding)>0); - // regression test for Harmony-1280 // make sure no NPE is thrown formatter.getHead(null); @@ -176,6 +221,14 @@ public class XMLFormatterTest extends TestCase { /* * test for method public String getTail(Handler h) */ + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "getTail", methodArgs = {Handler.class}) + } + ) public void testGetTail() { assertEquals( "Tail string with null handler should be equal expected value", @@ -188,6 +241,16 @@ public class XMLFormatterTest extends TestCase { "</log>", formatter.getTail(handler).trim()); } + @TestInfo + (level = TestLevel.COMPLETE, + purpose = "", + targets = + { + @TestTarget(methodName = "format", methodArgs = {LogRecord.class}), + @TestTarget(methodName = "getTail", methodArgs = {Handler.class}), + @TestTarget(methodName = "XMLFormatter", methodArgs = {}) + } + ) public void testInvalidParameter() { formatter.getTail(null); try { @@ -199,7 +262,7 @@ public class XMLFormatterTest extends TestCase { formatter = new XMLFormatter(); lr = new LogRecord(Level.SEVERE, null); String output = formatter.format(lr); - assertTrue(output.indexOf("<message") < 0); + assertTrue(output.indexOf("<message/>") != -1); } public static class MockHandler extends Handler { |