Author: konstantin.mishin
Date: 2010-03-12 14:59:36 -0500 (Fri, 12 Mar 2010)
New Revision: 16572
Added:
root/ui-sandbox/trunk/components/tables/ui/src/test/java/org/richfaces/component/UIColumnTest.java
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java
Log:
RF-8118 RF-8119 unit test
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java 2010-03-12
19:48:31 UTC (rev 16571)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/java/org/richfaces/component/UIColumn.java 2010-03-12
19:59:36 UTC (rev 16572)
@@ -41,7 +41,7 @@
}
public SortOrder getSortOrder() {
- return (SortOrder) getStateHelper().eval(PropertyKeys.sortOrder);
+ return (SortOrder) getStateHelper().eval(PropertyKeys.sortOrder,
SortOrder.UNSORTED);
}
public void setFilter(Filter<?> filter) {
Added:
root/ui-sandbox/trunk/components/tables/ui/src/test/java/org/richfaces/component/UIColumnTest.java
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/test/java/org/richfaces/component/UIColumnTest.java
(rev 0)
+++
root/ui-sandbox/trunk/components/tables/ui/src/test/java/org/richfaces/component/UIColumnTest.java 2010-03-12
19:59:36 UTC (rev 16572)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.richfaces.component;
+
+import static org.easymock.EasyMock.expect;
+
+import java.util.Comparator;
+
+import javax.el.ValueExpression;
+import javax.swing.SortOrder;
+
+import junit.framework.Assert;
+
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.richfaces.model.Filter;
+import org.richfaces.model.FilterField;
+import org.richfaces.model.SortField;
+
+/**
+ * @author Konstantin Mishin
+ *
+ */
+public class UIColumnTest {
+
+ private MockFacesEnvironment environment;
+ private UIColumn column;
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ environment = MockFacesEnvironment.createEnvironment();
+ column = new UIColumn();
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ environment.verify();
+ environment.release();
+ environment = null;
+ column = null;
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.component.UIColumn#setSortOrder(javax.swing.SortOrder)} and
+ * {@link org.richfaces.component.UIColumn#getSortOrder()}.
+ */
+ @Test
+ public final void testSortOrder() {
+ Assert.assertEquals(SortOrder.UNSORTED, column.getSortOrder());
+ column.setSortOrder(SortOrder.ASCENDING);
+ Assert.assertEquals(SortOrder.ASCENDING, column.getSortOrder());
+ environment.replay();
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.component.UIColumn#setFilter(org.richfaces.model.Filter)} and
+ * {@link org.richfaces.component.UIColumn#getFilter()}.
+ */
+ @Test
+ public final void testFilter() {
+ Assert.assertNull(column.getFilter());
+ Filter<?> filter = new Filter<Object>() {
+ @Override
+ public boolean accept(Object t) {
+ return false;
+ }
+ };
+ column.setFilter(filter);
+ Assert.assertSame(filter, column.getFilter());
+ environment.replay();
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.component.UIColumn#setFilterValue(java.lang.Object)} and
+ * {@link org.richfaces.component.UIColumn#getFilterValue()}.
+ */
+ @Test
+ public final void testFilterValue() {
+ Assert.assertNull(column.getFilterValue());
+ Object object = new Object();
+ column.setFilterValue(object);
+ Assert.assertEquals(object, column.getFilterValue());
+ environment.replay();
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.component.UIColumn#setComparator(java.util.Comparator)} and
+ * {@link org.richfaces.component.UIColumn#getComparator()}.
+ */
+ @Test
+ public final void testComparator() {
+ Assert.assertNull(column.getComparator());
+ Comparator<?> comparator = new Comparator<Object>() {
+ @Override
+ public int compare(Object o1, Object o2) {
+ return 0;
+ }
+ };
+ column.setComparator(comparator);
+ Assert.assertSame(comparator, column.getComparator());
+ environment.replay();
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIColumn#getFilterField()}.
+ */
+ @Test
+ public final void testGetFilterField() {
+ Assert.assertNull(column.getFilterField());
+ ValueExpression expression = environment.createMock(ValueExpression.class);
+ expect(expression.isLiteralText()).andStubReturn(false);
+ environment.replay();
+ Filter<?> filter = new Filter<Object>() {
+ @Override
+ public boolean accept(Object t) {
+ return false;
+ }
+ };
+ Object object = new Object();
+ column.setValueExpression("filterExpression", expression);
+ column.setFilter(filter);
+ column.setFilterValue(object);
+ FilterField filterField = column.getFilterField();
+ Assert.assertEquals(expression, filterField.getFilterExpression());
+ Assert.assertSame(filter, filterField.getFilter());
+ Assert.assertEquals(object, filterField.getFilterValue());
+ }
+
+ /**
+ * Test method for {@link org.richfaces.component.UIColumn#getSortField()}.
+ */
+ @Test
+ public final void testGetSortField() {
+ Assert.assertNull(column.getSortField());
+ ValueExpression expression = environment.createMock(ValueExpression.class);
+ expect(expression.isLiteralText()).andStubReturn(false);
+ environment.replay();
+ Comparator<?> comparator = new Comparator<Object>() {
+ @Override
+ public int compare(Object o1, Object o2) {
+ return 0;
+ }
+ };
+ column.setSortOrder(SortOrder.ASCENDING);
+ column.setValueExpression("sortBy", expression);
+ column.setComparator(comparator);
+ SortField sortField = column.getSortField();
+ Assert.assertEquals(SortOrder.ASCENDING, sortField.getSortOrder());
+ Assert.assertEquals(expression, sortField.getSortBy());
+ Assert.assertSame(comparator, sortField.getComparator());
+ }
+
+}