/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.dynamic.data.mapping.type.radio.internal; import com.liferay.dynamic.data.mapping.model.DDMFormFieldOptions; import com.liferay.portal.json.JSONFactoryImpl; import com.liferay.portal.kernel.util.LocaleUtil; import com.liferay.portal.kernel.util.StringPool; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import org.junit.Assert; import org.junit.Test; /** * @author Marcellus Tavares */ public class RadioDDMFormFieldContextHelperTest { @Test public void testGetOptions() { List<Object> expectedOptions = new ArrayList<>(); expectedOptions.add(createOption("Label 1", "value 1")); expectedOptions.add(createOption("Label 2", "value 2")); expectedOptions.add(createOption("Label 3", "value 3")); DDMFormFieldOptions ddmFormFieldOptions = createDDMFormFieldOptions(); List<Object> actualOptions = getActualOptions( ddmFormFieldOptions, LocaleUtil.US); Assert.assertEquals(expectedOptions, actualOptions); } protected DDMFormFieldOptions createDDMFormFieldOptions() { DDMFormFieldOptions ddmFormFieldOptions = new DDMFormFieldOptions(); ddmFormFieldOptions.addOptionLabel("value 1", LocaleUtil.US, "Label 1"); ddmFormFieldOptions.addOptionLabel("value 2", LocaleUtil.US, "Label 2"); ddmFormFieldOptions.addOptionLabel("value 3", LocaleUtil.US, "Label 3"); return ddmFormFieldOptions; } protected Map<String, String> createOption(String label, String value) { Map<String, String> option = new HashMap<>(); option.put("label", label); option.put("value", value); return option; } protected List<Object> getActualOptions( DDMFormFieldOptions ddmFormFieldOptions, Locale locale) { RadioDDMFormFieldContextHelper radioDDMFormFieldContextHelper = new RadioDDMFormFieldContextHelper( new JSONFactoryImpl(), ddmFormFieldOptions, StringPool.BLANK, null, locale); return radioDDMFormFieldContextHelper.getOptions(); } }