From commits-return-4235-apmail-zookeeper-commits-archive=zookeeper.apache.org@zookeeper.apache.org Sun May 3 17:55:29 2015 Return-Path: X-Original-To: apmail-zookeeper-commits-archive@www.apache.org Delivered-To: apmail-zookeeper-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1D608108E4 for ; Sun, 3 May 2015 17:55:29 +0000 (UTC) Received: (qmail 21208 invoked by uid 500); 3 May 2015 17:55:29 -0000 Delivered-To: apmail-zookeeper-commits-archive@zookeeper.apache.org Received: (qmail 21166 invoked by uid 500); 3 May 2015 17:55:29 -0000 Mailing-List: contact commits-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ Delivered-To: mailing list commits@zookeeper.apache.org Received: (qmail 21154 invoked by uid 99); 3 May 2015 17:55:28 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 May 2015 17:55:28 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id B6BD8AC010F for ; Sun, 3 May 2015 17:55:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1677460 - in /zookeeper/trunk: CHANGES.txt src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java Date: Sun, 03 May 2015 17:55:28 -0000 To: commits@zookeeper.apache.org From: rgs@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150503175528.B6BD8AC010F@hades.apache.org> Author: rgs Date: Sun May 3 17:55:28 2015 New Revision: 1677460 URL: http://svn.apache.org/r1677460 Log: ZOOKEEPER-2174 JUnit4ZKTestRunner logs test failure for all exceptions JUnit4ZKTestRunner logs test failure for all exceptions, even if the test method is annotated with an expected exception (Chris Nauroth via rgs). Modified: zookeeper/trunk/CHANGES.txt zookeeper/trunk/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java Modified: zookeeper/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1677460&r1=1677459&r2=1677460&view=diff ============================================================================== --- zookeeper/trunk/CHANGES.txt (original) +++ zookeeper/trunk/CHANGES.txt Sun May 3 17:55:28 2015 @@ -82,6 +82,10 @@ BUGFIXES: ZOOKEEPER-2173. ZK startup failure should be handled with proper error message (J.Andreina via camille) + ZOOKEEPER-2174 JUnit4ZKTestRunner logs test failure for all exceptions even + if the test method is annotated with an expected exception (Chris Nauroth + via rgs) + IMPROVEMENTS: ZOOKEEPER-1660 Documentation for Dynamic Reconfiguration (Reed Wanderman-Milne via shralex) Modified: zookeeper/trunk/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java?rev=1677460&r1=1677459&r2=1677460&view=diff ============================================================================== --- zookeeper/trunk/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java (original) +++ zookeeper/trunk/src/java/test/org/apache/zookeeper/JUnit4ZKTestRunner.java Sun May 3 17:55:28 2015 @@ -20,6 +20,7 @@ package org.apache.zookeeper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.junit.Test; import org.junit.internal.runners.statements.InvokeMethod; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.model.FrameworkMethod; @@ -38,16 +39,18 @@ public class JUnit4ZKTestRunner extends } public static class LoggedInvokeMethod extends InvokeMethod { - private String name; + private final FrameworkMethod method; + private final String name; public LoggedInvokeMethod(FrameworkMethod method, Object target) { super(method, target); + this.method = method; name = method.getName(); } @Override public void evaluate() throws Throwable { - LOG.info("RUNNING TEST METHOD " + name); + LOG.info("RUNNING TEST METHOD {}", name); try { super.evaluate(); Runtime rt = Runtime.getRuntime(); @@ -59,10 +62,20 @@ public class JUnit4ZKTestRunner extends } LOG.info("Number of threads {}", tg.activeCount()); } catch (Throwable t) { - LOG.info("TEST METHOD FAILED " + name, t); + // The test method threw an exception, but it might be an + // expected exception as defined in the @Test annotation. + // Check the annotation and log an appropriate message. + Test annotation = this.method.getAnnotation(Test.class); + if (annotation != null && annotation.expected() != null && + annotation.expected().isAssignableFrom(t.getClass())) { + LOG.info("TEST METHOD {} THREW EXPECTED EXCEPTION {}", name, + annotation.expected()); + } else { + LOG.info("TEST METHOD FAILED {}", name, t); + } throw t; } - LOG.info("FINISHED TEST METHOD " + name); + LOG.info("FINISHED TEST METHOD {}", name); } }