/** * 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.date.internal; import com.liferay.dynamic.data.mapping.model.DDMForm; import com.liferay.dynamic.data.mapping.model.DDMFormField; import com.liferay.dynamic.data.mapping.model.UnlocalizedValue; import com.liferay.dynamic.data.mapping.storage.DDMFormFieldValue; import com.liferay.dynamic.data.mapping.storage.DDMFormValues; import com.liferay.dynamic.data.mapping.test.util.DDMFormTestUtil; import com.liferay.dynamic.data.mapping.test.util.DDMFormValuesTestUtil; import com.liferay.portal.kernel.util.DateFormatFactoryUtil; import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil; import com.liferay.portal.kernel.util.LocaleUtil; import com.liferay.portal.kernel.util.StringPool; import com.liferay.portal.util.DateFormatFactoryImpl; import com.liferay.portal.util.FastDateFormatFactoryImpl; import org.junit.Assert; import org.junit.Before; import org.junit.Test; /** * @author Bruno Basto */ public class DateDDMFormFieldValueRendererTest { @Before public void setUp() { setUpDateFormatFactoryUtil(); setUpFastDateFormatFactoryUtil(); } @Test public void testRender() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createDDMFormField( "birthday", "Birthday", "date", "string", false, false, false); ddmForm.addDDMFormField(ddmFormField); DDMFormValues ddmFormValues = DDMFormValuesTestUtil.createDDMFormValues( ddmForm); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createDDMFormFieldValue( "birthday", new UnlocalizedValue("2015-01-25")); ddmFormValues.addDDMFormFieldValue(ddmFormFieldValue); DateDDMFormFieldValueRenderer dateDDMFormFieldValueRenderer = new DateDDMFormFieldValueRenderer(); Assert.assertEquals( "1/25/15", dateDDMFormFieldValueRenderer.render( ddmFormFieldValue, LocaleUtil.US)); Assert.assertEquals( "25/01/15", dateDDMFormFieldValueRenderer.render( ddmFormFieldValue, LocaleUtil.BRAZIL)); ddmFormFieldValue.setValue(new UnlocalizedValue("")); Assert.assertEquals( StringPool.BLANK, dateDDMFormFieldValueRenderer.render( ddmFormFieldValue, LocaleUtil.US)); } protected void setUpDateFormatFactoryUtil() { DateFormatFactoryUtil dateFormatFactoryUtil = new DateFormatFactoryUtil(); dateFormatFactoryUtil.setDateFormatFactory(new DateFormatFactoryImpl()); } protected void setUpFastDateFormatFactoryUtil() { FastDateFormatFactoryUtil fastDateFormatFactoryUtil = new FastDateFormatFactoryUtil(); fastDateFormatFactoryUtil.setFastDateFormatFactory( new FastDateFormatFactoryImpl()); } }