CheckboxDDMFormFieldTemplateContextContributor implements DDMFormFieldTemplateContextContributor { @Override public Map<String, Object> getParameters( DDMFormField ddmFormField, DDMFormFieldRenderingContext ddmFormFieldRenderingContext) { return HashMapBuilder.<String, Object>put( "predefinedValue", GetterUtil.getBoolean( getPredefinedValue(ddmFormField, ddmFormFieldRenderingContext)) ).put( "showAsSwitcher", GetterUtil.getBoolean(ddmFormField.getProperty("showAsSwitcher")) ).put( "value", GetterUtil.getBoolean(ddmFormFieldRenderingContext.getValue()) ).build(); }  @Override Map<String, Object> getParameters(
		DDMFormField ddmFormField,
		DDMFormFieldRenderingContext ddmFormFieldRenderingContext);  }
@Test public void testGetNotDefinedPredefinedValue() { DDMFormField ddmFormField = new DDMFormField("field", "checkbox"); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setLocale(LocaleUtil.US); Map<String, Object> parameters = _checkboxDDMFormFieldTemplateContextContributor.getParameters( ddmFormField, ddmFormFieldRenderingContext); boolean predefinedValue = (boolean)parameters.get("predefinedValue"); Assert.assertEquals(false, predefinedValue); }
@Test public void testGetPredefinedValueFalse() { DDMFormField ddmFormField = new DDMFormField("field", "checkbox"); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setLocale(LocaleUtil.US); LocalizedValue predefinedValue = new LocalizedValue(LocaleUtil.US); predefinedValue.addString(LocaleUtil.US, StringPool.FALSE); ddmFormField.setProperty("predefinedValue", predefinedValue); Map<String, Object> parameters = _checkboxDDMFormFieldTemplateContextContributor.getParameters( ddmFormField, ddmFormFieldRenderingContext); boolean actualPredefinedValue = (boolean)parameters.get( "predefinedValue"); Assert.assertEquals(false, actualPredefinedValue); }
@Test public void testGetPredefinedValueTrue() { DDMFormField ddmFormField = new DDMFormField("field", "checkbox"); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setLocale(LocaleUtil.US); LocalizedValue predefinedValue = new LocalizedValue(LocaleUtil.US); predefinedValue.addString(LocaleUtil.US, StringPool.TRUE); ddmFormField.setProperty("predefinedValue", predefinedValue); Map<String, Object> parameters = _checkboxDDMFormFieldTemplateContextContributor.getParameters( ddmFormField, ddmFormFieldRenderingContext); boolean actualPredefinedValue = (boolean)parameters.get( "predefinedValue"); Assert.assertEquals(true, actualPredefinedValue); }