static void unregister(MBeanServer server, ObjectName objectName) {
    try {
      for (ObjectName name : server.queryNames(objectName, null)) {
        server.unregisterMBean(name);
      }
    } catch (MBeanRegistrationException | InstanceNotFoundException e) {
      throw new CacheException("Error unregistering " + objectName, e);
    }
  }
@Test(dataProvider = "unegisterExceptions")
  public void unregister_error(Class<? extends Throwable> throwableType) throws JMException {
    var name = new ObjectName("");
    MBeanServer server = Mockito.mock();
    when(server.queryNames(any(), any())).thenReturn(Set.of(name));
    doThrow(throwableType).when(server).unregisterMBean(any());
    assertThrows(CacheException.class, () -> JmxRegistration.unregister(server, name));
  }