You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Robert Muir (JIRA)" <ji...@apache.org> on 2016/02/19 16:06:18 UTC

[jira] [Updated] (LUCENE-7037) Switch all exception tests to expectThrows()

     [ https://issues.apache.org/jira/browse/LUCENE-7037?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Robert Muir updated LUCENE-7037:
--------------------------------
    Attachment: LUCENE-7037.patch

Here is a patch. It fixes numerous instances of missing {{fail()}} calls and other problems. 

If a test was "crazy" (e.g. multi-catch) then I did not switch it over.
For example {{catch (NoSuchFileException | FileNotFoundException)}}. I think we should try to improve those APIs if possible instead?

In some cases the limitations of effectively-final meant I had to split up big tests into smaller ones or change local variables or similar. I see this as a good thing...

> Switch all exception tests to expectThrows()
> --------------------------------------------
>
>                 Key: LUCENE-7037
>                 URL: https://issues.apache.org/jira/browse/LUCENE-7037
>             Project: Lucene - Core
>          Issue Type: Bug
>            Reporter: Robert Muir
>         Attachments: LUCENE-7037.patch
>
>
> Tests expecting exceptions today are done in various ways.
> The best ones look like this.
> {code}
> try {
>   something();
>   fail("message");
> } catch (Exception expected) {
>   assertSomethingAbout(expected);
> }
> {code}
> But there are many forms (involving booleans and such). All of these are a little sketchy because it is all-too easy to just forget the {{fail()}} and then the whole test is useless.
> `expectThrows` was added in LUCENE-7009 which solves a lot of these problems. Its not perfect, but overall a big improvement. We should cut over all of our tests.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org