geode-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Blum <jb...@pivotal.io>
Subject Re: Testing tip: Use IgnoredException as an AutoCloseable
Date Fri, 02 Nov 2018 20:56:28 GMT
With IDE highlighting things as unused, you can either
@SuppressWarnings("unused") on the method or statement highlighted or
adjust your IDE inspections (perhaps more advisable), which is per project.

On Fri, Nov 2, 2018 at 1:27 PM, Kirk Lund <klund@apache.org> wrote:

> The easiest way to use IgnoredException is as an AutoCloseable in a
> try-with-resource block and by specifying the Exception class:
>
> import static
> org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
>
> import org.apache.geode.cache.client.ServerOperationException;
>
> @Test
> public void test{} {
>   try (IgnoredException ie =
> addIgnoredException(ServerOperationException.class))
> {
>     invokeMethodThatLogsServerOperationException();
>   }
> }
>
> Another benefit is that the logged ServerOperationException is only ignored
> within the tiny scope of that try-with-resource block.
>
> Unfortunately you DO need to declare IgnoredException ie even though your
> IDE will highlight it as unused. That's just the way try-with-resource
> works.
>



-- 
-John
john.blum10101 (skype)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message