SpringBootServiceEnricher implements ServiceEnricher { @Override public <T> Collection<T> produce(Class<T> type) { ApplicationContext applicationContext = ApplicationContextProvider.getApplicationContext(); if (applicationContext == null) { log.info("No application context found. Can't produce services of type {}", type); return new ArrayList<>(); } return applicationContext.getBeanProvider(type) .orderedStream() .collect(Collectors.toList()); }  @Override Collection<T> produce(Class<T> type); @Override void enrich(T service);  }
@Test void produce_returnsMutableCollection() { new ApplicationContextProvider().destroy(); Collection<Object> produce = this.serviceEnricher.produce(Object.class); assertThat(produce).isEmpty(); produce.add(new Object()); assertThat(produce).hasSize(1); }