'How put data in pool after test

There is a test in which the pool is accessed to take data from there. For example

@ExtendWith(PoolExtension.class)
public class SomeTest {
  @Inject private PhonePool pool()
  void test() {
    Phone phone = pool.getPhone();
    //some actions with phone
  }
}

The pool has a limited amount of data. How to return the taken data to the pool after the end of the test in this extension using the afterEach() method

public class PoolExtension implements AfterEachCallback {
  public PoolExtension() {
      final Injector injector = Guice.createInjector(new DataModule());
      injector.injectMembers(this);
  }
  @Override
  public void afterEach(ExtensionContext context} throws Exception {}
}

What are some ideas? java8, jUnit5, Guice for DI



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source