MeterRegistrySupplier implements Supplier<MeterRegistry> { @Override public MeterRegistry get() { InternalDistributedSystem system = internalDistributedSystemSupplier.get(); if (system == null) { return null; } InternalCache internalCache = system.getCache(); if (internalCache == null) { return null; } return internalCache.getMeterRegistry(); } MeterRegistrySupplier(
      Supplier<InternalDistributedSystem> internalDistributedSystemSupplier); @Override MeterRegistry get();  }
@Test public void get_internalDistributedSystemIsNull_expectNull() { MeterRegistrySupplier meterRegistrySupplier = new MeterRegistrySupplier(() -> null); MeterRegistry value = meterRegistrySupplier.get(); assertThat(value) .isNull(); }
@Test public void get_internalCacheIsNull_expectNull() { InternalDistributedSystem internalDistributedSystem = mock(InternalDistributedSystem.class); when(internalDistributedSystem.getCache()).thenReturn(null); MeterRegistrySupplier meterRegistrySupplier = new MeterRegistrySupplier(() -> internalDistributedSystem); MeterRegistry value = meterRegistrySupplier.get(); assertThat(value) .isNull(); }
@Test public void get_meterRegistryIsNull_expectNull() { InternalDistributedSystem internalDistributedSystem = mock(InternalDistributedSystem.class); InternalCache internalCache = mock(InternalCache.class); when(internalDistributedSystem.getCache()).thenReturn(internalCache); when(internalCache.getMeterRegistry()).thenReturn(null); MeterRegistrySupplier meterRegistrySupplier = new MeterRegistrySupplier(() -> internalDistributedSystem); MeterRegistry value = meterRegistrySupplier.get(); assertThat(value) .isNull(); }
@Test public void get_meterRegistryExists_expectActualMeterRegistry() { InternalDistributedSystem internalDistributedSystem = mock(InternalDistributedSystem.class); InternalCache internalCache = mock(InternalCache.class); MeterRegistry meterRegistry = mock(MeterRegistry.class); when(internalDistributedSystem.getCache()).thenReturn(internalCache); when(internalCache.getMeterRegistry()).thenReturn(meterRegistry); MeterRegistrySupplier meterRegistrySupplier = new MeterRegistrySupplier(() -> internalDistributedSystem); MeterRegistry value = meterRegistrySupplier.get(); assertThat(value) .isSameAs(meterRegistry); }