harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikhail Loenko" <mloe...@gmail.com>
Subject Re: [classlib] exception messages
Date Mon, 15 May 2006 03:10:10 GMT
Hi Andrew

The problem with this test is that it will not catch the change
of the message for the given key.

For example if we throw some message from 3 points in the code
and we do some change in the property file that is acceptable for
two points but not acceptable for the 3rd one, we will not catch this
regression by the test you propose.

Thanks,
Mikhail

2006/5/13, Andrew Zhang <zhanghuangzhu@gmail.com>:
> Hello, Mikhail
>
> org.apache.harmony.luni.util.Msg has already handled locale issue.
>
> So it's not neccessary to get locale inforamtion again in test case, and
> then get i18n message.
>
> For example, following code is from java.net.HttpURLConnection.java
>
> method setRequestMethod:
>
> if (connected)
>   throw new ProtocolException(org.apache.harmony.luni.util.Msg.getString
> ("K0037"));
>
> Correspondingly, we could write a test case:
>
> public void test_setRequestMethod(){
> try{
> ... // make the exception happen
> }catch(ProtocolException e){
>   assertEquals(Msg.getString("K0037"), e.getMessage());
> }
>
>
> Since source code and test code are running in the same runtime, they use
> the same locale information, which is used to initialize ResourceBundle in
> class Msg.
> static {
>  // Attempt to load the messages.
>  try {
>   bundle = MsgHelp.setLocale(Locale.getDefault(),
>     "org.apache.harmony.luni.util.ExternalMessages");
>  }
>  ...
>  }
>
>
> Finally, I don't think we need test exception message in most cases,
> unless there're some speical reasons, e.g, the exception message format is
> metioned in spec.
>
> Any comment? Thanks!
>
> On 5/13/06, Mikhail Loenko <mloenko@gmail.com> wrote:
> >
> > Another (more preferable for me) way could be set a specific locale and
> > compare to the message for this locale
> >
> > Thanks,
> > Mikhail.
> >
> > 2006/5/13, Andrew Zhang <zhanghuangzhu@gmail.com>:
> > > Hello,
> > >
> > > If we really decide to test exception message, I think we could write
> > test
> > > case as follows:
> > >
> > > public void test_f(){
> > >    .....
> > >    catch(SomeException e){
> > >         assertEquals(org.apache.util.Msg.getString("K508C"),e.getMessage
> > > ());
> > >    }
> > > }
> > >
> > > Does it work?  Because what we want to make sure it that "SomeException"
> > is
> > > really thrown with message K508C. So that's another reason that we
> > should
> > > use Msg.getString  rather than explicit string to fill exception
> > > information.
> > >
> > > On 5/13/06, Tim Ellison <t.p.ellison@gmail.com> wrote:
> > > >
> > > > Loenko, Mikhail Y wrote:
> > > > > From: Tim Ellison [mailto:t.p.ellison@gmail.com]
> > > > >> So let me refine my position to say, "our API tests shouldn't
be
> > > > >> asserting the value of unspecified parts of an exception message".
> > > > >> Does that make sense?
> > > > >
> > > > > Yes, it does. But we might have impl tests that check for exception
> > > > > messages.
> > > >
> > > > Ok, provided they still pass when I translate the message catalog to
> > > > Klingon ;-)
> > > >
> > > > Regards,
> > > > Tim
> > > >
> > > > --
> > > >
> > > > Tim Ellison (t.p.ellison@gmail.com)
> > > > IBM Java technology centre, UK.
> > > >
> > > > ---------------------------------------------------------------------
> > > > 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
> > > >
> > > >
> > >
> > >
> > > --
> > > Andrew Zhang
> > > China Software Development Lab, IBM
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > 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
> >
> >
>
>
> --
> Andrew Zhang
> China Software Development Lab, IBM
>
>

---------------------------------------------------------------------
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


Mime
View raw message