@Test
    void verify() {
        val applicationContext = new StaticApplicationContext();
        applicationContext.refresh();
        val serializer = mock(StringSerializer.class);
        doThrow(new RuntimeException()).when(serializer).to(any(OutputStream.class), any());
        val registry = new AbstractResourceBasedServiceRegistry(FileUtils.getTempDirectory().toPath(),
            serializer, applicationContext, mock(RegisteredServiceReplicationStrategy.class),
            new DefaultRegisteredServiceResourceNamingStrategy(), List.of(), mock(WatcherService.class)) {
            @Override
            protected String[] getExtensions() {
                return new String[]{".json"};
            }
        };
        val r = buildRegisteredServiceInstance(RandomUtils.nextInt(), CasRegisteredService.class);
        assertThrows(IllegalArgumentException.class, () -> registry.save(r));
        registry.destroy();
    }
This is {@link BaseResourceBasedServiceRegistryTests}.

@author Misagh Moayyed
@since 5.0.0
core/cas-server-core-services/src/test/java/org/apereo/cas/services/BaseResourceBasedServiceRegistryTests.java