Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 41579 invoked from network); 9 Aug 2010 07:15:51 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 9 Aug 2010 07:15:51 -0000 Received: (qmail 80284 invoked by uid 500); 9 Aug 2010 07:15:51 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 79721 invoked by uid 500); 9 Aug 2010 07:15:48 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 79711 invoked by uid 99); 9 Aug 2010 07:15:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Aug 2010 07:15:46 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_HELO_PASS,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of jak-commons-dev@m.gmane.org designates 80.91.229.12 as permitted sender) Received: from [80.91.229.12] (HELO lo.gmane.org) (80.91.229.12) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Aug 2010 07:15:39 +0000 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1OiMZk-0002xs-Vm for dev@commons.apache.org; Mon, 09 Aug 2010 09:15:12 +0200 Received: from mail.elsag-solutions.com ([62.154.225.82]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 09 Aug 2010 09:15:12 +0200 Received: from joerg.schaible by mail.elsag-solutions.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 09 Aug 2010 09:15:12 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: dev@commons.apache.org From: =?UTF-8?B?SsO2cmc=?= Schaible Subject: Re: svn commit: r983219 - /commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java Followup-To: gmane.comp.jakarta.commons.devel Date: Mon, 09 Aug 2010 09:15:02 +0200 Lines: 63 Message-ID: References: <20100807120447.1745F2388A02@eris.apache.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: mail.elsag-solutions.com User-Agent: KNode/4.4.3 X-Virus-Checked: Checked by ClamAV on apache.org sebb wrote: > On 8 August 2010 22:34, James Carman wrote: >> To make sure I'm actually passing in the exact same values (by letting >> the compiler create the arrays using the varargs feature) I added the >> following output to the startsWithAny() method: >> >> System.out.println("startsWithAny(): Received " + string + " input >> with " + (searchStrings == null ? null : >> Arrays.asList(searchStrings).toString()) + " input array"); >> >> When running the old version of the test code to the new version, >> there was no difference in the output. >> >> I also ran a similar test by changing getCommonPrefix() method: >> >> System.out.println("getCommonPrefix(): Received " + (strs == null ? >> null : Arrays.asList(strs).toString()) + " input array"); >> >> Again, no changes in the output. So, we're at least exercising the >> "guts" of the methods the same. Now I can understand that you might >> be saying that we're not exercising how the code is called the same >> way in both cases, but the varargs support vs. the manual array >> creation is identical. If you think we should add back in the manual >> String[] stuff, I guess we could, but I really don't see much value in >> it other than testing that varargs == manual String[]. >> > > Although the compiler changes varargs into String[] arrays, the two > tests are not equivalent. > > Using varargs exclusively can hide bugs. > > For example, method(String, String[]) is not the same as method(String > ...). While we're at it, looking at such a method, we should consider to test method(string); instead of its explicit equivalent method(string, (String[])null); Also, when introducing varargs we may not forget to update Javadoc. E.g. StringUitls.startsWithAny documents: ============= %< ================ * StringUtils.startsWithAny(null, null) = false * StringUtils.startsWithAny("abcxyz", null) = false ============= %< ================ both calls are ambiguous now and will not compile. Actually there are now 4 cases: ============= %< ================ * StringUtils.startsWithAny(null) = false * StringUtils.startsWithAny("abcxyz") = false * StringUtils.startsWithAny(null, (String)null) = false * StringUtils.startsWithAny("abcxyz", (String)null) = false ============= %< ================ - Jörg --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org