static void register(MBeanServer server, ObjectName objectName, Object mbean) {
    try {
      if (!server.isRegistered(objectName)) {
        server.registerMBean(mbean, objectName);
      }
    } catch (InstanceAlreadyExistsException
        | MBeanRegistrationException | NotCompliantMBeanException e) {
      throw new CacheException("Error registering " + objectName, e);
    }
  }
@Test(dataProvider = "registerExceptions")
  public void register_error(Class<? extends Throwable> throwableType) throws JMException {
    var name = new ObjectName("");
    var bean = new JCacheStatisticsMXBean();
    MBeanServer server = Mockito.mock();
    when(server.registerMBean(bean, name)).thenThrow(throwableType);
    assertThrows(CacheException.class, () -> JmxRegistration.register(server, name, bean));
  }