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 <[EMAIL PROTECTED]>:
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 <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]>:
> > 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 <[EMAIL PROTECTED]> wrote:
> > >
> > > Loenko, Mikhail Y wrote:
> > > > From: Tim Ellison [mailto:[EMAIL PROTECTED]
> > > >> 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 ([EMAIL PROTECTED])
> > > IBM Java technology centre, UK.
> > >
> > > ---------------------------------------------------------------------
> > > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > Andrew Zhang
> > China Software Development Lab, IBM
> >
> >
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


--
Andrew Zhang
China Software Development Lab, IBM



---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to