GetSegmentsFieldValueNameMVCResourceCommand extends BaseMVCResourceCommand { protected JSONObject getFieldValueNameJSONObject( String entityName, String fieldName, String fieldValue, Locale locale) { Optional<String> fieldValueNameOptional = _getFieldValueName( entityName, fieldName, fieldValue, locale); return JSONUtil.put( "fieldValueName", fieldValueNameOptional.orElse(null)); }    }
@Test public void testGetFieldValueNameJSONObjectWithExistingSegmentsFieldCustomizer() { String entityName = RandomTestUtil.randomString(); String fieldName = RandomTestUtil.randomString(); String fieldValue = RandomTestUtil.randomString(); String fieldValueName = RandomTestUtil.randomString(); Locale locale = LocaleUtil.getDefault(); Mockito.doReturn( Optional.of( _createSegmentsFieldCustomizer( fieldValue, fieldValueName, locale)) ).when( _segmentsFieldCustomizerRegistry ).getSegmentsFieldCustomizerOptional( entityName, fieldName ); JSONObject jsonObject = _getSegmentsFieldValueNameMVCResourceCommand. getFieldValueNameJSONObject( entityName, fieldName, fieldValue, locale); JSONObject expectedJSONObject = JSONUtil.put( "fieldValueName", fieldValueName); Assert.assertEquals( expectedJSONObject.toJSONString(), jsonObject.toJSONString()); }
@Test public void testGetFieldValueNameJSONObjectWithNonexistingSegmentsFieldCustomizer() { String entityName = RandomTestUtil.randomString(); String fieldName = RandomTestUtil.randomString(); Mockito.doReturn( Optional.empty() ).when( _segmentsFieldCustomizerRegistry ).getSegmentsFieldCustomizerOptional( entityName, fieldName ); JSONObject jsonObject = _getSegmentsFieldValueNameMVCResourceCommand. getFieldValueNameJSONObject( entityName, fieldName, RandomTestUtil.randomString(), LocaleUtil.getDefault()); Assert.assertEquals("{}", jsonObject.toJSONString()); }