### Question:
DefaultServiceRegistry implements ServiceRegistry { @Override public <T> void setProvider(@NotNull Class<T> service, @NotNull T provider, boolean immutable, boolean needsReplacement) throws ProviderImmutableException { ServiceRegistryEntry<?> current = this.entries.get(service); if (current != null && current.isImmutable()) { throw new ProviderImmutableException(service); } this.entries.put(service, new DefaultServiceRegistryEntry<>(service, provider, immutable, needsReplacement)); }  @Override void setProvider(@NotNull Class<T> service, @NotNull T provider, boolean immutable, boolean needsReplacement); @NotNull @Override @SuppressWarnings("unchecked") Optional<T> getProvider(@NotNull Class<T> service); @NotNull @Override @SuppressWarnings("unchecked") Optional<ServiceRegistryEntry<T>> getRegisteredEntry(@NotNull Class<T> service); @NotNull @Override @SuppressWarnings("unchecked") T getProviderUnchecked(@NotNull Class<T> service); @NotNull @Override @UnmodifiableView Collection<ServiceRegistryEntry<?>> getRegisteredServices(); @Override @SuppressWarnings("unchecked") void unregisterService(@NotNull Class<T> service, @Nullable T replacement);  }### Answer:
@Test @Order(1) void testSetProvider() { this.serviceRegistry.setProvider(AService.class, new AService()); Assertions.assertEquals(1, this.serviceRegistry.getRegisteredServices().size()); this.serviceRegistry.setProvider(AService.class, new AService(), true); Assertions.assertEquals(1, this.serviceRegistry.getRegisteredServices().size()); Assertions.assertThrows(ProviderImmutableException.class, () -> this.serviceRegistry.setProvider(AService.class, new AService())); }