### Question:
SharedServiceConfigProvider { public Cluster configureCluster(@Nonnull Cluster requestedCluster, User user, Workspace workspace) { Objects.requireNonNull(requestedCluster); Stack stack = requestedCluster.getStack(); if (stack.getDatalakeResourceId() != null) { Optional<DatalakeResources> datalakeResources = datalakeResourcesService.findById(stack.getDatalakeResourceId()); if (datalakeResources.isPresent()) { DatalakeResources datalakeResource = datalakeResources.get(); setupRds(requestedCluster, datalakeResource); setupStoragePath(requestedCluster, datalakeResource); } } return requestedCluster; }  Cluster configureCluster(@Nonnull Cluster requestedCluster, User user, Workspace workspace); @Measure(SharedServiceConfigProvider.class) Stack prepareDatalakeConfigs(Stack publicStack);  }### Answer:
@Test public void testConfigureClusterWhenConnectedClusterRequestIsNullThenOriginalClusterInstanceShouldReturn() { Cluster cluster = new Cluster(); cluster.setStack(publicStack); when(publicStack.getDatalakeResourceId()).thenReturn(null); Cluster result = underTest.configureCluster(cluster, user, workspace); Assert.assertEquals(cluster, result); verify(datalakeResourcesService, times(0)).findById(anyLong()); assertNull(cluster.getRdsConfigs()); }
@Test public void testConfigureClusterWithDl() { Cluster requestedCluster = createBarelyConfiguredRequestedCluster(); DatalakeResources datalakeResources = new DatalakeResources(); when(publicStack.getId()).thenReturn(TEST_LONG_VALUE); when(publicStackCluster.getId()).thenReturn(TEST_LONG_VALUE); when(publicStack.getCluster()).thenReturn(publicStackCluster); when(datalakeResourcesService.findById(anyLong())).thenReturn(Optional.of(datalakeResources)); Cluster result = underTest.configureCluster(requestedCluster, user, workspace); Assert.assertTrue(result.getRdsConfigs().isEmpty()); verify(datalakeResourcesService, times(1)).findById(anyLong()); }
@Test public void testConfigureClusterIfSourceClusterContainsDifferentResourceStatusThenTheDefaultOnesWouldNotBeStoredInTheReturnCluster() { Cluster requestedCluster = createBarelyConfiguredRequestedCluster(); DatalakeResources datalakeResources = new DatalakeResources(); datalakeResources.setRdsConfigs(createRdsConfigs(DEFAULT, DEFAULT_DELETED, USER_MANAGED)); when(stackService.getById(TEST_LONG_VALUE)).thenReturn(publicStack); when(publicStack.getId()).thenReturn(TEST_LONG_VALUE); when(publicStackCluster.getId()).thenReturn(TEST_LONG_VALUE); when(publicStack.getCluster()).thenReturn(publicStackCluster); when(datalakeResourcesService.findById(anyLong())).thenReturn(Optional.of(datalakeResources)); Cluster result = underTest.configureCluster(requestedCluster, user, workspace); Assert.assertEquals(0L, result.getRdsConfigs().size()); result.getRdsConfigs().forEach(rdsConfig -> Assert.assertNotEquals(DEFAULT, rdsConfig.getStatus())); }