### Question:
FormEditorHelper { public FieldDefinition switchToField(FieldDefinition originalField, String newBinding) { if (newBinding != null && !"".equals(newBinding)) { Optional<FieldDefinition> availableFieldOptional = availableFields.values() .stream() .filter(availableField -> availableField.getBinding().equals(newBinding)).findFirst(); if (availableFieldOptional.isPresent()) { FieldDefinition availableField = availableFieldOptional.get(); FieldDefinition resultField = fieldManager.getFieldFromProvider(originalField.getFieldType().getTypeName(), availableField.getFieldTypeInfo()); if (resultField == null) { resultField = fieldManager.getFieldFromProvider(availableField.getFieldType().getTypeName(), availableField.getFieldTypeInfo()); } resultField.copyFrom(originalField); resultField.setId(availableField.getId()); resultField.setName(availableField.getName()); resultField.setStandaloneClassName(availableField.getStandaloneClassName()); resultField.setBinding(newBinding); return resultField; } } FieldDefinition resultField = fieldManager.getFieldFromProvider(originalField.getFieldType().getTypeName(), originalField.getFieldTypeInfo()); if (newBinding == null || newBinding.equals("")) { resultField.setName(generateUnboundFieldName(resultField)); resultField.setBinding(""); } resultField.copyFrom(originalField); resultField.setBinding(newBinding); if (resultField.getName() == null) { resultField.setName(newBinding); } return resultField; } @Inject  FormEditorHelper(FieldManager fieldManager,
                            ManagedInstance<EditorFieldLayoutComponent> editorFieldLayoutComponents,
                            SyncBeanManager beanManager); FormModelerContent getContent(); void initHelper(FormModelerContent content); FormDefinition getFormDefinition(); FormModel getFormModel(); void addAvailableFields(); void addAvailableField(FieldDefinition field); void removeAvailableField(FieldDefinition field); FieldDefinition getFormField(String fieldId); void removeField(String fieldId,
                            boolean addToAvailables); boolean modelContainsField(FieldDefinition fieldDefinition); List<String> getCompatibleModelFields(FieldDefinition field); List<String> getCompatibleFieldTypes(FieldDefinition field); FieldDefinition switchToField(FieldDefinition originalField,
                                         String newBinding); FieldDefinition switchToFieldType(FieldDefinition field,
                                             String fieldCode); void saveFormField(FieldDefinition originalField,
                              FieldDefinition fieldCopy); String generateUnboundFieldName(FieldDefinition field); Collection<EditorFieldLayoutComponent> getBaseFieldsDraggables(); Map<String, FieldDefinition> getAvailableFields(); FormEditorRenderingContext getRenderingContext(); @PreDestroy void destroy(); static final String UNBOUND_FIELD_NAME_PREFFIX; }### Answer:
@Test public void testSwitchToNullBinding() { FieldDefinition result = formEditorHelper.switchToField(nameField, null); Assertions.assertThat(result.getId()).isNotEqualTo(nameField.getId()); Assertions.assertThat(result.getName()).isNotEqualTo(nameField.getName()); Assertions.assertThat(result.getBinding()).isNullOrEmpty(); Assertions.assertThat(result.getBinding()).isNotEqualTo(nameField.getBinding()); Assertions.assertThat(result.getStandaloneClassName()).isEqualTo(nameField.getStandaloneClassName()); }
@Test public void testSwitchToDynamicBinding() { FieldDefinition result = formEditorHelper.switchToField(nameField, DYNAMIC_BINDING); Assertions.assertThat(result.getId()).isNotEqualTo(nameField.getId()); Assertions.assertThat(result.getName()).isEqualTo(DYNAMIC_BINDING); Assertions.assertThat(result.getBinding()).isEqualTo(DYNAMIC_BINDING); Assertions.assertThat(result.getStandaloneClassName()).isEqualTo(nameField.getStandaloneClassName()); }