concept AutoCloseable interface in category apache pulsar

appears as: AutoCloseable interface
Apache Pulsar in Action

This is an excerpt from Manning's book Apache Pulsar in Action.

Listing 4.9 KeywordFilterFunction Unit Tests
package com.manning.pulsar.chapter4.functions.sdk;
 
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
...
public class KeywordFilterFunctionTests {    
private KeywordFilterFunction function = new KeywordFilterFunction();
    
@Mock
private Context mockedCtx;
    
@Before
public final void setUp() {
  MockitoAnnotations.initMocks(this);
}
 
  @Test
  public final void containsKeywordTest() throws Exception {
    when(mockedCtx.getUserConfigValue(
       KeywordFilterFunction.KEYWORD_CONFIG))
       .thenReturn(Optional.of("dog"));    #A
    
 String sentence = "The brown fox jumped over the lazy dog";
 String result = function.process(sentence, mockedCtx);
 assertNotNull(result);    #B
 assertEquals(sentence, result);
  }
    
  @Test
  public final void doesNotContainKeywordTest() throws Exception {
    when(mockedCtx.getUserConfigValue(
    KeywordFilterFunction.KEYWORD_CONFIG))
    .thenReturn(Optional.of("cat"));    #C
    
    String sentence = "It was the best of times, it was the worst of times";
 String result = function.process(sentence, mockedCtx);
 assertNull(result);    #D
  }
    
  @Test
  public final void ignoreCaseTest() {
    when(mockedCtx.getUserConfigValue(
       KeywordFilterFunction.KEYWORD_CONFIG))
       .thenReturn(Optional.of("RED"));    #E
 
    when(mockedCtx.getUserConfigValue(
       KeywordFilterFunction.IGNORE_CONFIG))
       .thenReturn(Optional.of(Boolean.TRUE));    #F
        
  String sentence = "Everyone watched the red sports car drive off.";
  String result = function.process(sentence, mockedCtx);
  assertNotNull(result);    #G
  assertEquals(sentence, result);
  }
}