### Question:
DefaultDescriptorGlobalConfigUtility { public Optional<FieldModel> getFieldModel() throws AlertException { Optional<ConfigurationModel> configurationModelOptional = getConfiguration(); if (configurationModelOptional.isPresent()) { ConfigurationModel configurationModel = configurationModelOptional.get(); FieldModel fieldModel = configurationFieldModelConverter.convertToFieldModel(configurationModel); return Optional.ofNullable(apiAction.afterGetAction(fieldModel)); } return Optional.empty(); } DefaultDescriptorGlobalConfigUtility(DescriptorKey descriptorKey, ConfigurationAccessor configurationAccessor, ApiAction apiAction,
        ConfigurationFieldModelConverter configurationFieldModelConverter); DescriptorKey getKey(); boolean doesConfigurationExist(); Optional<ConfigurationModel> getConfiguration(); Optional<FieldModel> getFieldModel(); FieldModel save(FieldModel fieldModel); FieldModel update(Long id, FieldModel fieldModel);  }### Answer:
@Test public void testGetFieldModelEmptyConfiguration() throws Exception { DescriptorKey descriptorKey = createDescriptorKey(); ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class); ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class); DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationAccessor, null, converter); assertFalse(configUtility.getFieldModel().isPresent()); }
@Test public void testGetFieldModel() throws Exception { DescriptorKey descriptorKey = createDescriptorKey(); FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of()); ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class); ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class); ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class); ApiAction apiAction = Mockito.mock(ApiAction.class); Mockito.when(configurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel)); Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel); Mockito.when(apiAction.afterGetAction(Mockito.eq(fieldModel))).thenReturn(fieldModel); DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationAccessor, apiAction, converter); FieldModel actualFieldModel = configUtility.getFieldModel().orElse(null); assertEquals(fieldModel, actualFieldModel); }
@Test public void testGetFieldModelActionNull() throws Exception { DescriptorKey descriptorKey = createDescriptorKey(); FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of()); ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class); ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class); ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class); ApiAction apiAction = Mockito.mock(ApiAction.class); Mockito.when(configurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel)); Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel); Mockito.when(apiAction.afterGetAction(Mockito.eq(fieldModel))).thenReturn(null); DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationAccessor, apiAction, converter); Optional<FieldModel> actualFieldModel = configUtility.getFieldModel(); assertFalse(actualFieldModel.isPresent()); }