Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 71668 invoked from network); 17 Apr 2006 06:19:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Apr 2006 06:19:40 -0000 Received: (qmail 43154 invoked by uid 500); 17 Apr 2006 06:19:36 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 43052 invoked by uid 500); 17 Apr 2006 06:19:36 -0000 Mailing-List: contact harmony-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-dev@incubator.apache.org Received: (qmail 43011 invoked by uid 99); 17 Apr 2006 06:19:36 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 16 Apr 2006 23:19:36 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of anton.avtamonov@gmail.com designates 64.233.162.198 as permitted sender) Received: from [64.233.162.198] (HELO nz-out-0102.google.com) (64.233.162.198) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 16 Apr 2006 23:19:34 -0700 Received: by nz-out-0102.google.com with SMTP id s1so505815nze for ; Sun, 16 Apr 2006 23:19:14 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=mYmCz4vL51ySZCnP14w34YXEtPMvQTB0qleosyCnU+elGBvxzMltP2EnMjdHYN3FJY4+vbrXCAG6HiiHtXbjgQy7rULy08VK5qTbdWYPFpzC8mIL1oKN/PmVqjRn+gnqvmS7vQtlcaa65KycrzTJ6JbUiEQAP4sueG7OLQx9C+E= Received: by 10.64.208.13 with SMTP id f13mr269045qbg; Sun, 16 Apr 2006 23:19:14 -0700 (PDT) Received: by 10.64.250.16 with HTTP; Sun, 16 Apr 2006 23:19:14 -0700 (PDT) Message-ID: <46d21a9a0604162319l5f23750awfde9d7f8ff880865@mail.gmail.com> Date: Mon, 17 Apr 2006 10:19:14 +0400 From: "Anton Avtamonov" To: harmony-dev@incubator.apache.org Subject: Re: should strings in exceptions match the reference implementation? In-Reply-To: <46d21a9a0604162306q73e0a474hca0d4a15bc8d66ed@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <011b01c660d5$2e802b50$1101a8c0@OFFICEDESKTOP> <906dd82e0604152206m4385f0fia6651ee40c58206a@mail.gmail.com> <5c8e69f0604161823r63392d44j32ae82981d2a95a@mail.gmail.com> <46d21a9a0604162235n69f1479dp39f88773592406a8@mail.gmail.com> <46d21a9a0604162306q73e0a474hca0d4a15bc8d66ed@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N In addition, I want to share what I do when testing exceptions. I created the following basic abstract class: protected abstract class ExceptionalCase { private Class clazz; private String msg; public abstract void exceptionalAction() throws Exception; public ExceptionalCase() { } public ExceptionalCase(String msg, Class clazz) { this.msg =3D msg; this.clazz =3D clazz; } public Class expectedExceptionClass() { return clazz; } public String expectedExceptionMessage() { return msg; } } and the following utility test method: protected void testExceptionalCase(final ExceptionalCase ec) { try { ec.exceptionalAction(); fail("Exceptional case was not detected!"); } catch (final Exception e) { if (ec.expectedExceptionClass() !=3D null) { if (!ec.expectedExceptionClass().isAssignableFrom(e.getClass())) { fail("Exception of wrong type " + e.getClass() + " is produced!"); } } if (ec.expectedExceptionMessage() !=3D null) { assertEquals("Wrong exception message", ec.expectedExceptionMessage(), e.getMessage()); } } } Besides, I created several 'concrete' ExceptionalCases like: protected abstract class NullPointerCase extends ExceptionalCase { public Class expectedExceptionClass() { return NullPointerException.class; } } So, every time when I want to test that "NPE and only NPE" is produced I do the following: testExceptionalCase(new NullPointerCase() { public void exceptionalAction() throws Exception { //some action which should produce NPE } }); It doesn't care about the message. If I need to test some particular message as well as type of exception I should either override expectedExceptionMessage() or use an appropriate constructor to create ExceptionalCase like: testExceptionalCase(new ExceptionalCase("expected message", NullPointerException.class) { public void exceptionalAction() throws Exception { //some action which should produce NPE } }); I believe that is convenient and Object-Oriented approach. Wishes, -- Anton Avtamonov, Intel Middleware Products Division On 4/17/06, Anton Avtamonov wrote: > On 4/17/06, Mark Hindess wrote: > > So, the second issue, should we be checking for messages/descriptions > > in exception > > tests, even to match what Harmony throws? If we do then our api tests > > wont pass on other implementations. > > Hi Mark, > As I said already I don't see any huge reasons to check the messages > (probably for not being empty only). However I suppose sometimes it > could be necessary. I'm pretty sure we will face many cases when we > need to deviate from RI (it was discussed already in other threads). > > What I propose is to use for tests some utility method like > isHarmony(). It will act as a 'formal' indicator of all our > deviations. > > For this particular situation is should be something like: > if (TestUtilities.isHarmony()) { > assertEquals("some message", e.getMessage()) > } > > What do you think? > > -- > Anton Avtamonov, > Intel Middleware Products Division > --------------------------------------------------------------------- Terms of use : http://incubator.apache.org/harmony/mailing.html To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org For additional commands, e-mail: harmony-dev-help@incubator.apache.org