Sort methods. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/fc4f1254 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/fc4f1254 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/fc4f1254
Branch: refs/heads/LOG4J-1181 Commit: fc4f12545fe628b6e9d93733b81a2010ea344871 Parents: 2066ff2 Author: ggregory <ggreg...@apache.org> Authored: Thu Jun 2 14:48:43 2016 -0700 Committer: ggregory <ggreg...@apache.org> Committed: Thu Jun 2 14:48:43 2016 -0700 ---------------------------------------------------------------------- .../logging/log4j/junit/LoggerContextRule.java | 88 ++++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fc4f1254/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java index 59e921d..789a5fe 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java @@ -104,62 +104,77 @@ public class LoggerContextRule implements TestRule { } /** - * Gets the current LoggerContext associated with this rule. + * Gets a named Appender for this LoggerContext. * - * @return the current LoggerContext. + * @param name the name of the Appender to look up. + * @return the named Appender or {@code null} if it wasn't defined in the configuration. */ - public LoggerContext getContext() { - return context; + public Appender getAppender(final String name) { + return getConfiguration().getAppenders().get(name); } /** - * Gets a named Logger using the test class's name from this LoggerContext. + * Gets a named Appender for this LoggerContext. * - * @return the test class's named Logger. + * @param <T> The target Appender class + * @param name the name of the Appender to look up. + * @param cls The target Appender class + * @return the named Appender or {@code null} if it wasn't defined in the configuration. */ - public Logger getLogger() { - return context.getLogger(testClassName); + public <T extends Appender> T getAppender(final String name, Class<T> cls) { + return cls.cast(getConfiguration().getAppenders().get(name)); } /** - * Gets a named Logger in this LoggerContext. + * Gets the associated Configuration for the configuration file this was constructed with. * - * @param name the name of the Logger to look up or create. - * @return the named Logger. + * @return this LoggerContext's Configuration. */ - public Logger getLogger(final String name) { - return context.getLogger(name); + public Configuration getConfiguration() { + return context.getConfiguration(); } /** - * Gets the associated Configuration for the configuration file this was constructed with. + * Gets the current LoggerContext associated with this rule. * - * @return this LoggerContext's Configuration. + * @return the current LoggerContext. */ - public Configuration getConfiguration() { - return context.getConfiguration(); + public LoggerContext getContext() { + return context; } /** - * Gets a named Appender for this LoggerContext. + * Gets a named ListAppender or throws an exception for this LoggerContext. * - * @param name the name of the Appender to look up. - * @return the named Appender or {@code null} if it wasn't defined in the configuration. + * @param name the name of the ListAppender to look up. + * @return the named ListAppender. + * @throws AssertionError if the named ListAppender doesn't exist or isn't a ListAppender. */ - public Appender getAppender(final String name) { - return getConfiguration().getAppenders().get(name); + public ListAppender getListAppender(final String name) { + final Appender appender = getAppender(name); + if (appender instanceof ListAppender) { + return (ListAppender) appender; + } + throw new AssertionError("No ListAppender named " + name + " found."); } /** - * Gets a named Appender for this LoggerContext. + * Gets a named Logger using the test class's name from this LoggerContext. * - * @param <T> The target Appender class - * @param name the name of the Appender to look up. - * @param cls The target Appender class - * @return the named Appender or {@code null} if it wasn't defined in the configuration. + * @return the test class's named Logger. */ - public <T extends Appender> T getAppender(final String name, Class<T> cls) { - return cls.cast(getConfiguration().getAppenders().get(name)); + public Logger getLogger() { + return context.getLogger(testClassName); + } + + /** + * Gets a named Logger in this LoggerContext. + * + * @param name the name of the Logger to look up or create. + * @return the named Logger. + */ + public Logger getLogger(final String name) { + return context.getLogger(name); } /** @@ -190,21 +205,6 @@ public class LoggerContextRule implements TestRule { return appender; } - /** - * Gets a named ListAppender or throws an exception for this LoggerContext. - * - * @param name the name of the ListAppender to look up. - * @return the named ListAppender. - * @throws AssertionError if the named ListAppender doesn't exist or isn't a ListAppender. - */ - public ListAppender getListAppender(final String name) { - final Appender appender = getAppender(name); - if (appender instanceof ListAppender) { - return (ListAppender) appender; - } - throw new AssertionError("No ListAppender named " + name + " found."); - } - @Override public String toString() { StringBuilder builder = new StringBuilder();