import java.util.HashMap;
import java.util.Map;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-public class DateTimeServiceTest extends TestCase {
+public class DateTimeServiceTest {
final long MILLISECONDS_PER_DAY = 24 * 3600 * 1000;
* calculates the ISO week number like we do.
*
*/
+ @Test
public void testISOWeekNumbers() {
Calendar c = Calendar.getInstance();
c.set(1990, 1, 1);
Date d = new Date(start + i * MILLISECONDS_PER_DAY);
int expected = getCalendarISOWeekNr(d);
int calculated = DateTimeService.getISOWeekNumber(d);
- assertEquals(d + " should be week " + expected, expected,
+ Assert.assertEquals(d + " should be week " + expected, expected,
calculated);
}
* {@link Calendar}).
*
*/
+ @Test
public void testSampleISOWeekNumbers() {
for (Date d : isoWeekNumbers.keySet()) {
// System.out.println("Sample: " + d);
int expected = isoWeekNumbers.get(d);
int calculated = DateTimeService.getISOWeekNumber(d);
- assertEquals(d + " should be week " + expected
+ Assert.assertEquals(d + " should be week " + expected
+ " (Java Calendar is wrong?)", expected,
getCalendarISOWeekNr(d));
- assertEquals(d + " should be week " + expected, expected,
+ Assert.assertEquals(d + " should be week " + expected, expected,
calculated);
}
*/
package com.vaadin.client;
-import junit.framework.TestCase;
-
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.client.componentlocator.LocatorUtil;
/*
* Test LocatorUtil.isUIElement() & isNotificaitonElement methods
*/
-public class LocatorUtilTest extends TestCase {
+public class LocatorUtilTest {
+ @Test
public void testIsUI1() {
boolean isUI = LocatorUtil.isUIElement("com.vaadin.ui.UI");
Assert.assertTrue(isUI);
}
+ @Test
public void testIsUI2() {
boolean isUI = LocatorUtil.isUIElement("/com.vaadin.ui.UI");
Assert.assertTrue(isUI);
}
+ @Test
public void testIsUI3() {
boolean isUI = LocatorUtil
.isUIElement("//com.vaadin.ui.UI[RandomString");
Assert.assertTrue(isUI);
}
+ @Test
public void testIsUI4() {
boolean isUI = LocatorUtil.isUIElement("//com.vaadin.ui.UI[0]");
Assert.assertTrue(isUI);
}
+ @Test
public void testIsNotification1() {
boolean isUI = LocatorUtil
.isNotificationElement("com.vaadin.ui.VNotification");
Assert.assertTrue(isUI);
}
+ @Test
public void testIsNotification2() {
boolean isUI = LocatorUtil
.isNotificationElement("com.vaadin.ui.Notification");
Assert.assertTrue(isUI);
}
+ @Test
public void testIsNotification3() {
boolean isUI = LocatorUtil
.isNotificationElement("/com.vaadin.ui.VNotification[");
Assert.assertTrue(isUI);
}
+ @Test
public void testIsNotification4() {
boolean isUI = LocatorUtil
.isNotificationElement("//com.vaadin.ui.VNotification[0]");
package com.vaadin.client;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.shared.VBrowserDetails;
-public class VBrowserDetailsUserAgentParserTest extends TestCase {
+public class VBrowserDetailsUserAgentParserTest {
private static final String FIREFOX30_WINDOWS = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
private static final String FIREFOX30_LINUX = "Mozilla/5.0 (X11; U; Linux x86_64; es-ES; rv:1.9.0.12) Gecko/2009070811 Ubuntu/9.04 (jaunty) Firefox/3.0.12";
private static final String EDGE_WINDOWS_10 = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240";
+ @Test
public void testSafari3() {
VBrowserDetails bd = new VBrowserDetails(SAFARI3_WINDOWS);
assertWebKit(bd);
assertWindows(bd);
}
+ @Test
public void testSafari4() {
VBrowserDetails bd = new VBrowserDetails(SAFARI4_MAC);
assertWebKit(bd);
assertMacOSX(bd);
}
+ @Test
public void testIPhoneIOS6Homescreen() {
VBrowserDetails bd = new VBrowserDetails(
IPHONE_IOS_6_1_HOMESCREEN_SIMULATOR);
assertIPhone(bd);
}
+ @Test
public void testIPhoneIOS5() {
VBrowserDetails bd = new VBrowserDetails(IPHONE_IOS_5_1);
assertWebKit(bd);
assertIPhone(bd);
}
+ @Test
public void testIPhoneIOS4() {
VBrowserDetails bd = new VBrowserDetails(IPHONE_IOS_4_0);
assertWebKit(bd);
assertIPhone(bd);
}
+ @Test
public void testIPadIOS4() {
VBrowserDetails bd = new VBrowserDetails(IPAD_IOS_4_3_1);
assertWebKit(bd);
assertIPad(bd);
}
+ @Test
public void testAndroid21() {
VBrowserDetails bd = new VBrowserDetails(ANDROID_HTC_2_1);
assertWebKit(bd);
}
+ @Test
public void testAndroid22() {
VBrowserDetails bd = new VBrowserDetails(ANDROID_GOOGLE_NEXUS_2_2);
assertWebKit(bd);
assertAndroid(bd, 2, 2);
}
+ @Test
public void testAndroid30() {
VBrowserDetails bd = new VBrowserDetails(ANDROID_MOTOROLA_3_0);
assertWebKit(bd);
assertAndroid(bd, 3, 0);
}
+ @Test
public void testAndroid40Chrome() {
VBrowserDetails bd = new VBrowserDetails(
ANDROID_GALAXY_NEXUS_4_0_4_CHROME);
assertEquals(i, bd.getOperatingSystemMinorVersion());
}
+ @Test
public void testChrome3() {
VBrowserDetails bd = new VBrowserDetails(CHROME3_MAC);
assertWebKit(bd);
assertMacOSX(bd);
}
+ @Test
public void testChrome4() {
VBrowserDetails bd = new VBrowserDetails(CHROME4_WINDOWS);
assertWebKit(bd);
assertWindows(bd);
}
+ @Test
public void testFirefox3() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX30_WINDOWS);
assertGecko(bd);
assertLinux(bd);
}
+ @Test
public void testFirefox33Android() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX33_ANDROID);
assertGecko(bd);
assertAndroid(bd, -1, -1);
}
+ @Test
public void testFirefox35() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX35_WINDOWS);
assertGecko(bd);
assertWindows(bd);
}
+ @Test
public void testFirefox36() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX36_WINDOWS);
assertGecko(bd);
assertWindows(bd);
}
+ @Test
public void testFirefox30b5() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX_30B5_MAC);
assertGecko(bd);
assertMacOSX(bd);
}
+ @Test
public void testFirefox40b11() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX_40B11_WIN);
assertGecko(bd);
assertWindows(bd);
}
+ @Test
public void testFirefox40b7() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX_40B7_WIN);
assertGecko(bd);
assertWindows(bd);
}
+ @Test
public void testKonquerorLinux() {
// Just ensure detection does not crash
VBrowserDetails bd = new VBrowserDetails(KONQUEROR_LINUX);
assertLinux(bd);
}
+ @Test
public void testFirefox36b() {
VBrowserDetails bd = new VBrowserDetails(FIREFOX36B_MAC);
assertGecko(bd);
assertMacOSX(bd);
}
+ @Test
public void testOpera964() {
VBrowserDetails bd = new VBrowserDetails(OPERA964_WINDOWS);
assertPresto(bd);
assertWindows(bd);
}
+ @Test
public void testOpera1010() {
VBrowserDetails bd = new VBrowserDetails(OPERA1010_WINDOWS);
assertPresto(bd);
assertWindows(bd);
}
+ @Test
public void testOpera1050() {
VBrowserDetails bd = new VBrowserDetails(OPERA1050_WINDOWS);
assertPresto(bd);
assertWindows(bd);
}
+ @Test
public void testIE6() {
VBrowserDetails bd = new VBrowserDetails(IE6_WINDOWS);
assertEngineVersion(bd, -1);
assertWindows(bd);
}
+ @Test
public void testIE7() {
VBrowserDetails bd = new VBrowserDetails(IE7_WINDOWS);
assertEngineVersion(bd, -1);
assertWindows(bd);
}
+ @Test
public void testIE8() {
VBrowserDetails bd = new VBrowserDetails(IE8_WINDOWS);
assertTrident(bd);
assertWindows(bd);
}
+ @Test
public void testIE8CompatibilityMode() {
VBrowserDetails bd = new VBrowserDetails(IE8_IN_IE7_MODE_WINDOWS);
bd.setIEMode(7);
assertWindows(bd);
}
+ @Test
public void testIE9() {
VBrowserDetails bd = new VBrowserDetails(IE9_BETA_WINDOWS_7);
assertTrident(bd);
assertWindows(bd);
}
+ @Test
public void testIE9InIE7CompatibilityMode() {
VBrowserDetails bd = new VBrowserDetails(IE9_IN_IE7_MODE_WINDOWS_7);
// bd.setIE8InCompatibilityMode();
assertWindows(bd);
}
+ @Test
public void testIE9InIE8CompatibilityMode() {
VBrowserDetails bd = new VBrowserDetails(IE9_BETA_IN_IE8_MODE_WINDOWS_7);
// bd.setIE8InCompatibilityMode();
assertWindows(bd);
}
+ @Test
public void testIE10() {
VBrowserDetails bd = new VBrowserDetails(IE10_WINDOWS_8);
assertTrident(bd);
assertWindows(bd);
}
+ @Test
public void testIE11() {
VBrowserDetails bd = new VBrowserDetails(IE11_WINDOWS_7);
assertTrident(bd);
assertWindows(bd);
}
+ @Test
public void testIE11WindowsPhone81Update() {
VBrowserDetails bd = new VBrowserDetails(IE11_WINDOWS_PHONE_8_1_UPDATE);
assertTrident(bd);
assertWindows(bd, true);
}
+ @Test
public void testEdgeWindows10() {
VBrowserDetails bd = new VBrowserDetails(EDGE_WINDOWS_10);
assertEdge(bd);
private void assertEngineVersion(VBrowserDetails browserDetails,
float version) {
- assertEquals(version, browserDetails.getBrowserEngineVersion());
+ assertEquals(version, browserDetails.getBrowserEngineVersion(), 0.01d);
}
--- /dev/null
+package com.vaadin.data.fieldgroup;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.Transactional;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.data.util.TransactionalPropertyWrapper;
+import com.vaadin.ui.Field;
+import com.vaadin.ui.TextField;
+
+public class FieldGroupTest {
+
+ private FieldGroup sut;
+ private Field field;
+
+ @Before
+ public void setup() {
+ sut = new FieldGroup();
+ field = mock(Field.class);
+ }
+
+ @Test
+ public void fieldIsBound() {
+ sut.bind(field, "foobar");
+
+ assertThat(sut.getField("foobar"), is(field));
+ }
+
+ @Test(expected = FieldGroup.BindException.class)
+ public void cannotBindToAlreadyBoundProperty() {
+ sut.bind(field, "foobar");
+ sut.bind(mock(Field.class), "foobar");
+ }
+
+ @Test(expected = FieldGroup.BindException.class)
+ public void cannotBindNullField() {
+ sut.bind(null, "foobar");
+ }
+
+ public void canUnbindWithoutItem() {
+ sut.bind(field, "foobar");
+
+ sut.unbind(field);
+ assertThat(sut.getField("foobar"), is(nullValue()));
+ }
+
+ @Test
+ public void wrapInTransactionalProperty_provideCustomImpl_customTransactionalWrapperIsUsed() {
+ Bean bean = new Bean();
+ FieldGroup group = new FieldGroup() {
+ @Override
+ protected <T> Transactional<T> wrapInTransactionalProperty(
+ Property<T> itemProperty) {
+ return new TransactionalPropertyImpl(itemProperty);
+ }
+ };
+ group.setItemDataSource(new BeanItem<Bean>(bean));
+ TextField field = new TextField();
+ group.bind(field, "name");
+
+ Property propertyDataSource = field.getPropertyDataSource();
+ Assert.assertTrue("Custom implementation of transactional property "
+ + "has not been used",
+ propertyDataSource instanceof TransactionalPropertyImpl);
+ }
+
+ public static class TransactionalPropertyImpl<T> extends
+ TransactionalPropertyWrapper<T> {
+
+ public TransactionalPropertyImpl(Property<T> wrappedProperty) {
+ super(wrappedProperty);
+ }
+
+ }
+
+ public static class Bean {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+}
+++ /dev/null
-package com.vaadin.data.fieldgroup;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.mockito.Mockito.mock;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.vaadin.data.Property;
-import com.vaadin.data.Property.Transactional;
-import com.vaadin.data.util.BeanItem;
-import com.vaadin.data.util.TransactionalPropertyWrapper;
-import com.vaadin.ui.Field;
-import com.vaadin.ui.TextField;
-
-public class FieldGroupTests {
-
- private FieldGroup sut;
- private Field field;
-
- @Before
- public void setup() {
- sut = new FieldGroup();
- field = mock(Field.class);
- }
-
- @Test
- public void fieldIsBound() {
- sut.bind(field, "foobar");
-
- assertThat(sut.getField("foobar"), is(field));
- }
-
- @Test(expected = FieldGroup.BindException.class)
- public void cannotBindToAlreadyBoundProperty() {
- sut.bind(field, "foobar");
- sut.bind(mock(Field.class), "foobar");
- }
-
- @Test(expected = FieldGroup.BindException.class)
- public void cannotBindNullField() {
- sut.bind(null, "foobar");
- }
-
- public void canUnbindWithoutItem() {
- sut.bind(field, "foobar");
-
- sut.unbind(field);
- assertThat(sut.getField("foobar"), is(nullValue()));
- }
-
- @Test
- public void wrapInTransactionalProperty_provideCustomImpl_customTransactionalWrapperIsUsed() {
- Bean bean = new Bean();
- FieldGroup group = new FieldGroup() {
- @Override
- protected <T> Transactional<T> wrapInTransactionalProperty(
- Property<T> itemProperty) {
- return new TransactionalPropertyImpl(itemProperty);
- }
- };
- group.setItemDataSource(new BeanItem<Bean>(bean));
- TextField field = new TextField();
- group.bind(field, "name");
-
- Property propertyDataSource = field.getPropertyDataSource();
- Assert.assertTrue("Custom implementation of transactional property "
- + "has not been used",
- propertyDataSource instanceof TransactionalPropertyImpl);
- }
-
- public static class TransactionalPropertyImpl<T> extends
- TransactionalPropertyWrapper<T> {
-
- public TransactionalPropertyImpl(Property<T> wrappedProperty) {
- super(wrappedProperty);
- }
-
- }
-
- public static class Bean {
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
- }
-}
package com.vaadin.data.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import junit.framework.TestCase;
-
import org.junit.Assert;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.filter.SimpleStringFilter;
-public abstract class AbstractContainerTestBase extends TestCase {
+public abstract class AbstractContainerTestBase {
/**
* Helper class for testing e.g. listeners expecting events to be fired.
package com.vaadin.data.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.Collection;
import com.vaadin.data.Container;
package com.vaadin.data.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
return new BeanContainer<String, ClassName>(ClassName.class);
}
- @Override
+ @Before
public void setUp() {
nameToBean.clear();
return false;
}
+ @Test
public void testGetType_existingProperty_typeReturned() {
BeanContainer<String, ClassName> container = getContainer();
Assert.assertEquals(
String.class, container.getType("simpleName"));
}
+ @Test
public void testGetType_notExistingProperty_nullReturned() {
BeanContainer<String, ClassName> container = getContainer();
Assert.assertNull("Not null type is returned for property ''",
container.getType(""));
}
+ @Test
public void testBasicOperations() {
testBasicContainerOperations(getContainer());
}
+ @Test
public void testFiltering() {
testContainerFiltering(getContainer());
}
+ @Test
public void testSorting() {
testContainerSorting(getContainer());
}
+ @Test
public void testSortingAndFiltering() {
testContainerSortingAndFiltering(getContainer());
}
// duplicated from parent class and modified - adding items to
// BeanContainer differs from other containers
+ @Test
public void testContainerOrdered() {
BeanContainer<String, String> container = new BeanContainer<String, String>(
String.class);
// TODO test Container.Indexed interface operation - testContainerIndexed()?
+ @Test
public void testAddItemAt() {
BeanContainer<String, String> container = new BeanContainer<String, String>(
String.class);
assertEquals("id4", container.getIdByIndex(3));
}
+ @Test
public void testUnsupportedMethods() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
assertEquals(1, container.size());
}
+ @Test
public void testRemoveContainerProperty() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
Assert.assertNull(container.getItem("John").getItemProperty("name"));
}
+ @Test
public void testAddNullBeans() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
assertEquals(0, container.size());
}
+ @Test
public void testAddNullId() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
assertEquals(0, container.size());
}
+ @Test
public void testEmptyContainer() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
// could test more about empty container
}
+ @Test
public void testAddBeanWithoutResolver() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
assertEquals(0, container.size());
}
+ @Test
public void testAddAllWithNullItemId() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
assertEquals(3, container.size());
}
+ @Test
public void testAddBeanWithNullResolver() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
assertEquals(0, container.size());
}
+ @Test
public void testAddBeanWithResolver() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
assertEquals(5, container.size());
}
+ @Test
public void testAddNullBeansWithResolver() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
assertEquals(0, container.size());
}
+ @Test
public void testAddBeanWithPropertyResolver() {
BeanContainer<String, Person> container = new BeanContainer<String, Person>(
Person.class);
assertEquals(5, container.size());
}
+ @Test
public void testAddNestedContainerProperty() {
BeanContainer<String, NestedMethodPropertyTest.Person> container = new BeanContainer<String, NestedMethodPropertyTest.Person>(
NestedMethodPropertyTest.Person.class);
.getValue());
}
+ @Test
public void testNestedContainerPropertyWithNullBean() {
BeanContainer<String, NestedMethodPropertyTest.Person> container = new BeanContainer<String, NestedMethodPropertyTest.Person>(
NestedMethodPropertyTest.Person.class);
package com.vaadin.data.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.data.Container;
import com.vaadin.data.Container.Indexed.ItemAddEvent;
return new BeanItemContainer<ClassName>(ClassName.class);
}
- @Override
+ @Before
public void setUp() {
nameToBean.clear();
return false;
}
+ @Test
public void testGetType_existingProperty_typeReturned() {
BeanItemContainer<ClassName> container = getContainer();
Assert.assertEquals(
String.class, container.getType("simpleName"));
}
+ @Test
public void testGetType_notExistingProperty_nullReturned() {
BeanItemContainer<ClassName> container = getContainer();
Assert.assertNull("Not null type is returned for property ''",
container.getType(""));
}
+ @Test
public void testBasicOperations() {
testBasicContainerOperations(getContainer());
}
+ @Test
public void testFiltering() {
testContainerFiltering(getContainer());
}
+ @Test
public void testSorting() {
testContainerSorting(getContainer());
}
+ @Test
public void testSortingAndFiltering() {
testContainerSortingAndFiltering(getContainer());
}
// duplicated from parent class and modified - adding items to
// BeanItemContainer differs from other containers
+ @Test
public void testContainerOrdered() {
BeanItemContainer<String> container = new BeanItemContainer<String>(
String.class);
}
+ @Test
public void testContainerIndexed() {
testContainerIndexed(getContainer(), nameToBean.get(sampleData[2]), 2,
false, new ClassName("org.vaadin.test.Test", 8888), true);
}
@SuppressWarnings("deprecation")
+ @Test
public void testCollectionConstructors() {
List<ClassName> classNames = new ArrayList<ClassName>();
classNames.add(new ClassName("a.b.c.Def", 1));
// this only applies to the collection constructor with no type parameter
@SuppressWarnings("deprecation")
+ @Test
public void testEmptyCollectionConstructor() {
try {
new BeanItemContainer<ClassName>((Collection<ClassName>) null);
}
}
+ @Test
public void testItemSetChangeListeners() {
BeanItemContainer<ClassName> container = getContainer();
ItemSetChangeCounter counter = new ItemSetChangeCounter();
}
+ @Test
public void testItemSetChangeListenersFiltering() {
BeanItemContainer<ClassName> container = getContainer();
ItemSetChangeCounter counter = new ItemSetChangeCounter();
counter.assertNone();
}
+ @Test
public void testAddRemoveWhileFiltering() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(michael, container.lastItemId());
}
+ @Test
public void testRefilterOnPropertyModification() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(3, container.size());
}
+ @Test
public void testAddAll() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(michael, container.nextItemId(jack));
}
+ @Test
public void testUnsupportedMethods() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(1, container.size());
}
+ @Test
public void testRemoveContainerProperty() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
Assert.assertNull(container.getItem(john).getItemProperty("name"));
}
+ @Test
public void testAddNullBean() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(1, container.size());
}
+ @Test
public void testBeanIdResolver() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertSame(john, container.getBeanIdResolver().getIdForBean(john));
}
+ @Test(expected = IllegalArgumentException.class)
public void testNullBeanClass() {
- try {
- new BeanItemContainer<Object>((Class<Object>) null);
- } catch (IllegalArgumentException e) {
- // should get exception
- }
+ new BeanItemContainer<Object>((Class<Object>) null);
}
+ @Test
public void testAddNestedContainerProperty() {
BeanItemContainer<NestedMethodPropertyTest.Person> container = new BeanItemContainer<NestedMethodPropertyTest.Person>(
NestedMethodPropertyTest.Person.class);
.getValue());
}
+ @Test
public void testNestedContainerPropertyWithNullBean() {
BeanItemContainer<NestedMethodPropertyTest.Person> container = new BeanItemContainer<NestedMethodPropertyTest.Person>(
NestedMethodPropertyTest.Person.class);
.getValue());
}
+ @Test
public void testItemAddedEvent() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
EasyMock.verify(addListener);
}
+ @Test
public void testItemAddedEvent_AddedItem() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(bean, capturedEvent.getValue().getFirstItemId());
}
+ @Test
public void testItemAddedEvent_addItemAt_IndexOfAddedItem() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(1, capturedEvent.getValue().getFirstIndex());
}
+ @Test
public void testItemAddedEvent_addItemAfter_IndexOfAddedItem() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(1, capturedEvent.getValue().getFirstIndex());
}
+ @Test
public void testItemAddedEvent_amountOfAddedItems() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(2, capturedEvent.getValue().getAddedItemsCount());
}
+ @Test
public void testItemAddedEvent_someItemsAreFiltered_amountOfAddedItemsIsReducedByAmountOfFilteredItems() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(1, capturedEvent.getValue().getAddedItemsCount());
}
+ @Test
public void testItemAddedEvent_someItemsAreFiltered_addedItemIsTheFirstVisibleItem() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(bean, capturedEvent.getValue().getFirstItemId());
}
+ @Test
public void testItemRemovedEvent() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
EasyMock.verify(removeListener);
}
+ @Test
public void testItemRemovedEvent_RemovedItem() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(bean, capturedEvent.getValue().getFirstItemId());
}
+ @Test
public void testItemRemovedEvent_indexOfRemovedItem() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
assertEquals(1, capturedEvent.getValue().getFirstIndex());
}
+ @Test
public void testItemRemovedEvent_amountOfRemovedItems() {
BeanItemContainer<Person> container = new BeanItemContainer<Person>(
Person.class);
return listener;
}
+ @Test
public void testAddNestedContainerBeanBeforeData() {
BeanItemContainer<NestedMethodPropertyTest.Person> container = new BeanItemContainer<NestedMethodPropertyTest.Person>(
NestedMethodPropertyTest.Person.class);
}
+ @Test
public void testAddNestedContainerBeanAfterData() {
BeanItemContainer<NestedMethodPropertyTest.Person> container = new BeanItemContainer<NestedMethodPropertyTest.Person>(
NestedMethodPropertyTest.Person.class);
import java.util.LinkedHashMap;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.Property;
*
* See also {@link PropertySetItemTest}, which tests the base class.
*/
-public class BeanItemTest extends TestCase {
+public class BeanItemTest {
@SuppressWarnings("unused")
protected static class MySuperClass {
public void setOverride(int i);
}
+ @Test
public void testGetProperties() {
BeanItem<MySuperClass> item = new BeanItem<MySuperClass>(
new MySuperClass());
Assert.assertTrue(itemPropertyIds.contains("superPublic"));
}
+ @Test
public void testGetSuperClassProperties() {
BeanItem<MyClass> item = new BeanItem<MyClass>(new MyClass("bean1"));
Assert.assertTrue(itemPropertyIds.contains("name2"));
}
+ @Test
public void testOverridingProperties() {
BeanItem<MyClass2> item = new BeanItem<MyClass2>(new MyClass2("bean2"));
Assert.assertFalse(item.getItemProperty("name2").isReadOnly());
}
+ @Test
public void testGetInterfaceProperties() throws SecurityException,
NoSuchMethodException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
Assert.assertTrue(property.isReadOnly());
}
+ @Test
public void testGetSuperInterfaceProperties() throws SecurityException,
NoSuchMethodException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
Assert.assertFalse(property.isReadOnly());
}
+ @Test
public void testPropertyExplicitOrder() {
Collection<String> ids = new ArrayList<String>();
ids.add("name");
Assert.assertFalse(it.hasNext());
}
+ @Test
public void testPropertyExplicitOrder2() {
BeanItem<MyClass> item = new BeanItem<MyClass>(new MyClass("bean1"),
new String[] { "name", "superPublic", "name2", "noField" });
Assert.assertFalse(it.hasNext());
}
+ @Test
public void testPropertyBadPropertyName() {
Collection<String> ids = new ArrayList<String>();
ids.add("name3");
Assert.assertFalse(it.hasNext());
}
+ @Test
public void testRemoveProperty() {
BeanItem<MyClass> item = new BeanItem<MyClass>(new MyClass("bean1"));
Assert.assertFalse(itemPropertyIds.contains("name2"));
}
+ @Test
public void testRemoveSuperProperty() {
BeanItem<MyClass> item = new BeanItem<MyClass>(new MyClass("bean1"));
Assert.assertFalse(itemPropertyIds.contains("superPrivate"));
}
+ @Test
public void testPropertyTypes() {
BeanItem<MyClass> item = new BeanItem<MyClass>(new MyClass("bean1"));
.getType()));
}
+ @Test
public void testPropertyReadOnly() {
BeanItem<MyClass> item = new BeanItem<MyClass>(new MyClass("bean1"));
Assert.assertTrue(item.getItemProperty("name2").isReadOnly());
}
+ @Test
public void testCustomProperties() throws Exception {
LinkedHashMap<String, VaadinPropertyDescriptor<MyClass>> propertyDescriptors = new LinkedHashMap<String, VaadinPropertyDescriptor<MyClass>>();
propertyDescriptors.put(
Assert.assertEquals("bean1", item.getItemProperty("myname").getValue());
}
+ @Test
public void testAddRemoveProperty() throws Exception {
MethodPropertyDescriptor<BeanItemTest.MyClass> pd = new MethodPropertyDescriptor<BeanItemTest.MyClass>(
"myname", MyClass.class,
Assert.assertEquals(null, item.getItemProperty("myname"));
}
+ @Test
public void testOverridenGenericMethods() {
BeanItem<SubClass> item = new BeanItem<SubClass>(new SubClass());
package com.vaadin.data.util;
+import org.junit.Test;
public class ContainerHierarchicalWrapperTest extends
AbstractHierarchicalContainerTestBase {
+ @Test
public void testBasicOperations() {
testBasicContainerOperations(new ContainerHierarchicalWrapper(
new IndexedContainer()));
}
+ @Test
public void testHierarchicalContainer() {
testHierarchicalContainer(new ContainerHierarchicalWrapper(
new IndexedContainer()));
}
+ @Test
public void testRemoveSubtree() {
testRemoveHierarchicalWrapperSubtree(new ContainerHierarchicalWrapper(
new IndexedContainer()));
import java.util.Collection;
+import org.junit.Test;
+
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
}
+ @Test
public void testBasicOperations() {
testBasicContainerOperations(new ContainerOrderedWrapper(
new NotOrderedContainer()));
}
+ @Test
public void testOrdered() {
testContainerOrdered(new ContainerOrderedWrapper(
new NotOrderedContainer()));
import java.util.Iterator;
import java.util.Map;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.tests.util.TestUtil;
-public class ContainerSortingTest extends TestCase {
+public class ContainerSortingTest {
private static final String ITEM_DATA_MINUS2_NULL = "Data -2 null";
private static final String ITEM_DATA_MINUS2 = "Data -2";
private static final String PROPERTY_STRING_NULL = "string-null";
private static final String PROPERTY_STRING_ID = "string-not-null";
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
+ @Test
public void testEmptyFilteredIndexedContainer() {
IndexedContainer ic = new IndexedContainer();
}
+ @Test
public void testFilteredIndexedContainer() {
IndexedContainer ic = new IndexedContainer();
ITEM_DATA_MINUS2_NULL, });
}
+ @Test
public void testIndexedContainer() {
IndexedContainer ic = new IndexedContainer();
}
+ @Test
public void testHierarchicalContainer() {
HierarchicalContainer hc = new HierarchicalContainer();
populateContainer(hc);
package com.vaadin.data.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.List;
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.Container;
import com.vaadin.data.Container.Indexed.ItemAddEvent;
public class GeneratedPropertyContainerBasicTest extends
AbstractInMemoryContainerTestBase {
+ @Test
public void testBasicOperations() {
testBasicContainerOperations(createContainer());
}
return new GeneratedPropertyContainer(new IndexedContainer());
}
+ @Test
public void testFiltering() {
testContainerFiltering(createContainer());
}
+ @Test
public void testSorting() {
testContainerSorting(createContainer());
}
+ @Test
public void testSortingAndFiltering() {
testContainerSortingAndFiltering(createContainer());
}
+ @Test
public void testContainerOrdered() {
testContainerOrdered(createContainer());
}
+ @Test
public void testContainerIndexed() {
testContainerIndexed(createContainer(), sampleData[2], 2, true,
"newItemId", true);
}
+ @Test
public void testItemSetChangeListeners() {
GeneratedPropertyContainer container = createContainer();
ItemSetChangeCounter counter = new ItemSetChangeCounter();
}
+ @Test
public void testAddRemoveContainerFilter() {
GeneratedPropertyContainer container = createContainer();
ItemSetChangeCounter counter = new ItemSetChangeCounter();
// TODO other tests should check positions after removing filter etc,
// here concentrating on listeners
+ @Test
public void testItemSetChangeListenersFiltering() {
Container.Indexed container = createContainer();
ItemSetChangeCounter counter = new ItemSetChangeCounter();
counter.assertNone();
}
+ @Test
public void testItemAdd_idSequence() {
GeneratedPropertyContainer container = createContainer();
Object itemId;
assertEquals(Integer.valueOf(4), itemId);
}
+ @Test
public void testItemAddRemove_idSequence() {
GeneratedPropertyContainer container = createContainer();
Object itemId;
Integer.valueOf(2), itemId);
}
+ @Test
public void testItemAddedEvent() {
GeneratedPropertyContainer container = createContainer();
ItemSetChangeListener addListener = createListenerMockFor(container);
EasyMock.verify(addListener);
}
+ @Test
public void testItemAddedEvent_AddedItem() {
GeneratedPropertyContainer container = createContainer();
ItemSetChangeListener addListener = createListenerMockFor(container);
assertEquals(itemId, capturedEvent.getValue().getFirstItemId());
}
+ @Test
public void testItemAddedEvent_IndexOfAddedItem() {
GeneratedPropertyContainer container = createContainer();
ItemSetChangeListener addListener = createListenerMockFor(container);
assertEquals(1, capturedEvent.getValue().getFirstIndex());
}
+ @Test
public void testItemRemovedEvent() {
GeneratedPropertyContainer container = createContainer();
Object itemId = container.addItem();
EasyMock.verify(removeListener);
}
+ @Test
public void testItemRemovedEvent_RemovedItem() {
GeneratedPropertyContainer container = createContainer();
Object itemId = container.addItem();
assertEquals(itemId, capturedEvent.getValue().getFirstItemId());
}
+ @Test
public void testItemRemovedEvent_indexOfRemovedItem() {
GeneratedPropertyContainer container = createContainer();
container.addItem();
assertEquals(1, capturedEvent.getValue().getFirstIndex());
}
+ @Test
public void testItemRemovedEvent_amountOfRemovedItems() {
GeneratedPropertyContainer container = createContainer();
container.addItem();
}
// Ticket 8028
+ @Test
public void testGetItemIdsRangeIndexOutOfBounds() {
GeneratedPropertyContainer ic = createContainer();
try {
}
// Ticket 8028
+ @Test
public void testGetItemIdsRangeIndexOutOfBounds2() {
GeneratedPropertyContainer ic = createContainer();
ic.addItem(new Object());
}
// Ticket 8028
+ @Test
public void testGetItemIdsRangeZeroRange() {
GeneratedPropertyContainer ic = createContainer();
ic.addItem(new Object());
}
// Ticket 8028
+ @Test
public void testGetItemIdsRangeNegativeRange() {
GeneratedPropertyContainer ic = createContainer();
ic.addItem(new Object());
}
// Ticket 8028
+ @Test
public void testGetItemIdsRangeIndexOutOfBoundsDueToSizeChange() {
GeneratedPropertyContainer ic = createContainer();
ic.addItem(new Object());
}
// Ticket 8028
+ @Test
public void testGetItemIdsRangeBaseCase() {
GeneratedPropertyContainer ic = createContainer();
String object1 = new String("Obj1");
}
// test getting non-existing property (#10445)
+ @Test
public void testNonExistingProperty() {
Container ic = createContainer();
String object1 = new String("Obj1");
}
// test getting null property id (#10445)
+ @Test
public void testNullPropertyId() {
Container ic = createContainer();
String object1 = new String("Obj1");
package com.vaadin.data.util;
+import org.junit.Test;
+
public class HierarchicalContainerOrderedWrapperTest extends
AbstractHierarchicalContainerTestBase {
new ContainerHierarchicalWrapper(new IndexedContainer()));
}
+ @Test
public void testBasicOperations() {
testBasicContainerOperations(createContainer());
}
+ @Test
public void testHierarchicalContainer() {
testHierarchicalContainer(createContainer());
}
+ @Test
public void testContainerOrdered() {
testContainerOrdered(createContainer());
}
+ @Test
public void testRemoveSubtree() {
testRemoveHierarchicalWrapperSubtree(createContainer());
}
package com.vaadin.data.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
import com.vaadin.data.Container.Filter;
import com.vaadin.data.Item;
public class HierarchicalContainerTest extends
AbstractHierarchicalContainerTestBase {
+ @Test
public void testBasicOperations() {
testBasicContainerOperations(new HierarchicalContainer());
}
+ @Test
public void testFiltering() {
testContainerFiltering(new HierarchicalContainer());
}
+ @Test
public void testSorting() {
testContainerSorting(new HierarchicalContainer());
}
+ @Test
public void testOrdered() {
testContainerOrdered(new HierarchicalContainer());
}
+ @Test
public void testHierarchicalSorting() {
testHierarchicalSorting(new HierarchicalContainer());
}
+ @Test
public void testSortingAndFiltering() {
testContainerSortingAndFiltering(new HierarchicalContainer());
}
+ @Test
public void testRemovingItemsFromFilteredContainer() {
HierarchicalContainer container = new HierarchicalContainer();
initializeContainer(container);
}
+ @Test
public void testParentWhenRemovingFilterFromContainer() {
HierarchicalContainer container = new HierarchicalContainer();
initializeContainer(container);
}
+ @Test
public void testChangeParentInFilteredContainer() {
HierarchicalContainer container = new HierarchicalContainer();
initializeContainer(container);
}
+ @Test
public void testHierarchicalFilteringWithParents() {
HierarchicalContainer container = new HierarchicalContainer();
initializeContainer(container);
}
+ @Test
public void testRemoveLastChild() {
HierarchicalContainer c = new HierarchicalContainer();
assertFalse(c.hasChildren("root"));
}
+ @Test
public void testRemoveLastChildFromFiltered() {
HierarchicalContainer c = new HierarchicalContainer();
assertFalse(c.hasChildren("root"));
}
+ @Test
public void testHierarchicalFilteringWithoutParents() {
HierarchicalContainer container = new HierarchicalContainer();
package com.vaadin.data.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.List;
import org.easymock.Capture;
import org.easymock.EasyMock;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.Container.Indexed.ItemAddEvent;
import com.vaadin.data.Container.Indexed.ItemRemoveEvent;
public class IndexedContainerTest extends AbstractInMemoryContainerTestBase {
+ @Test
public void testBasicOperations() {
testBasicContainerOperations(new IndexedContainer());
}
+ @Test
public void testFiltering() {
testContainerFiltering(new IndexedContainer());
}
+ @Test
public void testSorting() {
testContainerSorting(new IndexedContainer());
}
+ @Test
public void testSortingAndFiltering() {
testContainerSortingAndFiltering(new IndexedContainer());
}
+ @Test
public void testContainerOrdered() {
testContainerOrdered(new IndexedContainer());
}
+ @Test
public void testContainerIndexed() {
testContainerIndexed(new IndexedContainer(), sampleData[2], 2, true,
"newItemId", true);
}
+ @Test
public void testItemSetChangeListeners() {
IndexedContainer container = new IndexedContainer();
ItemSetChangeCounter counter = new ItemSetChangeCounter();
}
+ @Test
public void testAddRemoveContainerFilter() {
IndexedContainer container = new IndexedContainer();
ItemSetChangeCounter counter = new ItemSetChangeCounter();
// TODO other tests should check positions after removing filter etc,
// here concentrating on listeners
+ @Test
public void testItemSetChangeListenersFiltering() {
IndexedContainer container = new IndexedContainer();
ItemSetChangeCounter counter = new ItemSetChangeCounter();
counter.assertNone();
}
+ @Test
public void testItemAdd_idSequence() {
IndexedContainer container = new IndexedContainer();
Object itemId;
assertEquals(Integer.valueOf(4), itemId);
}
+ @Test
public void testItemAddRemove_idSequence() {
IndexedContainer container = new IndexedContainer();
Object itemId;
Integer.valueOf(2), itemId);
}
+ @Test
public void testItemAddedEvent() {
IndexedContainer container = new IndexedContainer();
ItemSetChangeListener addListener = createListenerMockFor(container);
EasyMock.verify(addListener);
}
+ @Test
public void testItemAddedEvent_AddedItem() {
IndexedContainer container = new IndexedContainer();
ItemSetChangeListener addListener = createListenerMockFor(container);
assertEquals(itemId, capturedEvent.getValue().getFirstItemId());
}
+ @Test
public void testItemAddedEvent_IndexOfAddedItem() {
IndexedContainer container = new IndexedContainer();
ItemSetChangeListener addListener = createListenerMockFor(container);
assertEquals(1, capturedEvent.getValue().getFirstIndex());
}
+ @Test
public void testItemRemovedEvent() {
IndexedContainer container = new IndexedContainer();
Object itemId = container.addItem();
EasyMock.verify(removeListener);
}
+ @Test
public void testItemRemovedEvent_RemovedItem() {
IndexedContainer container = new IndexedContainer();
Object itemId = container.addItem();
assertEquals(itemId, capturedEvent.getValue().getFirstItemId());
}
+ @Test
public void testItemRemovedEvent_indexOfRemovedItem() {
IndexedContainer container = new IndexedContainer();
container.addItem();
assertEquals(1, capturedEvent.getValue().getFirstIndex());
}
+ @Test
public void testItemRemovedEvent_amountOfRemovedItems() {
IndexedContainer container = new IndexedContainer();
container.addItem();
}
// Ticket 8028
+ @Test(expected = IndexOutOfBoundsException.class)
public void testGetItemIdsRangeIndexOutOfBounds() {
IndexedContainer ic = new IndexedContainer();
- try {
- ic.getItemIds(-1, 10);
- fail("Container returned items starting from index -1, something very wrong here!");
- } catch (IndexOutOfBoundsException e) {
- // This is expected...
- } catch (Exception e) {
- // Should not happen!
- fail("Container threw unspecified exception when fetching a range of items and the range started from -1");
- }
-
+ ic.getItemIds(-1, 10);
}
// Ticket 8028
+ @Test(expected = IndexOutOfBoundsException.class)
public void testGetItemIdsRangeIndexOutOfBounds2() {
IndexedContainer ic = new IndexedContainer();
ic.addItem(new Object());
- try {
- ic.getItemIds(2, 1);
- fail("Container returned items starting from index -1, something very wrong here!");
- } catch (IndexOutOfBoundsException e) {
- // This is expected...
- } catch (Exception e) {
- // Should not happen!
- fail("Container threw unspecified exception when fetching a out of bounds range of items");
- }
-
+ ic.getItemIds(2, 1);
}
// Ticket 8028
+ @Test
public void testGetItemIdsRangeZeroRange() {
IndexedContainer ic = new IndexedContainer();
ic.addItem(new Object());
- try {
- List<Object> itemIds = ic.getItemIds(1, 0);
-
- assertTrue(
- "Container returned actual values when asking for 0 items...",
- itemIds.isEmpty());
- } catch (Exception e) {
- // Should not happen!
- fail("Container threw unspecified exception when fetching 0 items...");
- }
+ List<Object> itemIds = ic.getItemIds(1, 0);
+ assertTrue(
+ "Container returned actual values when asking for 0 items...",
+ itemIds.isEmpty());
}
// Ticket 8028
+ @Test(expected = IllegalArgumentException.class)
public void testGetItemIdsRangeNegativeRange() {
IndexedContainer ic = new IndexedContainer();
ic.addItem(new Object());
- try {
- List<Object> itemIds = ic.getItemIds(1, -1);
-
- assertTrue(
- "Container returned actual values when asking for -1 items...",
- itemIds.isEmpty());
- } catch (IllegalArgumentException e) {
- // this is expected
-
- } catch (Exception e) {
- // Should not happen!
- fail("Container threw unspecified exception when fetching -1 items...");
- }
+ List<Object> itemIds = ic.getItemIds(1, -1);
+ assertTrue(
+ "Container returned actual values when asking for -1 items...",
+ itemIds.isEmpty());
}
// Ticket 8028
+ @Test
public void testGetItemIdsRangeIndexOutOfBoundsDueToSizeChange() {
IndexedContainer ic = new IndexedContainer();
ic.addItem(new Object());
}
// Ticket 8028
+ @Test
public void testGetItemIdsRangeBaseCase() {
IndexedContainer ic = new IndexedContainer();
String object1 = new String("Obj1");
ic.addItem(object4);
ic.addItem(object5);
- try {
- List<Object> itemIds = ic.getItemIds(1, 2);
+ List<Object> itemIds = ic.getItemIds(1, 2);
- assertTrue(itemIds.contains(object2));
- assertTrue(itemIds.contains(object3));
- assertEquals(2, itemIds.size());
-
- } catch (Exception e) {
- // Should not happen!
- fail("Container threw exception when fetching a range of items ");
- }
+ assertTrue(itemIds.contains(object2));
+ assertTrue(itemIds.contains(object3));
+ assertEquals(2, itemIds.size());
}
// test getting non-existing property (#10445)
+ @Test
public void testNonExistingProperty() {
IndexedContainer ic = new IndexedContainer();
String object1 = new String("Obj1");
}
// test getting null property id (#10445)
+ @Test
public void testNullPropertyId() {
IndexedContainer ic = new IndexedContainer();
String object1 = new String("Obj1");
ic.addItem(object1);
assertNull(ic.getContainerProperty(object1, null));
}
-
}
package com.vaadin.data.util;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import junit.framework.TestCase;
-
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class NestedMethodPropertyTest extends TestCase {
+public class NestedMethodPropertyTest {
public static class Address implements Serializable {
private String street;
private Person joonas;
private Team vaadin;
- @Override
+ @Before
public void setUp() {
oldMill = new Address("Ruukinkatu 2-4", 20540);
joonas = new Person("Joonas", oldMill);
vaadin = new Team("Vaadin", joonas);
}
- @Override
- public void tearDown() {
- vaadin = null;
- joonas = null;
- oldMill = null;
- }
-
+ @Test
public void testSingleLevelNestedSimpleProperty() {
NestedMethodProperty<String> nameProperty = new NestedMethodProperty<String>(
vaadin, "name");
Assert.assertEquals("Vaadin", nameProperty.getValue());
}
+ @Test
public void testSingleLevelNestedObjectProperty() {
NestedMethodProperty<Person> managerProperty = new NestedMethodProperty<Person>(
vaadin, "manager");
Assert.assertEquals(joonas, managerProperty.getValue());
}
+ @Test
public void testMultiLevelNestedProperty() {
NestedMethodProperty<String> managerNameProperty = new NestedMethodProperty<String>(
vaadin, "manager.name");
Assert.assertEquals(Boolean.TRUE, booleanProperty.getValue());
}
+ @Test
public void testEmptyPropertyName() {
try {
new NestedMethodProperty<Object>(vaadin, "");
}
}
+ @Test
public void testInvalidPropertyName() {
try {
new NestedMethodProperty<Object>(vaadin, ".");
}
}
+ @Test
public void testInvalidNestedPropertyName() {
try {
new NestedMethodProperty<Object>(vaadin, "member");
}
}
+ @Test
public void testNullNestedProperty() {
NestedMethodProperty<String> managerNameProperty = new NestedMethodProperty<String>(
vaadin, "manager.name");
}
+ @Test
public void testMultiLevelNestedPropertySetValue() {
NestedMethodProperty<String> managerNameProperty = new NestedMethodProperty<String>(
vaadin, "manager.name");
Assert.assertEquals("Other street", streetProperty.getValue());
}
+ @Test
public void testSerialization() throws IOException, ClassNotFoundException {
NestedMethodProperty<String> streetProperty = new NestedMethodProperty<String>(
vaadin, "manager.address.street");
Assert.assertEquals("Ruukinkatu 2-4", property2.getValue());
}
+ @Test
public void testSerializationWithIntermediateNull() throws IOException,
ClassNotFoundException {
vaadin.setManager(null);
Assert.assertNull(property2.getValue());
}
+ @Test
public void testIsReadOnly() {
NestedMethodProperty<String> streetProperty = new NestedMethodProperty<String>(
vaadin, "manager.address.street");
package com.vaadin.data.util;
-import junit.framework.TestCase;
-
import org.junit.Assert;
+import org.junit.Test;
-public class ObjectPropertyTest extends TestCase {
+public class ObjectPropertyTest {
public static class TestSuperClass {
private String name;
private TestSuperClass super1 = new TestSuperClass("super1");
private TestSubClass sub1 = new TestSubClass("sub1");
+ @Test
public void testSimple() {
ObjectProperty<TestSuperClass> prop1 = new ObjectProperty<TestSuperClass>(
super1, TestSuperClass.class);
Assert.assertEquals("Subclass: sub1", prop2.getValue().getName());
}
+ @Test
public void testSetValueObjectSuper() {
ObjectProperty<TestSuperClass> prop = new ObjectProperty<TestSuperClass>(
super1, TestSuperClass.class);
Assert.assertEquals("super2", prop.getValue().getName());
}
+ @Test
public void testSetValueObjectSub() {
ObjectProperty<TestSubClass> prop = new ObjectProperty<TestSubClass>(
sub1, TestSubClass.class);
Assert.assertEquals("Subclass: sub2", prop.getValue().getName());
}
+ @Test
public void testSetValueStringSuper() {
ObjectProperty<TestSuperClass> prop = new ObjectProperty<TestSuperClass>(
super1, TestSuperClass.class);
Assert.assertEquals("super2", prop.getValue().getName());
}
+ @Test
public void testSetValueStringSub() {
ObjectProperty<TestSubClass> prop = new ObjectProperty<TestSubClass>(
sub1, TestSubClass.class);
Assert.assertEquals("Subclass: sub2", prop.getValue().getName());
}
+ @Test
public void testMixedGenerics() {
ObjectProperty<TestSuperClass> prop = new ObjectProperty<TestSuperClass>(
sub1);
import java.util.SortedSet;
import java.util.TreeSet;
-import junit.framework.TestCase;
-
import org.junit.Assert;
+import org.junit.Test;
-public class PerformanceTestIndexedContainerTest extends TestCase {
+public class PerformanceTestIndexedContainerTest {
private static final int REPEATS = 10;
private final static int ITEMS = 50000;
private static final long ADD_ITEM_AFTER_LAST_FAIL_THRESHOLD = 5000;
private static final long ADD_ITEMS_CONSTRUCTOR_FAIL_THRESHOLD = 200;
+ @Test
public void testAddItemPerformance() {
Collection<Long> times = new ArrayList<Long>();
for (int j = 0; j < REPEATS; ++j) {
ADD_ITEM_FAIL_THRESHOLD);
}
+ @Test
public void testAddItemAtPerformance() {
Collection<Long> times = new ArrayList<Long>();
for (int j = 0; j < REPEATS; ++j) {
ADD_ITEM_AT_FAIL_THRESHOLD);
}
+ @Test
public void testAddItemAfterPerformance() {
Object initialId = "Item0";
Collection<Long> times = new ArrayList<Long>();
ADD_ITEM_AFTER_FAIL_THRESHOLD);
}
+ @Test
public void testAddItemAfterLastPerformance() {
// TODO running with less items because slow otherwise
Collection<Long> times = new ArrayList<Long>();
ADD_ITEM_AFTER_LAST_FAIL_THRESHOLD);
}
+ @Test
public void testAddItemsConstructorPerformance() {
Collection<Object> items = new ArrayList<Object>(50000);
for (int i = 0; i < ITEMS; ++i) {
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import junit.framework.TestCase;
-
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.Property;
import com.vaadin.data.util.NestedMethodPropertyTest.Person;
-public class PropertyDescriptorTest extends TestCase {
+public class PropertyDescriptorTest {
+
+ @Test
public void testMethodPropertyDescriptorSerialization() throws Exception {
PropertyDescriptor[] pds = Introspector.getBeanInfo(Person.class)
.getPropertyDescriptors();
Assert.assertEquals("John", property.getValue());
}
+ @Test
public void testSimpleNestedPropertyDescriptorSerialization()
throws Exception {
NestedPropertyDescriptor<Person> pd = new NestedPropertyDescriptor<Person>(
Assert.assertEquals("John", property.getValue());
}
+ @Test
public void testNestedPropertyDescriptorSerialization() throws Exception {
NestedPropertyDescriptor<Person> pd = new NestedPropertyDescriptor<Person>(
"address.street", Person.class);
Assert.assertNull(property.getValue());
}
+ @Test
public void testMethodPropertyDescriptorWithPrimitivePropertyType()
throws Exception {
MethodPropertyDescriptor<Person> pd = new MethodPropertyDescriptor<Person>(
import java.util.Iterator;
-import junit.framework.TestCase;
-
import org.easymock.EasyMock;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.data.Item.PropertySetChangeEvent;
import com.vaadin.data.Item.PropertySetChangeListener;
-public class PropertySetItemTest extends TestCase {
+public class PropertySetItemTest {
private static final String ID1 = "id1";
private static final String ID2 = "id2";
private PropertySetChangeListener propertySetListenerMock;
private PropertySetChangeListener propertySetListenerMock2;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() {
prop1 = new ObjectProperty<String>(VALUE1, String.class);
prop2 = new ObjectProperty<String>(VALUE2, String.class);
prop3 = new ObjectProperty<String>(VALUE3, String.class);
.createMock(PropertySetChangeListener.class);
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() {
prop1 = null;
prop2 = null;
prop3 = null;
return new PropertysetItem();
}
+ @Test
public void testEmptyItem() {
PropertysetItem item = createPropertySetItem();
Assert.assertNotNull(item.getItemPropertyIds());
Assert.assertEquals(0, item.getItemPropertyIds().size());
}
+ @Test
public void testGetProperty() {
PropertysetItem item = createPropertySetItem();
Assert.assertNull(item.getItemProperty(ID2));
}
+ @Test
public void testAddSingleProperty() {
PropertysetItem item = createPropertySetItem();
Assert.assertEquals(prop1, item.getItemProperty(ID1));
}
+ @Test
public void testAddMultipleProperties() {
PropertysetItem item = createPropertySetItem();
Assert.assertEquals(3, item.getItemPropertyIds().size());
}
+ @Test
public void testAddedPropertyOrder() {
PropertysetItem item = createPropertySetItem();
item.addItemProperty(ID1, prop1);
Assert.assertEquals(ID3, it.next());
}
+ @Test
public void testAddPropertyTwice() {
PropertysetItem item = createPropertySetItem();
Assert.assertTrue(item.addItemProperty(ID1, prop1));
Assert.assertEquals(prop1, item.getItemProperty(ID1));
}
+ @Test
public void testCannotChangeProperty() {
PropertysetItem item = createPropertySetItem();
Assert.assertTrue(item.addItemProperty(ID1, prop1));
Assert.assertEquals(prop1, item.getItemProperty(ID1));
}
+ @Test
public void testRemoveProperty() {
PropertysetItem item = createPropertySetItem();
item.addItemProperty(ID1, prop1);
Assert.assertNull(item.getItemProperty(ID1));
}
+ @Test
public void testRemovePropertyOrder() {
PropertysetItem item = createPropertySetItem();
item.addItemProperty(ID1, prop1);
Assert.assertEquals(ID3, it.next());
}
+ @Test
public void testRemoveNonExistentListener() {
PropertysetItem item = createPropertySetItem();
item.removeListener(propertySetListenerMock);
}
+ @Test
public void testRemoveListenerTwice() {
PropertysetItem item = createPropertySetItem();
item.addListener(propertySetListenerMock);
item.removeListener(propertySetListenerMock);
}
+ @Test
public void testAddPropertyNotification() {
// exactly one notification each time
PropertysetItem item = createPropertySetItem();
EasyMock.verify(propertySetListenerMock);
}
+ @Test
public void testRemovePropertyNotification() {
// exactly one notification each time
PropertysetItem item = createPropertySetItem();
EasyMock.verify(propertySetListenerMock);
}
+ @Test
public void testItemEqualsNull() {
PropertysetItem item = createPropertySetItem();
Assert.assertFalse(item.equals(null));
}
+ @Test
public void testEmptyItemEquals() {
PropertysetItem item1 = createPropertySetItem();
PropertysetItem item2 = createPropertySetItem();
Assert.assertTrue(item1.equals(item2));
}
+ @Test
public void testItemEqualsSingleProperty() {
PropertysetItem item1 = createPropertySetItem();
PropertysetItem item2 = createPropertySetItem();
Assert.assertFalse(item2.equals(item1));
}
+ @Test
public void testItemEqualsMultipleProperties() {
PropertysetItem item1 = createPropertySetItem();
item1.addItemProperty(ID1, prop1);
Assert.assertTrue(item2.equals(item3));
}
+ @Test
public void testItemEqualsPropertyOrder() {
PropertysetItem item1 = createPropertySetItem();
item1.addItemProperty(ID1, prop1);
Assert.assertFalse(item1.equals(item2));
}
+ @Test
public void testEqualsSingleListener() {
PropertysetItem item1 = createPropertySetItem();
PropertysetItem item2 = createPropertySetItem();
Assert.assertTrue(item2.equals(item1));
}
+ @Test
public void testEqualsMultipleListeners() {
PropertysetItem item1 = createPropertySetItem();
PropertysetItem item2 = createPropertySetItem();
Assert.assertTrue(item2.equals(item1));
}
+ @Test
public void testEqualsAddRemoveListener() {
PropertysetItem item1 = createPropertySetItem();
PropertysetItem item2 = createPropertySetItem();
Assert.assertTrue(item2.equals(item1));
}
+ @Test
public void testItemHashCodeEmpty() {
PropertysetItem item1 = createPropertySetItem();
PropertysetItem item2 = createPropertySetItem();
Assert.assertEquals(item1.hashCode(), item2.hashCode());
}
+ @Test
public void testItemHashCodeAddProperties() {
PropertysetItem item1 = createPropertySetItem();
PropertysetItem item2 = createPropertySetItem();
Assert.assertEquals(item1.hashCode(), item2.hashCode());
}
+ @Test
public void testItemHashCodeAddListeners() {
PropertysetItem item1 = createPropertySetItem();
PropertysetItem item2 = createPropertySetItem();
Assert.assertEquals(item1.hashCode(), item2.hashCode());
}
+ @Test
public void testItemHashCodeAddRemoveProperty() {
PropertysetItem item1 = createPropertySetItem();
PropertysetItem item2 = createPropertySetItem();
Assert.assertEquals(item1.hashCode(), item2.hashCode());
}
+ @Test
public void testItemHashCodeAddRemoveListener() {
PropertysetItem item1 = createPropertySetItem();
PropertysetItem item2 = createPropertySetItem();
Assert.assertEquals(item1.hashCode(), item2.hashCode());
}
+ @Test
public void testToString() {
// toString() behavior is specified in the class javadoc
PropertysetItem item = createPropertySetItem();
package com.vaadin.data.util.filter;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.Container.Filter;
import com.vaadin.data.Item;
protected Item item1 = new BeanItem<Integer>(1);
protected Item item2 = new BeanItem<Integer>(2);
+ @Test
public void testNoFilterAnd() {
Filter filter = new And();
Assert.assertTrue(filter.passesFilter(null, item1));
}
+ @Test
public void testSingleFilterAnd() {
Filter filter = new And(new SameItemFilter(item1));
Assert.assertFalse(filter.passesFilter(null, item2));
}
+ @Test
public void testTwoFilterAnd() {
Filter filter1 = new And(new SameItemFilter(item1), new SameItemFilter(
item1));
Assert.assertFalse(filter2.passesFilter(null, item2));
}
+ @Test
public void testThreeFilterAnd() {
Filter filter1 = new And(new SameItemFilter(item1), new SameItemFilter(
item1), new SameItemFilter(item1));
Assert.assertFalse(filter2.passesFilter(null, item2));
}
+ @Test
public void testNoFilterOr() {
Filter filter = new Or();
Assert.assertFalse(filter.passesFilter(null, item1));
}
+ @Test
public void testSingleFilterOr() {
Filter filter = new Or(new SameItemFilter(item1));
Assert.assertFalse(filter.passesFilter(null, item2));
}
+ @Test
public void testTwoFilterOr() {
Filter filter1 = new Or(new SameItemFilter(item1), new SameItemFilter(
item1));
Assert.assertTrue(filter2.passesFilter(null, item2));
}
+ @Test
public void testThreeFilterOr() {
Filter filter1 = new Or(new SameItemFilter(item1), new SameItemFilter(
item1), new SameItemFilter(item1));
Assert.assertTrue(filter2.passesFilter(null, item2));
}
+ @Test
public void testAndEqualsHashCode() {
Filter filter0 = new And();
Filter filter0b = new And();
Assert.assertEquals(filter2b.hashCode(), filter2b2.hashCode());
}
+ @Test
public void testOrEqualsHashCode() {
Filter filter0 = new Or();
Filter filter0b = new Or();
Assert.assertEquals(filter2b.hashCode(), filter2b2.hashCode());
}
+ @Test
public void testAndAppliesToProperty() {
Filter filter0 = new And();
Filter filter1a = new And(new SameItemFilter(item1, "a"));
Assert.assertFalse(filter3abc.appliesToProperty("d"));
}
+ @Test
public void testOrAppliesToProperty() {
Filter filter0 = new Or();
Filter filter1a = new Or(new SameItemFilter(item1, "a"));
import java.util.Date;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.Container.Filter;
import com.vaadin.data.Item;
itemB = null;
}
+ @Test
public void testCompareString() {
Assert.assertFalse(equalB.passesFilter(null, itemEmpty));
Assert.assertFalse(equalB.passesFilter(null, itemA));
Assert.assertFalse(lessEqualB.passesFilter(null, itemC));
}
+ @Test
public void testCompareWithNull() {
// null comparisons: null is less than any other value
Assert.assertFalse(equalB.passesFilter(null, itemNull));
Assert.assertTrue(lessEqualNull.passesFilter(null, itemA));
}
+ @Test
public void testCompareInteger() {
int negative = -1;
int zero = 0;
Assert.assertFalse(isNonPositive.passesFilter(null, itemPositive));
}
+ @Test
public void testCompareBigDecimal() {
BigDecimal negative = new BigDecimal(-1);
BigDecimal zero = new BigDecimal(0);
}
+ @Test
public void testCompareDate() {
Date now = new Date();
// new Date() is only accurate to the millisecond, so repeating it gives
Assert.assertFalse(beforeOrNow.passesFilter(null, itemLater));
}
+ @Test
public void testCompareAppliesToProperty() {
Filter filterA = new Equal("a", 1);
Filter filterB = new Equal("b", 1);
Assert.assertTrue(filterB.appliesToProperty("b"));
}
+ @Test
public void testCompareEqualsHashCode() {
// most checks with Equal filter, then only some with others
Filter equalNull2 = new Equal(PROPERTY1, null);
package com.vaadin.data.util.filter;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.Container.Filter;
import com.vaadin.data.Item;
public class IsNullFilterTest extends AbstractFilterTestBase<IsNull> {
+ @Test
public void testIsNull() {
Item item1 = new PropertysetItem();
item1.addItemProperty("a", new ObjectProperty<String>(null,
Assert.assertTrue(filter2.passesFilter(null, item2));
}
+ @Test
public void testIsNullAppliesToProperty() {
Filter filterA = new IsNull("a");
Filter filterB = new IsNull("b");
Assert.assertTrue(filterB.appliesToProperty("b"));
}
+ @Test
public void testIsNullEqualsHashCode() {
Filter filter1 = new IsNull("a");
Filter filter1b = new IsNull("a");
package com.vaadin.data.util.filter;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.Item;
import com.vaadin.data.util.ObjectProperty;
protected Item item2 = new PropertysetItem();
protected Item item3 = new PropertysetItem();
+ @Test
public void testLikeWithNulls() {
Like filter = new Like("value", "a");
package com.vaadin.data.util.filter;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.Container.Filter;
import com.vaadin.data.Item;
protected Item item1 = new BeanItem<Integer>(1);
protected Item item2 = new BeanItem<Integer>(2);
+ @Test
public void testNot() {
Filter origFilter = new SameItemFilter(item1);
Filter filter = new Not(origFilter);
Assert.assertTrue(filter.passesFilter(null, item2));
}
+ @Test
public void testANotAppliesToProperty() {
Filter filterA = new Not(new SameItemFilter(item1, "a"));
Filter filterB = new Not(new SameItemFilter(item1, "b"));
Assert.assertTrue(filterB.appliesToProperty("b"));
}
+ @Test
public void testNotEqualsHashCode() {
Filter origFilter = new SameItemFilter(item1);
Filter filter1 = new Not(origFilter);
package com.vaadin.data.util.filter;
import org.junit.Assert;
+import org.junit.Test;
public class SimpleStringFilterTest extends
AbstractFilterTestBase<SimpleStringFilter> {
.passesFilter(null, getTestItem());
}
+ @Test
public void testStartsWithCaseSensitive() {
Assert.assertTrue(passes(PROPERTY1, "ab", false, true));
Assert.assertTrue(passes(PROPERTY1, "", false, true));
Assert.assertFalse(passes(PROPERTY1, "AB", false, true));
}
+ @Test
public void testStartsWithCaseInsensitive() {
Assert.assertTrue(passes(PROPERTY1, "AB", true, true));
Assert.assertTrue(passes(PROPERTY2, "te", true, true));
Assert.assertFalse(passes(PROPERTY2, "AB", true, true));
}
+ @Test
public void testContainsCaseSensitive() {
Assert.assertTrue(passes(PROPERTY1, "ab", false, false));
Assert.assertTrue(passes(PROPERTY1, "abcde", false, false));
Assert.assertFalse(passes(PROPERTY1, "es", false, false));
}
+ @Test
public void testContainsCaseInsensitive() {
Assert.assertTrue(passes(PROPERTY1, "AB", true, false));
Assert.assertTrue(passes(PROPERTY1, "aBcDe", true, false));
Assert.assertFalse(passes(PROPERTY2, "ab", true, false));
}
+ @Test
public void testAppliesToProperty() {
SimpleStringFilter filter = f(PROPERTY1, "ab", false, true);
Assert.assertTrue(filter.appliesToProperty(PROPERTY1));
Assert.assertFalse(filter.appliesToProperty("other"));
}
+ @Test
public void testEqualsHashCode() {
SimpleStringFilter filter = f(PROPERTY1, "ab", false, true);
Assert.assertEquals(f4.hashCode(), f4b.hashCode());
}
+ @Test
public void testNonExistentProperty() {
Assert.assertFalse(passes("other1", "ab", false, true));
}
+ @Test
public void testNullValueForProperty() {
TestItem<String, String> item = createTestItem();
item.addItemProperty("other1", new NullProperty());
FreeformQueryTest.class, RowIdTest.class, SQLContainerTest.class,
SQLContainerTableQueryTest.class, ColumnPropertyTest.class,
TableQueryTest.class, SQLGeneratorsTest.class, UtilTest.class,
- TicketTests.class, BetweenTest.class, ReadOnlyRowIdTest.class })
+ TicketTest.class, BetweenTest.class, ReadOnlyRowIdTest.class })
public class AllTests {
}
--- /dev/null
+package com.vaadin.data.util.sqlcontainer;
+
+import java.math.BigDecimal;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.Container.Filter;
+import com.vaadin.data.Item;
+import com.vaadin.data.util.filter.Compare.Equal;
+import com.vaadin.data.util.sqlcontainer.SQLTestsConstants.DB;
+import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool;
+import com.vaadin.data.util.sqlcontainer.query.FreeformQuery;
+import com.vaadin.data.util.sqlcontainer.query.FreeformStatementDelegate;
+import com.vaadin.data.util.sqlcontainer.query.TableQuery;
+import com.vaadin.data.util.sqlcontainer.query.ValidatingSimpleJDBCConnectionPool;
+import com.vaadin.data.util.sqlcontainer.query.generator.StatementHelper;
+import com.vaadin.data.util.sqlcontainer.query.generator.filter.QueryBuilder;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.Window;
+
+public class TicketTest {
+
+ private JDBCConnectionPool connectionPool;
+
+ @Before
+ public void setUp() throws SQLException {
+ connectionPool = new ValidatingSimpleJDBCConnectionPool(
+ SQLTestsConstants.dbDriver, SQLTestsConstants.dbURL,
+ SQLTestsConstants.dbUser, SQLTestsConstants.dbPwd, 2, 2);
+ DataGenerator.addPeopleToDatabase(connectionPool);
+ }
+
+ @Test
+ public void ticket5867_throwsIllegalState_transactionAlreadyActive()
+ throws SQLException {
+ SQLContainer container = new SQLContainer(new FreeformQuery(
+ "SELECT * FROM people", Arrays.asList("ID"), connectionPool));
+ Table table = new Table();
+ Window w = new Window();
+ w.setContent(table);
+ table.setContainerDataSource(container);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void ticket6136_freeform_ageIs18() throws SQLException {
+ FreeformQuery query = new FreeformQuery("SELECT * FROM people",
+ Arrays.asList("ID"), connectionPool);
+ FreeformStatementDelegate delegate = EasyMock
+ .createMock(FreeformStatementDelegate.class);
+ final ArrayList<Filter> filters = new ArrayList<Filter>();
+ delegate.setFilters(null);
+ EasyMock.expectLastCall().anyTimes();
+ delegate.setOrderBy(EasyMock.isA(List.class));
+ EasyMock.expectLastCall().anyTimes();
+ delegate.setOrderBy(null);
+ EasyMock.expectLastCall().anyTimes();
+ delegate.setFilters(EasyMock.isA(List.class));
+ EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
+ public Object answer() throws Throwable {
+ List<Filter> orders = (List<Filter>) EasyMock
+ .getCurrentArguments()[0];
+ filters.clear();
+ filters.addAll(orders);
+ return null;
+ }
+ }).anyTimes();
+ EasyMock.expect(
+ delegate.getQueryStatement(EasyMock.anyInt(), EasyMock.anyInt()))
+ .andAnswer(new IAnswer<StatementHelper>() {
+ @Override
+ public StatementHelper answer() throws Throwable {
+ Object[] args = EasyMock.getCurrentArguments();
+ int offset = (Integer) (args[0]);
+ int limit = (Integer) (args[1]);
+ return FreeformQueryUtil.getQueryWithFilters(filters,
+ offset, limit);
+ }
+ }).anyTimes();
+ EasyMock.expect(delegate.getCountStatement())
+ .andAnswer(new IAnswer<StatementHelper>() {
+ @Override
+ public StatementHelper answer() throws Throwable {
+ StatementHelper sh = new StatementHelper();
+ StringBuffer query = new StringBuffer(
+ "SELECT COUNT(*) FROM people");
+ if (!filters.isEmpty()) {
+ query.append(QueryBuilder.getWhereStringForFilters(
+ filters, sh));
+ }
+ sh.setQueryString(query.toString());
+ return sh;
+ }
+ }).anyTimes();
+
+ EasyMock.replay(delegate);
+ query.setDelegate(delegate);
+ SQLContainer container = new SQLContainer(query);
+ // Ville, Kalle, Pelle, Börje
+ Assert.assertEquals(4, container.size());
+ Assert.assertEquals("Börje",
+ container.getContainerProperty(container.lastItemId(), "NAME")
+ .getValue());
+
+ container.addContainerFilter(new Equal("AGE", 18));
+ // Pelle
+ Assert.assertEquals(1, container.size());
+ Assert.assertEquals("Pelle",
+ container.getContainerProperty(container.firstItemId(), "NAME")
+ .getValue());
+ if (SQLTestsConstants.db == DB.ORACLE) {
+ Assert.assertEquals(new BigDecimal(18), container
+ .getContainerProperty(container.firstItemId(), "AGE")
+ .getValue());
+ } else {
+ Assert.assertEquals(
+ 18,
+ container.getContainerProperty(container.firstItemId(),
+ "AGE").getValue());
+ }
+
+ EasyMock.verify(delegate);
+ }
+
+ @Test
+ public void ticket6136_table_ageIs18() throws SQLException {
+ TableQuery query = new TableQuery("people", connectionPool,
+ SQLTestsConstants.sqlGen);
+ SQLContainer container = new SQLContainer(query);
+ // Ville, Kalle, Pelle, Börje
+ Assert.assertEquals(4, container.size());
+
+ container.addContainerFilter(new Equal("AGE", 18));
+
+ // Pelle
+ Assert.assertEquals(1, container.size());
+ Assert.assertEquals("Pelle",
+ container.getContainerProperty(container.firstItemId(), "NAME")
+ .getValue());
+ if (SQLTestsConstants.db == DB.ORACLE) {
+ Assert.assertEquals(new BigDecimal(18), container
+ .getContainerProperty(container.firstItemId(), "AGE")
+ .getValue());
+ } else {
+ Assert.assertEquals(
+ 18,
+ container.getContainerProperty(container.firstItemId(),
+ "AGE").getValue());
+ }
+ }
+
+ @Test
+ public void ticket7434_getItem_Modified_Changed_Unchanged()
+ throws SQLException {
+ SQLContainer container = new SQLContainer(new TableQuery("people",
+ connectionPool, SQLTestsConstants.sqlGen));
+
+ Object id = container.firstItemId();
+ Item item = container.getItem(id);
+ String name = (String) item.getItemProperty("NAME").getValue();
+
+ // set a different name
+ item.getItemProperty("NAME").setValue("otherName");
+ Assert.assertEquals("otherName", item.getItemProperty("NAME")
+ .getValue());
+
+ // access the item and reset the name to its old value
+ Item item2 = container.getItem(id);
+ item2.getItemProperty("NAME").setValue(name);
+ Assert.assertEquals(name, item2.getItemProperty("NAME").getValue());
+
+ Item item3 = container.getItem(id);
+ String name3 = (String) item3.getItemProperty("NAME").getValue();
+
+ Assert.assertEquals(name, name3);
+ }
+
+ @Test
+ public void ticket10032_empty_set_metadata_correctly_handled()
+ throws SQLException {
+ // If problem exists will break when method getPropertyIds()
+ // is called in constructor SQLContainer(QueryDelegate delegate).
+ SQLContainer container = new SQLContainer(new FreeformQuery(
+ "SELECT * FROM people WHERE name='does_not_exist'",
+ Arrays.asList("ID"), connectionPool));
+ Assert.assertTrue("Got items while expected empty set",
+ container.size() == 0);
+ }
+}
+++ /dev/null
-package com.vaadin.data.util.sqlcontainer;
-
-import java.math.BigDecimal;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.vaadin.data.Container.Filter;
-import com.vaadin.data.Item;
-import com.vaadin.data.util.filter.Compare.Equal;
-import com.vaadin.data.util.sqlcontainer.SQLTestsConstants.DB;
-import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool;
-import com.vaadin.data.util.sqlcontainer.query.FreeformQuery;
-import com.vaadin.data.util.sqlcontainer.query.FreeformStatementDelegate;
-import com.vaadin.data.util.sqlcontainer.query.TableQuery;
-import com.vaadin.data.util.sqlcontainer.query.ValidatingSimpleJDBCConnectionPool;
-import com.vaadin.data.util.sqlcontainer.query.generator.StatementHelper;
-import com.vaadin.data.util.sqlcontainer.query.generator.filter.QueryBuilder;
-import com.vaadin.ui.Table;
-import com.vaadin.ui.Window;
-
-public class TicketTests {
-
- private JDBCConnectionPool connectionPool;
-
- @Before
- public void setUp() throws SQLException {
- connectionPool = new ValidatingSimpleJDBCConnectionPool(
- SQLTestsConstants.dbDriver, SQLTestsConstants.dbURL,
- SQLTestsConstants.dbUser, SQLTestsConstants.dbPwd, 2, 2);
- DataGenerator.addPeopleToDatabase(connectionPool);
- }
-
- @Test
- public void ticket5867_throwsIllegalState_transactionAlreadyActive()
- throws SQLException {
- SQLContainer container = new SQLContainer(new FreeformQuery(
- "SELECT * FROM people", Arrays.asList("ID"), connectionPool));
- Table table = new Table();
- Window w = new Window();
- w.setContent(table);
- table.setContainerDataSource(container);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void ticket6136_freeform_ageIs18() throws SQLException {
- FreeformQuery query = new FreeformQuery("SELECT * FROM people",
- Arrays.asList("ID"), connectionPool);
- FreeformStatementDelegate delegate = EasyMock
- .createMock(FreeformStatementDelegate.class);
- final ArrayList<Filter> filters = new ArrayList<Filter>();
- delegate.setFilters(null);
- EasyMock.expectLastCall().anyTimes();
- delegate.setOrderBy(EasyMock.isA(List.class));
- EasyMock.expectLastCall().anyTimes();
- delegate.setOrderBy(null);
- EasyMock.expectLastCall().anyTimes();
- delegate.setFilters(EasyMock.isA(List.class));
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
- @Override
- public Object answer() throws Throwable {
- List<Filter> orders = (List<Filter>) EasyMock
- .getCurrentArguments()[0];
- filters.clear();
- filters.addAll(orders);
- return null;
- }
- }).anyTimes();
- EasyMock.expect(
- delegate.getQueryStatement(EasyMock.anyInt(), EasyMock.anyInt()))
- .andAnswer(new IAnswer<StatementHelper>() {
- @Override
- public StatementHelper answer() throws Throwable {
- Object[] args = EasyMock.getCurrentArguments();
- int offset = (Integer) (args[0]);
- int limit = (Integer) (args[1]);
- return FreeformQueryUtil.getQueryWithFilters(filters,
- offset, limit);
- }
- }).anyTimes();
- EasyMock.expect(delegate.getCountStatement())
- .andAnswer(new IAnswer<StatementHelper>() {
- @Override
- public StatementHelper answer() throws Throwable {
- StatementHelper sh = new StatementHelper();
- StringBuffer query = new StringBuffer(
- "SELECT COUNT(*) FROM people");
- if (!filters.isEmpty()) {
- query.append(QueryBuilder.getWhereStringForFilters(
- filters, sh));
- }
- sh.setQueryString(query.toString());
- return sh;
- }
- }).anyTimes();
-
- EasyMock.replay(delegate);
- query.setDelegate(delegate);
- SQLContainer container = new SQLContainer(query);
- // Ville, Kalle, Pelle, Börje
- Assert.assertEquals(4, container.size());
- Assert.assertEquals("Börje",
- container.getContainerProperty(container.lastItemId(), "NAME")
- .getValue());
-
- container.addContainerFilter(new Equal("AGE", 18));
- // Pelle
- Assert.assertEquals(1, container.size());
- Assert.assertEquals("Pelle",
- container.getContainerProperty(container.firstItemId(), "NAME")
- .getValue());
- if (SQLTestsConstants.db == DB.ORACLE) {
- Assert.assertEquals(new BigDecimal(18), container
- .getContainerProperty(container.firstItemId(), "AGE")
- .getValue());
- } else {
- Assert.assertEquals(
- 18,
- container.getContainerProperty(container.firstItemId(),
- "AGE").getValue());
- }
-
- EasyMock.verify(delegate);
- }
-
- @Test
- public void ticket6136_table_ageIs18() throws SQLException {
- TableQuery query = new TableQuery("people", connectionPool,
- SQLTestsConstants.sqlGen);
- SQLContainer container = new SQLContainer(query);
- // Ville, Kalle, Pelle, Börje
- Assert.assertEquals(4, container.size());
-
- container.addContainerFilter(new Equal("AGE", 18));
-
- // Pelle
- Assert.assertEquals(1, container.size());
- Assert.assertEquals("Pelle",
- container.getContainerProperty(container.firstItemId(), "NAME")
- .getValue());
- if (SQLTestsConstants.db == DB.ORACLE) {
- Assert.assertEquals(new BigDecimal(18), container
- .getContainerProperty(container.firstItemId(), "AGE")
- .getValue());
- } else {
- Assert.assertEquals(
- 18,
- container.getContainerProperty(container.firstItemId(),
- "AGE").getValue());
- }
- }
-
- @Test
- public void ticket7434_getItem_Modified_Changed_Unchanged()
- throws SQLException {
- SQLContainer container = new SQLContainer(new TableQuery("people",
- connectionPool, SQLTestsConstants.sqlGen));
-
- Object id = container.firstItemId();
- Item item = container.getItem(id);
- String name = (String) item.getItemProperty("NAME").getValue();
-
- // set a different name
- item.getItemProperty("NAME").setValue("otherName");
- Assert.assertEquals("otherName", item.getItemProperty("NAME")
- .getValue());
-
- // access the item and reset the name to its old value
- Item item2 = container.getItem(id);
- item2.getItemProperty("NAME").setValue(name);
- Assert.assertEquals(name, item2.getItemProperty("NAME").getValue());
-
- Item item3 = container.getItem(id);
- String name3 = (String) item3.getItemProperty("NAME").getValue();
-
- Assert.assertEquals(name, name3);
- }
-
- @Test
- public void ticket10032_empty_set_metadata_correctly_handled()
- throws SQLException {
- // If problem exists will break when method getPropertyIds()
- // is called in constructor SQLContainer(QueryDelegate delegate).
- SQLContainer container = new SQLContainer(new FreeformQuery(
- "SELECT * FROM people WHERE name='does_not_exist'",
- Arrays.asList("ID"), connectionPool));
- Assert.assertTrue("Got items while expected empty set",
- container.size() == 0);
- }
-}
import java.util.HashMap;
import java.util.Map;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.server.JsonCodec.BeanProperty;
import com.vaadin.shared.communication.UidlValue;
* @since 7.0
*
*/
-public class JSONSerializerTest extends TestCase {
+public class JSONSerializerTest {
HashMap<String, AbstractSplitPanelState> stringToStateMap;
HashMap<AbstractSplitPanelState, String> stateToStringMap;
+ @Test
public void testStringToBeanMapSerialization() throws Exception {
Type mapType = getClass().getDeclaredField("stringToStateMap")
.getGenericType();
ensureDecodedCorrectly(stringToStateMap, encodedMap, mapType);
}
+ @Test
public void testBeanToStringMapSerialization() throws Exception {
Type mapType = getClass().getDeclaredField("stateToStringMap")
.getGenericType();
ensureDecodedCorrectly(stateToStringMap, encodedMap, mapType);
}
+ @Test
public void testNullLegacyValue() throws JsonException {
JsonArray inputArray = Json.createArray();
inputArray.set(0, "n");
inputArray.set(1, Json.createNull());
UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
UidlValue.class, true, inputArray, null);
- assertNull(decodedObject.getValue());
+ Assert.assertNull(decodedObject.getValue());
}
+ @Test(expected = JsonException.class)
public void testNullTypeOtherValue() {
- try {
- JsonArray inputArray = Json.createArray();
- inputArray.set(0, "n");
- inputArray.set(1, "a");
- UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
- UidlValue.class, true, inputArray, null);
-
- throw new AssertionFailedError("No JsonException thrown");
- } catch (JsonException e) {
- // Should throw exception
- }
+ JsonArray inputArray = Json.createArray();
+ inputArray.set(0, "n");
+ inputArray.set(1, "a");
+ UidlValue decodedObject = (UidlValue) JsonCodec.decodeInternalType(
+ UidlValue.class, true, inputArray, null);
}
private void ensureDecodedCorrectly(Object original, JsonValue encoded,
Type type) throws Exception {
Object serverSideDecoded = JsonCodec.decodeInternalOrCustomType(type,
encoded, null);
- assertTrue("Server decoded", equals(original, serverSideDecoded));
+ Assert.assertTrue("Server decoded", equals(original, serverSideDecoded));
}
import javax.servlet.http.HttpServletRequest;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class TestAbstractApplicationServletStaticFilesLocation extends TestCase {
+public class TestAbstractApplicationServletStaticFilesLocation {
VaadinServlet servlet;
// private Method getStaticFilesLocationMethod;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUp() throws Exception {
servlet = new VaadinServlet();
servlet.init(new MockServletConfig());
}
+ @Test
public void testWidgetSetLocation() throws Exception {
String location;
// should return . (relative url resolving to /contextpath)
location = testLocation("http://dummy.host:8080", "/contextpath",
"/servlet", "");
- assertEquals(".", location);
+ Assert.assertEquals(".", location);
// http://dummy.host:8080/contextpath/servlet/
// should return ./.. (relative url resolving to /contextpath)
location = testLocation("http://dummy.host:8080", "/contextpath",
"/servlet", "/");
- assertEquals("./..", location);
+ Assert.assertEquals("./..", location);
// http://dummy.host:8080/servlet
// should return "."
location = testLocation("http://dummy.host:8080", "", "/servlet", "");
- assertEquals(".", location);
+ Assert.assertEquals(".", location);
// http://dummy.host/contextpath/servlet/extra/stuff
// should return ./../.. (relative url resolving to /contextpath)
location = testLocation("http://dummy.host", "/contextpath",
"/servlet", "/extra/stuff");
- assertEquals("./../..", location);
+ Assert.assertEquals("./../..", location);
// http://dummy.host/context/path/servlet/extra/stuff
// should return ./../.. (relative url resolving to /context/path)
location = testLocation("http://dummy.host", "/context/path",
"/servlet", "/extra/stuff");
- assertEquals("./../..", location);
+ Assert.assertEquals("./../..", location);
/* Include requests */
// Include request support dropped with support for portlet1
--- /dev/null
+package com.vaadin.server;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class VaadinPortletRequestTest {
+
+ private PortletRequest request;
+ private VaadinPortletRequest sut;
+ private VaadinPortletService service;
+ private PortletPreferences preferences;
+
+ @Before
+ public void setup() {
+ request = mock(PortletRequest.class);
+ service = mock(VaadinPortletService.class);
+
+ sut = new VaadinPortletRequest(request, service);
+
+ preferences = mock(PortletPreferences.class);
+ when(request.getPreferences()).thenReturn(preferences);
+ }
+
+ @Test
+ public void portletPreferenceIsFetched() {
+ when(preferences.getValue(eq("foo"), anyString())).thenReturn("bar");
+
+ String value = sut.getPortletPreference("foo");
+
+ assertThat(value, is("bar"));
+ }
+
+ @Test
+ public void defaultValueForPortletPreferenceIsNull() {
+ when(preferences.getValue(anyString(), isNull(String.class)))
+ .thenReturn(null);
+
+ String value = sut.getPortletPreference("foo");
+
+ assertNull(value);
+ }
+
+}
+++ /dev/null
-package com.vaadin.server;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import javax.portlet.PortletPreferences;
-import javax.portlet.PortletRequest;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class VaadinPortletRequestTests {
-
- private PortletRequest request;
- private VaadinPortletRequest sut;
- private VaadinPortletService service;
- private PortletPreferences preferences;
-
- @Before
- public void setup() {
- request = mock(PortletRequest.class);
- service = mock(VaadinPortletService.class);
-
- sut = new VaadinPortletRequest(request, service);
-
- preferences = mock(PortletPreferences.class);
- when(request.getPreferences()).thenReturn(preferences);
- }
-
- @Test
- public void portletPreferenceIsFetched() {
- when(preferences.getValue(eq("foo"), anyString())).thenReturn("bar");
-
- String value = sut.getPortletPreference("foo");
-
- assertThat(value, is("bar"));
- }
-
- @Test
- public void defaultValueForPortletPreferenceIsNull() {
- when(preferences.getValue(anyString(), isNull(String.class)))
- .thenReturn(null);
-
- String value = sut.getPortletPreference("foo");
-
- assertNull(value);
- }
-
-}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.server;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.vaadin.shared.ui.ui.UIConstants;
+import com.vaadin.ui.UI;
+
+public class VaadinPortletServiceTest {
+
+ private VaadinPortletService sut;
+ private VaadinPortletRequest request;
+ private DeploymentConfiguration conf;
+
+ @Before
+ public void setup() throws ServiceException {
+ VaadinPortlet portlet = mock(VaadinPortlet.class);
+ conf = mock(DeploymentConfiguration.class);
+
+ sut = new VaadinPortletService(portlet, conf);
+
+ request = mock(VaadinPortletRequest.class);
+ }
+
+ private void mockFileLocationProperty(String location) {
+ mockPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH,
+ location);
+ }
+
+ private void mockPortalProperty(String name, String value) {
+ when(request.getPortalProperty(name)).thenReturn(value);
+ }
+
+ private void mockFileLocationPreference(String location) {
+ when(
+ request.getPortletPreference(Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH))
+ .thenReturn(location);
+ }
+
+ private void mockLocationDeploymentConfiguration(String location) {
+ when(
+ conf.getApplicationOrSystemProperty(
+ Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH, null))
+ .thenReturn(location);
+ }
+
+ private String getStaticFileLocation() {
+ return sut.getStaticFileLocation(request);
+ }
+
+ private String getTheme() {
+ return sut.getConfiguredTheme(request);
+ }
+
+ private void mockThemeProperty(String theme) {
+ mockPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME, theme);
+ }
+
+ private void mockWidgetsetProperty(String widgetset) {
+ mockPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_WIDGETSET,
+ widgetset);
+ }
+
+ private void mockWidgetsetConfiguration(String widgetset) {
+ when(conf.getWidgetset(null)).thenReturn(widgetset);
+ }
+
+ @Test
+ public void preferencesOverrideDeploymentConfiguration() {
+ mockFileLocationPreference("prefs");
+ mockLocationDeploymentConfiguration("conf");
+
+ String location = getStaticFileLocation();
+
+ assertThat(location, is("prefs"));
+ }
+
+ @Test
+ public void deploymentConfigurationOverridesProperties() {
+ mockFileLocationPreference(null);
+ mockLocationDeploymentConfiguration("conf");
+ mockFileLocationProperty("props");
+
+ String location = getStaticFileLocation();
+
+ assertThat(location, is("conf"));
+ }
+
+ @Test
+ public void defaultFileLocationIsSet() {
+ mockFileLocationPreference(null);
+ mockLocationDeploymentConfiguration(null);
+ mockFileLocationProperty(null);
+
+ String location = getStaticFileLocation();
+
+ assertThat(location, is("/html"));
+ }
+
+ @Test
+ public void trailingSlashesAreTrimmedFromStaticFileLocation() {
+ mockFileLocationPreference("/content////");
+
+ String staticFileLocation = getStaticFileLocation();
+
+ assertThat(staticFileLocation, is("/content"));
+ }
+
+ @Test
+ public void themeCanBeOverridden() {
+ mockThemeProperty("foobar");
+
+ String theme = getTheme();
+
+ assertThat(theme, is("foobar"));
+ }
+
+ @Test
+ public void defaultThemeIsSet() {
+ mockThemeProperty(null);
+
+ String theme = getTheme();
+
+ assertThat(theme, is(Constants.DEFAULT_THEME_NAME));
+ }
+
+ private String getWidgetset() {
+ return sut.getConfiguredWidgetset(request);
+ }
+
+ @Test
+ public void defaultWidgetsetIsSet() {
+ mockWidgetsetProperty(null);
+ mockWidgetsetConfiguration(null);
+
+ String widgetset = getWidgetset();
+
+ assertThat(widgetset, is(Constants.DEFAULT_WIDGETSET));
+ }
+
+ @Test
+ public void configurationWidgetsetOverridesProperty() {
+ mockWidgetsetProperty("foo");
+ mockWidgetsetConfiguration("bar");
+
+ String widgetset = getWidgetset();
+
+ assertThat(widgetset, is("bar"));
+ }
+
+ @Test
+ public void oldDefaultWidgetsetIsMappedToDefaultWidgetset() {
+ mockWidgetsetConfiguration(null);
+ mockWidgetsetProperty("com.vaadin.portal.gwt.PortalDefaultWidgetSet");
+
+ String widgetset = getWidgetset();
+
+ assertThat(widgetset, is(Constants.DEFAULT_WIDGETSET));
+ }
+
+ @Test
+ public void oldDefaultWidgetSetIsNotMappedToDefaultWidgetset() {
+ mockWidgetsetConfiguration("com.vaadin.portal.gwt.PortalDefaultWidgetSet");
+ mockWidgetsetProperty(null);
+
+ String widgetset = getWidgetset();
+
+ assertThat(widgetset,
+ is("com.vaadin.portal.gwt.PortalDefaultWidgetSet"));
+ }
+
+ @Test
+ public void findUIDoesntThrowNPE() {
+ try {
+ ReentrantLock mockLock = Mockito.mock(ReentrantLock.class);
+ when(mockLock.isHeldByCurrentThread()).thenReturn(true);
+
+ WrappedSession emptyWrappedSession = Mockito
+ .mock(WrappedPortletSession.class);
+ when(emptyWrappedSession.getAttribute("null.lock")).thenReturn(
+ mockLock);
+ VaadinRequest requestWithUIIDSet = Mockito
+ .mock(VaadinRequest.class);
+ when(requestWithUIIDSet.getParameter(UIConstants.UI_ID_PARAMETER))
+ .thenReturn("1");
+ when(requestWithUIIDSet.getWrappedSession()).thenReturn(
+ emptyWrappedSession);
+
+ UI ui = sut.findUI(requestWithUIIDSet);
+ Assert.assertNull("Unset session did not return null", ui);
+ } catch (NullPointerException e) {
+ Assert.fail("findUI threw a NullPointerException");
+ }
+ }
+}
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.server;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.concurrent.locks.ReentrantLock;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import com.vaadin.shared.ui.ui.UIConstants;
-import com.vaadin.ui.UI;
-
-public class VaadinPortletServiceTests {
-
- private VaadinPortletService sut;
- private VaadinPortletRequest request;
- private DeploymentConfiguration conf;
-
- @Before
- public void setup() throws ServiceException {
- VaadinPortlet portlet = mock(VaadinPortlet.class);
- conf = mock(DeploymentConfiguration.class);
-
- sut = new VaadinPortletService(portlet, conf);
-
- request = mock(VaadinPortletRequest.class);
- }
-
- private void mockFileLocationProperty(String location) {
- mockPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH,
- location);
- }
-
- private void mockPortalProperty(String name, String value) {
- when(request.getPortalProperty(name)).thenReturn(value);
- }
-
- private void mockFileLocationPreference(String location) {
- when(
- request.getPortletPreference(Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH))
- .thenReturn(location);
- }
-
- private void mockLocationDeploymentConfiguration(String location) {
- when(
- conf.getApplicationOrSystemProperty(
- Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH, null))
- .thenReturn(location);
- }
-
- private String getStaticFileLocation() {
- return sut.getStaticFileLocation(request);
- }
-
- private String getTheme() {
- return sut.getConfiguredTheme(request);
- }
-
- private void mockThemeProperty(String theme) {
- mockPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME, theme);
- }
-
- private void mockWidgetsetProperty(String widgetset) {
- mockPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_WIDGETSET,
- widgetset);
- }
-
- private void mockWidgetsetConfiguration(String widgetset) {
- when(conf.getWidgetset(null)).thenReturn(widgetset);
- }
-
- @Test
- public void preferencesOverrideDeploymentConfiguration() {
- mockFileLocationPreference("prefs");
- mockLocationDeploymentConfiguration("conf");
-
- String location = getStaticFileLocation();
-
- assertThat(location, is("prefs"));
- }
-
- @Test
- public void deploymentConfigurationOverridesProperties() {
- mockFileLocationPreference(null);
- mockLocationDeploymentConfiguration("conf");
- mockFileLocationProperty("props");
-
- String location = getStaticFileLocation();
-
- assertThat(location, is("conf"));
- }
-
- @Test
- public void defaultFileLocationIsSet() {
- mockFileLocationPreference(null);
- mockLocationDeploymentConfiguration(null);
- mockFileLocationProperty(null);
-
- String location = getStaticFileLocation();
-
- assertThat(location, is("/html"));
- }
-
- @Test
- public void trailingSlashesAreTrimmedFromStaticFileLocation() {
- mockFileLocationPreference("/content////");
-
- String staticFileLocation = getStaticFileLocation();
-
- assertThat(staticFileLocation, is("/content"));
- }
-
- @Test
- public void themeCanBeOverridden() {
- mockThemeProperty("foobar");
-
- String theme = getTheme();
-
- assertThat(theme, is("foobar"));
- }
-
- @Test
- public void defaultThemeIsSet() {
- mockThemeProperty(null);
-
- String theme = getTheme();
-
- assertThat(theme, is(Constants.DEFAULT_THEME_NAME));
- }
-
- private String getWidgetset() {
- return sut.getConfiguredWidgetset(request);
- }
-
- @Test
- public void defaultWidgetsetIsSet() {
- mockWidgetsetProperty(null);
- mockWidgetsetConfiguration(null);
-
- String widgetset = getWidgetset();
-
- assertThat(widgetset, is(Constants.DEFAULT_WIDGETSET));
- }
-
- @Test
- public void configurationWidgetsetOverridesProperty() {
- mockWidgetsetProperty("foo");
- mockWidgetsetConfiguration("bar");
-
- String widgetset = getWidgetset();
-
- assertThat(widgetset, is("bar"));
- }
-
- @Test
- public void oldDefaultWidgetsetIsMappedToDefaultWidgetset() {
- mockWidgetsetConfiguration(null);
- mockWidgetsetProperty("com.vaadin.portal.gwt.PortalDefaultWidgetSet");
-
- String widgetset = getWidgetset();
-
- assertThat(widgetset, is(Constants.DEFAULT_WIDGETSET));
- }
-
- @Test
- public void oldDefaultWidgetSetIsNotMappedToDefaultWidgetset() {
- mockWidgetsetConfiguration("com.vaadin.portal.gwt.PortalDefaultWidgetSet");
- mockWidgetsetProperty(null);
-
- String widgetset = getWidgetset();
-
- assertThat(widgetset,
- is("com.vaadin.portal.gwt.PortalDefaultWidgetSet"));
- }
-
- @Test
- public void findUIDoesntThrowNPE() {
- try {
- ReentrantLock mockLock = Mockito.mock(ReentrantLock.class);
- when(mockLock.isHeldByCurrentThread()).thenReturn(true);
-
- WrappedSession emptyWrappedSession = Mockito
- .mock(WrappedPortletSession.class);
- when(emptyWrappedSession.getAttribute("null.lock")).thenReturn(
- mockLock);
- VaadinRequest requestWithUIIDSet = Mockito
- .mock(VaadinRequest.class);
- when(requestWithUIIDSet.getParameter(UIConstants.UI_ID_PARAMETER))
- .thenReturn("1");
- when(requestWithUIIDSet.getWrappedSession()).thenReturn(
- emptyWrappedSession);
-
- UI ui = sut.findUI(requestWithUIIDSet);
- Assert.assertNull("Unset session did not return null", ui);
- } catch (NullPointerException e) {
- Assert.fail("findUI threw a NullPointerException");
- }
- }
-}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.server;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.portlet.PortalContext;
+import javax.portlet.PortletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.server.VaadinPortlet.VaadinGateInRequest;
+import com.vaadin.server.VaadinPortlet.VaadinLiferayRequest;
+import com.vaadin.server.VaadinPortlet.VaadinWebSpherePortalRequest;
+
+public class VaadinPortletTest {
+
+ private VaadinPortlet sut;
+ private PortletRequest portletRequest;
+ private PortalContext portalContext;
+
+ @Before
+ public void setup() {
+ sut = new VaadinPortlet();
+
+ portletRequest = mock(PortletRequest.class);
+ portalContext = mock(PortalContext.class);
+
+ when(portletRequest.getPortalContext()).thenReturn(portalContext);
+ }
+
+ private void mockPortalInfo(String name) {
+ when(portalContext.getPortalInfo()).thenReturn(name);
+ }
+
+ private VaadinPortletRequest createRequest() {
+ VaadinPortletRequest request = sut.createVaadinRequest(portletRequest);
+ return request;
+ }
+
+ @Test
+ public void gateInRequestIsCreated() {
+ mockPortalInfo("gatein");
+
+ VaadinPortletRequest request = createRequest();
+
+ assertThat(request, instanceOf(VaadinGateInRequest.class));
+ }
+
+ @Test
+ public void liferayRequestIsCreated() {
+ mockPortalInfo("liferay");
+
+ VaadinPortletRequest request = createRequest();
+
+ assertThat(request, instanceOf(VaadinLiferayRequest.class));
+ }
+
+ @Test
+ public void webspherePortalRequestIsCreated() {
+ mockPortalInfo("websphere portal");
+
+ VaadinPortletRequest request = createRequest();
+
+ assertThat(request, instanceOf(VaadinWebSpherePortalRequest.class));
+ }
+
+ @Test
+ public void defaultPortletRequestIsCreated() {
+ mockPortalInfo("foobar");
+
+ VaadinPortletRequest request = createRequest();
+
+ assertThat(request, instanceOf(VaadinPortletRequest.class));
+ }
+
+}
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.server;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import javax.portlet.PortalContext;
-import javax.portlet.PortletRequest;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.vaadin.server.VaadinPortlet.VaadinGateInRequest;
-import com.vaadin.server.VaadinPortlet.VaadinLiferayRequest;
-import com.vaadin.server.VaadinPortlet.VaadinWebSpherePortalRequest;
-
-public class VaadinPortletTests {
-
- private VaadinPortlet sut;
- private PortletRequest portletRequest;
- private PortalContext portalContext;
-
- @Before
- public void setup() {
- sut = new VaadinPortlet();
-
- portletRequest = mock(PortletRequest.class);
- portalContext = mock(PortalContext.class);
-
- when(portletRequest.getPortalContext()).thenReturn(portalContext);
- }
-
- private void mockPortalInfo(String name) {
- when(portalContext.getPortalInfo()).thenReturn(name);
- }
-
- private VaadinPortletRequest createRequest() {
- VaadinPortletRequest request = sut.createVaadinRequest(portletRequest);
- return request;
- }
-
- @Test
- public void gateInRequestIsCreated() {
- mockPortalInfo("gatein");
-
- VaadinPortletRequest request = createRequest();
-
- assertThat(request, instanceOf(VaadinGateInRequest.class));
- }
-
- @Test
- public void liferayRequestIsCreated() {
- mockPortalInfo("liferay");
-
- VaadinPortletRequest request = createRequest();
-
- assertThat(request, instanceOf(VaadinLiferayRequest.class));
- }
-
- @Test
- public void webspherePortalRequestIsCreated() {
- mockPortalInfo("websphere portal");
-
- VaadinPortletRequest request = createRequest();
-
- assertThat(request, instanceOf(VaadinWebSpherePortalRequest.class));
- }
-
- @Test
- public void defaultPortletRequestIsCreated() {
- mockPortalInfo("foobar");
-
- VaadinPortletRequest request = createRequest();
-
- assertThat(request, instanceOf(VaadinPortletRequest.class));
- }
-
-}
import com.vaadin.server.communication.AtmospherePushConnection.State;
import com.vaadin.ui.UI;
-/**
- * @author Vaadin Ltd
- */
public class AtmospherePushConnectionTest {
@Test
public void testSerialization() throws Exception {
import java.util.Locale;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.DefaultConverterFactory;
import com.vaadin.tests.util.AlwaysLockedVaadinSession;
import com.vaadin.ui.TextField;
-public class ConverterFactoryTest extends TestCase {
+public class ConverterFactoryTest {
public static class ConvertTo42 implements Converter<String, Integer> {
}
}
+ @Test
public void testApplicationConverterFactoryInBackgroundThread() {
VaadinSession.setCurrent(null);
final VaadinSession appWithCustomIntegerConverter = new AlwaysLockedVaadinSession(
tf.setConverter(Integer.class);
// The application converter always returns 42. Current application is
// null
- assertEquals(42, tf.getConvertedValue());
+ Assert.assertEquals(42, tf.getConvertedValue());
}
+ @Test
public void testApplicationConverterFactoryForDetachedComponent() {
final VaadinSession appWithCustomIntegerConverter = new AlwaysLockedVaadinSession(
null);
tf.setConverter(Integer.class);
// The application converter always returns 42. Current application is
// null
- assertEquals(42, tf.getConvertedValue());
+ Assert.assertEquals(42, tf.getConvertedValue());
}
+ @Test
public void testApplicationConverterFactoryForDifferentThanCurrentApplication() {
final VaadinSession fieldAppWithCustomIntegerConverter = new AlwaysLockedVaadinSession(
null);
// The application converter always returns 42. Application.getCurrent()
// should not be used
- assertEquals(42, tf.getConvertedValue());
+ Assert.assertEquals(42, tf.getConvertedValue());
}
}
import java.util.Date;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.DateToLongConverter;
-public class DateToLongConverterTest extends TestCase {
+public class DateToLongConverterTest {
DateToLongConverter converter = new DateToLongConverter();
+ @Test
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Long.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel(null, Long.class, null));
}
+ @Test
public void testValueConversion() {
- assertEquals(Long.valueOf(946677600000l),
+ Assert.assertEquals(Long.valueOf(946677600000l),
converter.convertToModel(new Date(100, 0, 1), Long.class, null));
}
}
import java.util.Date;
import java.util.Locale;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.DateToSqlDateConverter;
-public class DateToSqlDateConverterTest extends TestCase {
+public class DateToSqlDateConverterTest {
DateToSqlDateConverter converter = new DateToSqlDateConverter();
+ @Test
public void testNullConversion() {
- assertEquals(null,
+ Assert.assertEquals(null,
converter.convertToModel(null, java.sql.Date.class, null));
}
+ @Test
public void testValueConversion() {
Date testDate = new Date(100, 0, 1);
long time = testDate.getTime();
- assertEquals(testDate, converter.convertToModel(
+ Assert.assertEquals(testDate, converter.convertToModel(
new java.sql.Date(time), java.sql.Date.class, Locale.ENGLISH));
}
}
import java.math.BigDecimal;
import java.util.Locale;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.StringToBigDecimalConverter;
-public class StringToBigDecimalConverterTest extends TestCase {
+public class StringToBigDecimalConverterTest {
StringToBigDecimalConverter converter = new StringToBigDecimalConverter();
+ @Test
public void testNullConversion() {
- assertEquals(null,
+ Assert.assertEquals(null,
converter.convertToModel(null, BigDecimal.class, null));
}
+ @Test
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", BigDecimal.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel("", BigDecimal.class, null));
}
+ @Test
public void testValueParsing() {
BigDecimal converted = converter.convertToModel("10", BigDecimal.class,
null);
BigDecimal expected = new BigDecimal(10);
- assertEquals(expected, converted);
+ Assert.assertEquals(expected, converted);
}
+ @Test
public void testValueFormatting() {
BigDecimal bd = new BigDecimal(12.5);
String expected = "12,5";
String converted = converter.convertToPresentation(bd, String.class,
Locale.GERMAN);
- assertEquals(expected, converted);
+ Assert.assertEquals(expected, converted);
}
}
import java.math.BigInteger;
import java.util.Locale;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.StringToBigIntegerConverter;
-public class StringToBigIntegerConverterTest extends TestCase {
+public class StringToBigIntegerConverterTest {
StringToBigIntegerConverter converter = new StringToBigIntegerConverter();
+ @Test
public void testNullConversion() {
- assertEquals("Null value was converted incorrectly", null,
+ Assert.assertEquals("Null value was converted incorrectly", null,
converter.convertToModel(null, BigInteger.class, null));
}
+ @Test
public void testEmptyStringConversion() {
- assertEquals("Empty value was converted incorrectly", null,
+ Assert.assertEquals("Empty value was converted incorrectly", null,
converter.convertToModel("", BigInteger.class, null));
}
+ @Test
public void testValueParsing() {
String bigInt = "1180591620717411303424"; // 2^70 > 2^63 - 1
BigInteger converted = converter.convertToModel(bigInt,
BigInteger.class, null);
BigInteger expected = new BigInteger(bigInt);
- assertEquals("Value bigger than max long was converted incorrectly",
+ Assert.assertEquals(
+ "Value bigger than max long was converted incorrectly",
expected, converted);
}
+ @Test
public void testValueFormatting() {
BigInteger bd = new BigInteger("1000");
String expected = "1.000";
String converted = converter.convertToPresentation(bd, String.class,
Locale.GERMAN);
- assertEquals("Value with specific locale was converted incorrectly",
+ Assert.assertEquals(
+ "Value with specific locale was converted incorrectly",
expected, converted);
}
}
package com.vaadin.tests.data.converter;
-import junit.framework.TestCase;
-
-import com.vaadin.data.util.converter.StringToBooleanConverter;
-
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
-public class StringToBooleanConverterTest extends TestCase {
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.data.util.converter.StringToBooleanConverter;
+
+public class StringToBooleanConverterTest {
StringToBooleanConverter converter = new StringToBooleanConverter();
- StringToBooleanConverter yesNoConverter = new StringToBooleanConverter("yes","no");
+ StringToBooleanConverter yesNoConverter = new StringToBooleanConverter(
+ "yes", "no");
StringToBooleanConverter localeConverter = new StringToBooleanConverter() {
@Override
public String getFalseString(Locale locale) {
- return SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG,locale).format(new Date(3000000000000L));
+ return SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG,
+ locale).format(new Date(3000000000000L));
}
@Override
public String getTrueString(Locale locale) {
- return SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG,locale).format(new Date(2000000000000L));
+ return SimpleDateFormat.getDateInstance(SimpleDateFormat.LONG,
+ locale).format(new Date(2000000000000L));
}
};
+ @Test
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Boolean.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel(null, Boolean.class, null));
}
+ @Test
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Boolean.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel("", Boolean.class, null));
}
+ @Test
public void testValueConversion() {
- assertTrue(converter.convertToModel("true", Boolean.class, null));
- assertFalse(converter.convertToModel("false", Boolean.class, null));
+ Assert.assertTrue(converter.convertToModel("true", Boolean.class, null));
+ Assert.assertFalse(converter.convertToModel("false", Boolean.class,
+ null));
}
+ @Test
public void testYesNoValueConversion() {
- assertTrue(yesNoConverter.convertToModel("yes", Boolean.class, null));
- assertFalse(yesNoConverter.convertToModel("no", Boolean.class, null));
+ Assert.assertTrue(yesNoConverter.convertToModel("yes", Boolean.class,
+ null));
+ Assert.assertFalse(yesNoConverter.convertToModel("no", Boolean.class,
+ null));
- assertEquals("yes", yesNoConverter.convertToPresentation(true, String.class, null));
- assertEquals("no", yesNoConverter.convertToPresentation(false, String.class, null));
+ Assert.assertEquals("yes",
+ yesNoConverter.convertToPresentation(true, String.class, null));
+ Assert.assertEquals("no",
+ yesNoConverter.convertToPresentation(false, String.class, null));
}
-
+ @Test
public void testLocale() {
- assertEquals("May 18, 2033", localeConverter.convertToPresentation(true, String.class, Locale.US));
- assertEquals("January 24, 2065", localeConverter.convertToPresentation(false, String.class, Locale.US));
+ Assert.assertEquals("May 18, 2033", localeConverter
+ .convertToPresentation(true, String.class, Locale.US));
+ Assert.assertEquals("January 24, 2065", localeConverter
+ .convertToPresentation(false, String.class, Locale.US));
- assertEquals("18. Mai 2033", localeConverter.convertToPresentation(true, String.class, Locale.GERMANY));
- assertEquals("24. Januar 2065", localeConverter.convertToPresentation(false, String.class, Locale.GERMANY));
+ Assert.assertEquals("18. Mai 2033", localeConverter
+ .convertToPresentation(true, String.class, Locale.GERMANY));
+ Assert.assertEquals("24. Januar 2065", localeConverter
+ .convertToPresentation(false, String.class, Locale.GERMANY));
}
-
}
package com.vaadin.tests.data.converter;
-import junit.framework.TestCase;
-
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.Converter.ConversionException;
import com.vaadin.data.util.converter.ReverseConverter;
import com.vaadin.data.util.converter.StringToByteConverter;
-public class StringToByteConverterTest extends TestCase {
+public class StringToByteConverterTest {
StringToByteConverter converter = new StringToByteConverter();
Converter<Byte, String> reverseConverter = new ReverseConverter<Byte, String>(
converter);
+ @Test
public void testNullConversion() {
- assertEquals("Null value was converted incorrectly", null,
+ Assert.assertEquals("Null value was converted incorrectly", null,
converter.convertToModel(null, Byte.class, null));
}
+ @Test
public void testReverseNullConversion() {
- assertEquals("Null value reversely was converted incorrectly", null,
- reverseConverter.convertToModel(null, String.class, null));
+ Assert.assertEquals("Null value reversely was converted incorrectly",
+ null, reverseConverter.convertToModel(null, String.class, null));
}
+ @Test
public void testEmptyStringConversion() {
- assertEquals("Empty value was converted incorrectly", null,
+ Assert.assertEquals("Empty value was converted incorrectly", null,
converter.convertToModel("", Byte.class, null));
}
+ @Test
public void testValueConversion() {
- assertEquals("Byte value was converted incorrectly",
+ Assert.assertEquals("Byte value was converted incorrectly",
Byte.valueOf((byte) 10),
converter.convertToModel("10", Byte.class, null));
}
+ @Test
public void testReverseValueConversion() {
- assertEquals("Byte value reversely was converted incorrectly",
+ Assert.assertEquals("Byte value reversely was converted incorrectly",
reverseConverter.convertToModel((byte) 10, String.class, null),
"10");
}
+ @Test
public void testExtremeByteValueConversion() {
byte b = converter.convertToModel("127", Byte.class, null);
Assert.assertEquals(Byte.MAX_VALUE, b);
b = converter.convertToModel("-128", Byte.class, null);
- assertEquals("Min byte value was converted incorrectly",
+ Assert.assertEquals("Min byte value was converted incorrectly",
Byte.MIN_VALUE, b);
}
+ @Test
public void testValueOutOfRange() {
Double[] values = new Double[] { Byte.MAX_VALUE * 2.0,
Byte.MIN_VALUE * 2.0, Long.MAX_VALUE * 2.0,
} catch (ConversionException expected) {
}
}
- assertFalse("Accepted value outside range of int", accepted);
+ Assert.assertFalse("Accepted value outside range of int", accepted);
}
}
import java.util.Date;
import java.util.Locale;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.StringToDateConverter;
-public class StringToDateConverterTest extends TestCase {
+public class StringToDateConverterTest {
StringToDateConverter converter = new StringToDateConverter();
+ @Test
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Date.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel(null, Date.class, null));
}
+ @Test
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Date.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel("", Date.class, null));
}
+ @Test
public void testValueConversion() {
- assertEquals(new Date(100, 0, 1), converter.convertToModel(
+ Assert.assertEquals(new Date(100, 0, 1), converter.convertToModel(
"Jan 1, 2000 12:00:00 AM", Date.class, Locale.ENGLISH));
}
}
package com.vaadin.tests.data.converter;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.StringToDoubleConverter;
-public class StringToDoubleConverterTest extends TestCase {
+public class StringToDoubleConverterTest {
StringToDoubleConverter converter = new StringToDoubleConverter();
+ @Test
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Double.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel(null, Double.class, null));
}
+ @Test
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Double.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel("", Double.class, null));
}
+ @Test
public void testValueConversion() {
- assertEquals(10.0, converter.convertToModel("10", Double.class, null));
+ Double value = converter.convertToModel("10", Double.class, null);
+ Assert.assertEquals(10.0d, value, 0.01d);
}
}
package com.vaadin.tests.data.converter;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.StringToFloatConverter;
-public class StringToFloatConverterTest extends TestCase {
+public class StringToFloatConverterTest {
StringToFloatConverter converter = new StringToFloatConverter();
+ @Test
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Float.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel(null, Float.class, null));
}
+ @Test
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Float.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel("", Float.class, null));
}
+ @Test
public void testValueConversion() {
- assertEquals(Float.valueOf(10),
+ Assert.assertEquals(Float.valueOf(10),
converter.convertToModel("10", Float.class, null));
}
}
package com.vaadin.tests.data.converter;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.Converter.ConversionException;
import com.vaadin.data.util.converter.StringToIntegerConverter;
-public class StringToIntegerConverterTest extends TestCase {
+public class StringToIntegerConverterTest {
StringToIntegerConverter converter = new StringToIntegerConverter();
+ @Test
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Integer.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel(null, Integer.class, null));
}
+ @Test
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Integer.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel("", Integer.class, null));
}
+ @Test
public void testValueOutOfRange() {
Double[] values = new Double[] { Integer.MAX_VALUE * 2.0,
Integer.MIN_VALUE * 2.0, Long.MAX_VALUE * 2.0,
} catch (ConversionException expected) {
}
}
- assertFalse("Accepted value outside range of int", accepted);
+ Assert.assertFalse("Accepted value outside range of int", accepted);
}
+ @Test
public void testValueConversion() {
- assertEquals(Integer.valueOf(10),
+ Assert.assertEquals(Integer.valueOf(10),
converter.convertToModel("10", Integer.class, null));
}
}
import java.util.Locale;
-import junit.framework.TestCase;
-
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.ReverseConverter;
import com.vaadin.data.util.converter.StringToLongConverter;
-public class StringToLongConverterTest extends TestCase {
+public class StringToLongConverterTest {
StringToLongConverter converter = new StringToLongConverter();
Converter<Long, String> reverseConverter = new ReverseConverter<Long, String>(
converter);
+ @Test
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Long.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel(null, Long.class, null));
}
+ @Test
public void testReverseNullConversion() {
- assertEquals(null,
+ Assert.assertEquals(null,
reverseConverter.convertToModel(null, String.class, null));
}
+ @Test
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Long.class, null));
+ Assert.assertEquals(null,
+ converter.convertToModel("", Long.class, null));
}
+ @Test
public void testValueConversion() {
- assertEquals(Long.valueOf(10),
+ Assert.assertEquals(Long.valueOf(10),
converter.convertToModel("10", Long.class, null));
}
+ @Test
public void testReverseValueConversion() {
- assertEquals(reverseConverter.convertToModel(10L, String.class, null),
- "10");
+ Assert.assertEquals(
+ reverseConverter.convertToModel(10L, String.class, null), "10");
}
+ @Test
public void testExtremeLongValueConversion() {
long l = converter.convertToModel("9223372036854775807", Long.class,
null);
Assert.assertEquals(Long.MAX_VALUE, l);
l = converter.convertToModel("-9223372036854775808", Long.class, null);
- assertEquals(Long.MIN_VALUE, l);
+ Assert.assertEquals(Long.MIN_VALUE, l);
}
+ @Test
public void testExtremeReverseLongValueConversion() {
String str = reverseConverter.convertToModel(Long.MAX_VALUE,
String.class, Locale.ENGLISH);
Assert.assertEquals("-9,223,372,036,854,775,808", str);
}
+ @Test
public void testOutOfBoundsValueConversion() {
// Long.MAX_VALUE+1 is converted to Long.MAX_VALUE
long l = converter.convertToModel("9223372036854775808", Long.class,
Assert.assertEquals(Long.MAX_VALUE, l);
// Long.MIN_VALUE-1 is converted to Long.MIN_VALUE
l = converter.convertToModel("-9223372036854775809", Long.class, null);
- assertEquals(Long.MIN_VALUE, l);
+ Assert.assertEquals(Long.MIN_VALUE, l);
}
}
package com.vaadin.tests.data.converter;
-import junit.framework.TestCase;
-
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.Converter.ConversionException;
import com.vaadin.data.util.converter.ReverseConverter;
import com.vaadin.data.util.converter.StringToShortConverter;
-public class StringToShortConverterTest extends TestCase {
+public class StringToShortConverterTest {
StringToShortConverter converter = new StringToShortConverter();
Converter<Short, String> reverseConverter = new ReverseConverter<Short, String>(
converter);
+ @Test
public void testNullConversion() {
- assertEquals("Null value was converted incorrectly", null,
+ Assert.assertEquals("Null value was converted incorrectly", null,
converter.convertToModel(null, Short.class, null));
}
+ @Test
public void testReverseNullConversion() {
- assertEquals("Null value reversely was converted incorrectly", null,
- reverseConverter.convertToModel(null, String.class, null));
+ Assert.assertEquals("Null value reversely was converted incorrectly",
+ null, reverseConverter.convertToModel(null, String.class, null));
}
+ @Test
public void testEmptyStringConversion() {
- assertEquals("Empty value was converted incorrectly", null,
+ Assert.assertEquals("Empty value was converted incorrectly", null,
converter.convertToModel("", Short.class, null));
}
+ @Test
public void testValueConversion() {
- assertEquals("Short value was converted incorrectly",
+ Assert.assertEquals("Short value was converted incorrectly",
Short.valueOf((short) 10),
converter.convertToModel("10", Short.class, null));
}
+ @Test
public void testReverseValueConversion() {
- assertEquals(
+ Assert.assertEquals(
"Short value reversely was converted incorrectly",
reverseConverter.convertToModel((short) 10, String.class, null),
"10");
}
+ @Test
public void testExtremeShortValueConversion() {
short b = converter.convertToModel("32767", Short.class, null);
Assert.assertEquals(Short.MAX_VALUE, b);
b = converter.convertToModel("-32768", Short.class, null);
- assertEquals("Min short value was converted incorrectly",
+ Assert.assertEquals("Min short value was converted incorrectly",
Short.MIN_VALUE, b);
}
+ @Test
public void testValueOutOfRange() {
Double[] values = new Double[] { Integer.MAX_VALUE * 2.0,
Integer.MIN_VALUE * 2.0, Long.MAX_VALUE * 2.0,
} catch (ConversionException expected) {
}
}
- assertFalse("Accepted value outside range of int", accepted);
+ Assert.assertFalse("Accepted value outside range of int", accepted);
}
}
import java.math.BigDecimal;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.validator.BigDecimalRangeValidator;
-public class BigDecimalRangeValidatorTest extends TestCase {
+public class BigDecimalRangeValidatorTest {
private BigDecimalRangeValidator cleanValidator = new BigDecimalRangeValidator(
"no values", null, null);
private BigDecimalRangeValidator minMaxValidator = new BigDecimalRangeValidator(
"no values", new BigDecimal(10.5), new BigDecimal(100.5));
+ @Test
public void testNullValue() {
- assertTrue("Didn't accept null", cleanValidator.isValid(null));
- assertTrue("Didn't accept null", minValidator.isValid(null));
- assertTrue("Didn't accept null", maxValidator.isValid(null));
- assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", minValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", maxValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", minMaxValidator.isValid(null));
}
+ @Test
public void testMinValue() {
- assertTrue("Validator without ranges didn't accept value",
+ Assert.assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(new BigDecimal(-15.0)));
- assertTrue("Didn't accept valid value",
+ Assert.assertTrue("Didn't accept valid value",
minValidator.isValid(new BigDecimal(10.1)));
- assertFalse("Accepted too small value",
+ Assert.assertFalse("Accepted too small value",
minValidator.isValid(new BigDecimal(10.0)));
}
+ @Test
public void testMaxValue() {
- assertTrue("Validator without ranges didn't accept value",
+ Assert.assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(new BigDecimal(1120.0)));
- assertTrue("Didn't accept valid value",
+ Assert.assertTrue("Didn't accept valid value",
maxValidator.isValid(new BigDecimal(15.0)));
- assertFalse("Accepted too large value",
+ Assert.assertFalse("Accepted too large value",
maxValidator.isValid(new BigDecimal(100.6)));
}
+ @Test
public void testMinMaxValue() {
- assertTrue("Didn't accept valid value",
+ Assert.assertTrue("Didn't accept valid value",
minMaxValidator.isValid(new BigDecimal(10.5)));
- assertTrue("Didn't accept valid value",
+ Assert.assertTrue("Didn't accept valid value",
minMaxValidator.isValid(new BigDecimal(100.5)));
- assertFalse("Accepted too small value",
+ Assert.assertFalse("Accepted too small value",
minMaxValidator.isValid(new BigDecimal(10.4)));
- assertFalse("Accepted too large value",
+ Assert.assertFalse("Accepted too large value",
minMaxValidator.isValid(new BigDecimal(100.6)));
}
}
import java.math.BigInteger;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.validator.BigIntegerRangeValidator;
-public class BigIntegerRangeValidatorTest extends TestCase {
+public class BigIntegerRangeValidatorTest {
private BigIntegerRangeValidator cleanValidator = new BigIntegerRangeValidator(
"no values", null, null);
private BigIntegerRangeValidator minMaxValidator = new BigIntegerRangeValidator(
"no values", BigInteger.valueOf(10), BigInteger.valueOf(100));
+ @Test
public void testNullValue() {
- assertTrue("Didn't accept null", cleanValidator.isValid(null));
- assertTrue("Didn't accept null", minValidator.isValid(null));
- assertTrue("Didn't accept null", maxValidator.isValid(null));
- assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", minValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", maxValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", minMaxValidator.isValid(null));
}
+ @Test
public void testMinValue() {
- assertTrue("Validator without ranges didn't accept value",
+ Assert.assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(BigInteger.valueOf(-15)));
- assertTrue("Didn't accept valid value",
+ Assert.assertTrue("Didn't accept valid value",
minValidator.isValid(BigInteger.valueOf(15)));
- assertFalse("Accepted too small value",
+ Assert.assertFalse("Accepted too small value",
minValidator.isValid(BigInteger.valueOf(9)));
}
+ @Test
public void testMaxValue() {
- assertTrue("Validator without ranges didn't accept value",
+ Assert.assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(BigInteger.valueOf(1120)));
- assertTrue("Didn't accept valid value",
+ Assert.assertTrue("Didn't accept valid value",
maxValidator.isValid(BigInteger.valueOf(15)));
- assertFalse("Accepted too large value",
+ Assert.assertFalse("Accepted too large value",
maxValidator.isValid(BigInteger.valueOf(120)));
}
+ @Test
public void testMinMaxValue() {
- assertTrue("Didn't accept valid value",
+ Assert.assertTrue("Didn't accept valid value",
minMaxValidator.isValid(BigInteger.valueOf(15)));
- assertTrue("Didn't accept valid value",
+ Assert.assertTrue("Didn't accept valid value",
minMaxValidator.isValid(BigInteger.valueOf(99)));
- assertFalse("Accepted too small value",
+ Assert.assertFalse("Accepted too small value",
minMaxValidator.isValid(BigInteger.valueOf(9)));
- assertFalse("Accepted too large value",
+ Assert.assertFalse("Accepted too large value",
minMaxValidator.isValid(BigInteger.valueOf(110)));
}
}
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import com.vaadin.data.validator.ByteRangeValidator;
-public class ByteRangeValidatorTest extends TestCase {
+public class ByteRangeValidatorTest {
private ByteRangeValidator cleanValidator = new ByteRangeValidator(
"no values", null, null);
private ByteRangeValidator minMaxValidator = new ByteRangeValidator(
"no values", (byte) 10, (byte) 100);
+ @Test
public void testNullValue() {
assertTrue("Didn't accept null", cleanValidator.isValid(null));
assertTrue("Didn't accept null", minValidator.isValid(null));
assertTrue("Didn't accept null", minMaxValidator.isValid(null));
}
+ @Test
public void testMinValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid((byte) -15));
assertFalse("Accepted too small value", minValidator.isValid((byte) 9));
}
+ @Test
public void testMaxValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid((byte) 112));
maxValidator.isValid((byte) 120));
}
+ @Test
public void testMinMaxValue() {
assertTrue("Didn't accept valid value",
minMaxValidator.isValid((byte) 15));
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.data.Validator;
import com.vaadin.data.validator.CompositeValidator;
import com.vaadin.data.validator.EmailValidator;
import com.vaadin.data.validator.RegexpValidator;
-public class CompositeValidatorTest extends TestCase {
+public class CompositeValidatorTest {
CompositeValidator and = new CompositeValidator(CombinationMode.AND,
"One validator not valid");
RegexpValidator regex = new RegexpValidator("@mail.com", false,
"Partial match validator error");
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUp() {
and.addValidator(email);
and.addValidator(regex);
or.addValidator(regex);
}
+ @Test
public void testCorrectValue() {
String testString = "user@mail.com";
assertTrue(email.isValid(testString));
}
}
+ @Test
public void testCorrectRegex() {
String testString = "@mail.com";
}
}
+ @Test
public void testCorrectEmail() {
String testString = "user@gmail.com";
}
}
+ @Test
public void testBothFaulty() {
String testString = "gmail.com";
package com.vaadin.tests.data.validator;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.data.validator.DateRangeValidator;
import com.vaadin.shared.ui.datefield.Resolution;
-public class DateRangeValidatorTest extends TestCase {
+public class DateRangeValidatorTest {
Calendar startDate = new GregorianCalendar(TimeZone.getTimeZone("GMT"),
Locale.ENGLISH);
Calendar endDate = new GregorianCalendar(TimeZone.getTimeZone("GMT"),
private DateRangeValidator maxValidator;
private DateRangeValidator minMaxValidator;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() {
startDate.set(2000, Calendar.JANUARY, 1, 12, 0, 0);
endDate.set(2000, Calendar.FEBRUARY, 20, 12, 0, 0);
startDate.getTime(), endDate.getTime(), Resolution.DAY);
}
+ @Test
public void testNullValue() {
assertTrue("Didn't accept null", cleanValidator.isValid(null));
assertTrue("Didn't accept null", minValidator.isValid(null));
assertTrue("Didn't accept null", minMaxValidator.isValid(null));
}
+ @Test
public void testMinValue() {
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"),
Locale.ENGLISH);
minValidator.isValid(cal.getTime()));
}
+ @Test
public void testMaxValue() {
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"),
Locale.ENGLISH);
maxValidator.isValid(cal.getTime()));
}
+ @Test
public void testMinMaxValue() {
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"),
Locale.ENGLISH);
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import com.vaadin.data.validator.DoubleRangeValidator;
-public class DoubleRangeValidatorTest extends TestCase {
+public class DoubleRangeValidatorTest {
private DoubleRangeValidator cleanValidator = new DoubleRangeValidator(
"no values", null, null);
private DoubleRangeValidator minMaxValidator = new DoubleRangeValidator(
"no values", 10.5, 100.5);
+ @Test
public void testNullValue() {
assertTrue("Didn't accept null", cleanValidator.isValid(null));
assertTrue("Didn't accept null", minValidator.isValid(null));
assertTrue("Didn't accept null", minMaxValidator.isValid(null));
}
+ @Test
public void testMinValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(-15.0));
assertFalse("Accepted too small value", minValidator.isValid(10.0));
}
+ @Test
public void testMaxValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(1120.0));
assertFalse("Accepted too large value", maxValidator.isValid(100.6));
}
+ @Test
public void testMinMaxValue() {
assertTrue("Didn't accept valid value", minMaxValidator.isValid(10.5));
assertTrue("Didn't accept valid value", minMaxValidator.isValid(100.5));
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.validator.EmailValidator;
-public class EmailValidatorTest extends TestCase {
+public class EmailValidatorTest {
private EmailValidator validator = new EmailValidator("Error");
+ @Test
public void testEmailValidatorWithNull() {
- assertTrue(validator.isValid(null));
+ Assert.assertTrue(validator.isValid(null));
}
+ @Test
public void testEmailValidatorWithEmptyString() {
- assertTrue(validator.isValid(""));
+ Assert.assertTrue(validator.isValid(""));
}
+ @Test
public void testEmailValidatorWithFaultyString() {
- assertFalse(validator.isValid("not.an.email"));
+ Assert.assertFalse(validator.isValid("not.an.email"));
}
+ @Test
public void testEmailValidatorWithOkEmail() {
- assertTrue(validator.isValid("my.name@email.com"));
+ Assert.assertTrue(validator.isValid("my.name@email.com"));
}
}
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import com.vaadin.data.validator.FloatRangeValidator;
-public class FloatRangeValidatorTest extends TestCase {
+public class FloatRangeValidatorTest {
private FloatRangeValidator cleanValidator = new FloatRangeValidator(
"no values", null, null);
private FloatRangeValidator minMaxValidator = new FloatRangeValidator(
"no values", 10.5f, 100.5f);
+ @Test
public void testNullValue() {
assertTrue("Didn't accept null", cleanValidator.isValid(null));
assertTrue("Didn't accept null", minValidator.isValid(null));
assertTrue("Didn't accept null", minMaxValidator.isValid(null));
}
+ @Test
public void testMinValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(-15.0f));
assertFalse("Accepted too small value", minValidator.isValid(10.0f));
}
+ @Test
public void testMaxValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(1120.0f));
assertFalse("Accepted too large value", maxValidator.isValid(100.6f));
}
+ @Test
public void testMinMaxValue() {
assertTrue("Didn't accept valid value", minMaxValidator.isValid(10.5f));
assertTrue("Didn't accept valid value", minMaxValidator.isValid(100.5f));
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import com.vaadin.data.validator.IntegerRangeValidator;
-public class IntegerRangeValidatorTest extends TestCase {
+public class IntegerRangeValidatorTest {
private IntegerRangeValidator cleanValidator = new IntegerRangeValidator(
"no values", null, null);
private IntegerRangeValidator minMaxValidator = new IntegerRangeValidator(
"no values", 10, 100);
+ @Test
public void testNullValue() {
assertTrue("Didn't accept null", cleanValidator.isValid(null));
assertTrue("Didn't accept null", minValidator.isValid(null));
assertTrue("Didn't accept null", minMaxValidator.isValid(null));
}
+ @Test
public void testMinValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(-15));
assertFalse("Accepted too small value", minValidator.isValid(9));
}
+ @Test
public void testMaxValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(1120));
assertFalse("Accepted too large value", maxValidator.isValid(120));
}
+ @Test
public void testMinMaxValue() {
assertTrue("Didn't accept valid value", minMaxValidator.isValid(15));
assertTrue("Didn't accept valid value", minMaxValidator.isValid(99));
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import com.vaadin.data.validator.LongRangeValidator;
-public class LongRangeValidatorTest extends TestCase {
+public class LongRangeValidatorTest {
private LongRangeValidator cleanValidator = new LongRangeValidator(
"no values", null, null);
private LongRangeValidator minMaxValidator = new LongRangeValidator(
"no values", 10l, 100l);
+ @Test
public void testNullValue() {
assertTrue("Didn't accept null", cleanValidator.isValid(null));
assertTrue("Didn't accept null", minValidator.isValid(null));
assertTrue("Didn't accept null", minMaxValidator.isValid(null));
}
+ @Test
public void testMinValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(-15l));
assertFalse("Accepted too small value", minValidator.isValid(9l));
}
+ @Test
public void testMaxValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid(1120l));
assertFalse("Accepted too large value", maxValidator.isValid(120l));
}
+ @Test
public void testMinMaxValue() {
assertTrue("Didn't accept valid value", minMaxValidator.isValid(15l));
assertTrue("Didn't accept valid value", minMaxValidator.isValid(99l));
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
import com.vaadin.data.Validator;
import com.vaadin.data.validator.NullValidator;
-public class NullValidatorTest extends TestCase {
+public class NullValidatorTest {
NullValidator notNull = new NullValidator("Null not accepted", false);
NullValidator onlyNull = new NullValidator("Only null accepted", true);
+ @Test
public void testNullValue() {
try {
notNull.validate(null);
}
}
+ @Test
public void testNonNullValue() {
try {
onlyNull.validate("Not a null value");
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import com.vaadin.data.validator.RegexpValidator;
-public class RegexpValidatorTest extends TestCase {
+public class RegexpValidatorTest {
private RegexpValidator completeValidator = new RegexpValidator("pattern",
true, "Complete match validator error");
private RegexpValidator partialValidator = new RegexpValidator("pattern",
false, "Partial match validator error");
+ @Test
public void testRegexpValidatorWithNull() {
assertTrue(completeValidator.isValid(null));
assertTrue(partialValidator.isValid(null));
}
+ @Test
public void testRegexpValidatorWithEmptyString() {
assertTrue(completeValidator.isValid(""));
assertTrue(partialValidator.isValid(""));
}
+ @Test
public void testCompleteRegexpValidatorWithFaultyString() {
assertFalse(completeValidator.isValid("mismatch"));
assertFalse(completeValidator.isValid("pattern2"));
assertFalse(completeValidator.isValid("1pattern"));
}
+ @Test
public void testCompleteRegexpValidatorWithOkString() {
assertTrue(completeValidator.isValid("pattern"));
}
+ @Test
public void testPartialRegexpValidatorWithFaultyString() {
assertFalse(partialValidator.isValid("mismatch"));
}
+ @Test
public void testPartialRegexpValidatorWithOkString() {
assertTrue(partialValidator.isValid("pattern"));
assertTrue(partialValidator.isValid("1pattern"));
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import com.vaadin.data.validator.ShortRangeValidator;
-public class ShortRangeValidatorTest extends TestCase {
+public class ShortRangeValidatorTest {
private ShortRangeValidator cleanValidator = new ShortRangeValidator(
"no values", null, null);
private ShortRangeValidator minMaxValidator = new ShortRangeValidator(
"no values", (short) 10, (short) 100);
+ @Test
public void testNullValue() {
assertTrue("Didn't accept null", cleanValidator.isValid(null));
assertTrue("Didn't accept null", minValidator.isValid(null));
assertTrue("Didn't accept null", minMaxValidator.isValid(null));
}
+ @Test
public void testMinValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid((short) -15));
assertFalse("Accepted too small value", minValidator.isValid((short) 9));
}
+ @Test
public void testMaxValue() {
assertTrue("Validator without ranges didn't accept value",
cleanValidator.isValid((short) 1120));
maxValidator.isValid((short) 120));
}
+ @Test
public void testMinMaxValue() {
assertTrue("Didn't accept valid value",
minMaxValidator.isValid((short) 15));
package com.vaadin.tests.data.validator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import com.vaadin.data.validator.StringLengthValidator;
-public class StringLengthValidatorTest extends TestCase {
+public class StringLengthValidatorTest {
private StringLengthValidator validator = new StringLengthValidator("Error");
private StringLengthValidator validatorNoNull = new StringLengthValidator(
private StringLengthValidator validatorMaxValue = new StringLengthValidator(
"Error", null, 15, true);
+ @Test
public void testValidatorWithNull() {
assertTrue("Didn't accept null", validator.isValid(null));
assertTrue("Didn't accept null", validatorMinValue.isValid(null));
}
+ @Test
public void testValidatorNotAcceptingNull() {
assertFalse("Accepted null", validatorNoNull.isValid(null));
}
+ @Test
public void testEmptyString() {
assertTrue("Didn't accept empty String", validator.isValid(""));
assertTrue("Didn't accept empty String", validatorMaxValue.isValid(""));
validatorMinValue.isValid(""));
}
+ @Test
public void testTooLongString() {
assertFalse("Too long string was accepted",
validatorNoNull.isValid("This string is too long"));
validatorMaxValue.isValid("This string is too long"));
}
+ @Test
public void testNoUpperBound() {
assertTrue(
"String not accepted even though no upper bound",
.isValid("This is a really long string to test that no upper bound exists"));
}
+ @Test
public void testNoLowerBound() {
assertTrue("Didn't accept short string", validatorMaxValue.isValid(""));
assertTrue("Didn't accept short string", validatorMaxValue.isValid("1"));
}
+ @Test
public void testStringLengthValidatorWithOkStringLength() {
assertTrue("Didn't accept string of correct length",
validatorNoNull.isValid("OK!"));
validatorMaxValue.isValid("OK!"));
}
+ @Test
public void testTooShortStringLength() {
assertFalse("Accepted a string that was too short.",
validatorMinValue.isValid("shot"));
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.design;
-
-import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.declarative.Design;
-import com.vaadin.ui.declarative.DesignException;
-
-public class InvalidTagNames {
-
- @Test(expected = DesignException.class)
- public void tagWithoutDash() {
- readDesign("<vbutton>foo</vbutton>");
- }
-
- @Test
- public void emptyTag() {
- // JSoup parses empty tags into text nodes
- Component c = readDesign("<>foo</>");
- Assert.assertNull(c);
- }
-
- @Test(expected = DesignException.class)
- public void onlyPrefix() {
- readDesign("<vaadin->foo</vaadin->");
- }
-
- @Test
- public void onlyClass() {
- // JSoup will refuse to parse tags starting with - and convert them into
- // text nodes instead
- Component c = readDesign("<-v>foo</-v>");
- Assert.assertNull(c);
- }
-
- @Test(expected = DesignException.class)
- public void unknownClass() {
- readDesign("<vaadin-unknownbutton>foo</vaadin-unknownbutton>");
- }
-
- @Test(expected = DesignException.class)
- public void unknownTag() {
- readDesign("<x-button></x-button>");
- }
-
- // @Test(expected = DesignException.class)
- // This is a side effect of not actively checking for invalid input. Will be
- // parsed currently as <vaadin-button> (this should not be considered API)
- public void tagEndsInDash() {
- Component c = readDesign("<vaadin-button-></vaadin-button->");
- Assert.assertTrue(c.getClass() == Button.class);
- }
-
- // @Test(expected = DesignException.class)
- // This is a side effect of not actively checking for invalid input. Will be
- // parsed currently as <vaadin-button> (this should not be considered API)
- public void tagEndsInTwoDashes() {
- Component c = readDesign("<vaadin-button--></vaadin-button-->");
- Assert.assertTrue(c.getClass() == Button.class);
- }
-
- // @Test(expected = DesignException.class)
- // This is a side effect of not actively checking for invalid input. Will be
- // parsed currently as <vaadin-button> (this should not be considered API)
- public void tagWithTwoDashes() {
- Component c = readDesign("<vaadin--button></vaadin--button>");
- Assert.assertTrue(c.getClass() == Button.class);
- }
-
- @Test(expected = DesignException.class)
- public void specialCharacters() {
- readDesign("<vaadin-button-&!#></vaadin-button-&!#>");
- }
-
- private Component readDesign(String string) {
- try {
- return Design.read(new ByteArrayInputStream(string
- .getBytes("UTF-8")));
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
-}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.design;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.declarative.Design;
+import com.vaadin.ui.declarative.DesignException;
+
+public class InvalidTagNamesTest {
+
+ @Test(expected = DesignException.class)
+ public void tagWithoutDash() {
+ readDesign("<vbutton>foo</vbutton>");
+ }
+
+ @Test
+ public void emptyTag() {
+ // JSoup parses empty tags into text nodes
+ Component c = readDesign("<>foo</>");
+ Assert.assertNull(c);
+ }
+
+ @Test(expected = DesignException.class)
+ public void onlyPrefix() {
+ readDesign("<vaadin->foo</vaadin->");
+ }
+
+ @Test
+ public void onlyClass() {
+ // JSoup will refuse to parse tags starting with - and convert them into
+ // text nodes instead
+ Component c = readDesign("<-v>foo</-v>");
+ Assert.assertNull(c);
+ }
+
+ @Test(expected = DesignException.class)
+ public void unknownClass() {
+ readDesign("<vaadin-unknownbutton>foo</vaadin-unknownbutton>");
+ }
+
+ @Test(expected = DesignException.class)
+ public void unknownTag() {
+ readDesign("<x-button></x-button>");
+ }
+
+ // @Test(expected = DesignException.class)
+ // This is a side effect of not actively checking for invalid input. Will be
+ // parsed currently as <vaadin-button> (this should not be considered API)
+ public void tagEndsInDash() {
+ Component c = readDesign("<vaadin-button-></vaadin-button->");
+ Assert.assertTrue(c.getClass() == Button.class);
+ }
+
+ // @Test(expected = DesignException.class)
+ // This is a side effect of not actively checking for invalid input. Will be
+ // parsed currently as <vaadin-button> (this should not be considered API)
+ public void tagEndsInTwoDashes() {
+ Component c = readDesign("<vaadin-button--></vaadin-button-->");
+ Assert.assertTrue(c.getClass() == Button.class);
+ }
+
+ // @Test(expected = DesignException.class)
+ // This is a side effect of not actively checking for invalid input. Will be
+ // parsed currently as <vaadin-button> (this should not be considered API)
+ public void tagWithTwoDashes() {
+ Component c = readDesign("<vaadin--button></vaadin--button>");
+ Assert.assertTrue(c.getClass() == Button.class);
+ }
+
+ @Test(expected = DesignException.class)
+ public void specialCharacters() {
+ readDesign("<vaadin-button-&!#></vaadin-button-&!#>");
+ }
+
+ private Component readDesign(String string) {
+ try {
+ return Design.read(new ByteArrayInputStream(string
+ .getBytes("UTF-8")));
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
package com.vaadin.tests.server;
+import org.junit.Test;
+
import com.vaadin.data.Container.ItemSetChangeEvent;
import com.vaadin.data.Container.ItemSetChangeListener;
import com.vaadin.data.Container.PropertySetChangeEvent;
public class AbstractContainerListenersTest extends
AbstractListenerMethodsTestBase {
+ @Test
public void testItemSetChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(IndexedContainer.class,
ItemSetChangeEvent.class, ItemSetChangeListener.class);
}
+ @Test
public void testPropertySetChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(IndexedContainer.class,
PropertySetChangeEvent.class, PropertySetChangeListener.class);
package com.vaadin.tests.server;
+import org.junit.Test;
+
import com.vaadin.data.Property.ReadOnlyStatusChangeEvent;
import com.vaadin.data.Property.ReadOnlyStatusChangeListener;
import com.vaadin.data.Property.ValueChangeEvent;
public class AbstractPropertyListenersTest extends
AbstractListenerMethodsTestBase {
+
+ @Test
public void testValueChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(AbstractProperty.class,
ValueChangeEvent.class, ValueChangeListener.class,
new ObjectProperty<String>(""));
}
+ @Test
public void testReadOnlyStatusChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(AbstractProperty.class,
ReadOnlyStatusChangeEvent.class,
package com.vaadin.tests.server;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertTrue;
-public class AssertionsEnabledTest extends TestCase {
+import org.junit.Test;
+
+public class AssertionsEnabledTest {
+
+ @Test
public void testAssertionsEnabled() {
boolean assertFailed = false;
try {
package com.vaadin.tests.server;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
import org.atmosphere.util.Version;
+import org.junit.Test;
import com.vaadin.server.Constants;
-public class AtmosphereVersionTest extends TestCase {
+public class AtmosphereVersionTest {
+
/**
* Test that the atmosphere version constant matches the version on our
* classpath
*/
+ @Test
public void testAtmosphereVersion() {
assertEquals(Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION,
Version.getRawVersion());
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-import junit.framework.TestCase;
-
+import org.junit.Assert;
import org.junit.Test;
-public class ClassesSerializableTest extends TestCase {
+public class ClassesSerializableTest {
/**
* JARs that will be scanned for classes to test, in addition to classpath
*
* @throws Exception
*/
+ @Test
public void testClassesSerializable() throws Exception {
List<String> rawClasspathEntries = getRawClasspathEntries();
nonSerializableString += ")";
}
}
- fail("Serializable not implemented by the following classes and interfaces: "
+ Assert.fail("Serializable not implemented by the following classes and interfaces: "
+ nonSerializableString);
}
}
*/
package com.vaadin.tests.server;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.server.ClientConnector;
import com.vaadin.server.ClientMethodInvocation;
import elemental.json.JsonValue;
import elemental.json.impl.JsonUtil;
-public class ClientMethodSerializationTest extends TestCase {
+public class ClientMethodSerializationTest {
private static final Method JAVASCRIPT_CALLBACK_METHOD = ReflectTools
.findMethod(JavaScriptCallbackRpc.class, "call", String.class,
* {@link JavaScriptCallbackHelper#invokeCallback(String, Object...)}.
* #12532
*/
+ @Test
public void testClientMethodSerialization_WithJSONArray_ContentStaysSame()
throws Exception {
JsonArray originalArray = Json.createArray();
JsonUtil.stringify(copyArray));
}
+ @Test
public void testClientMethodSerialization_WithBasicParams_NoChanges()
throws Exception {
String stringParam = "a string 123";
assertEquals(copyInteger, integerParam);
}
+ @Test
public void testClientMethodSerialization_NoParams_NoExceptions() {
ClientMethodInvocation original = new ClientMethodInvocation(null,
"interfaceName", NO_PARAMS_CALL_METHOD, null);
return output;
}
+ @Test
public void testSerializeTwice() {
String name = "javascriptFunctionName";
String[] arguments = { "1", "2", "3" };
package com.vaadin.tests.server;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.ui.TextField;
-public class EventRouterTest extends TestCase {
+public class EventRouterTest {
int innerListenerCalls = 0;
+ @Test
public void testAddInEventListener() {
final TextField tf = new TextField();
package com.vaadin.tests.server;
+import static org.junit.Assert.assertEquals;
+
import java.io.File;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.util.FileTypeResolver;
-public class FileTypeResolverTest extends TestCase {
+public class FileTypeResolverTest {
private static final String FLASH_MIME_TYPE = "application/x-shockwave-flash";
private static final String TEXT_MIME_TYPE = "text/plain";
private static final String HTML_MIME_TYPE = "text/html";
+ @Test
public void testMimeTypes() {
File plainFlash = new File("MyFlash.swf");
File plainText = new File("/a/b/MyFlash.txt");
}
+ @Test
public void testExtensionCase() {
assertEquals("image/jpeg", FileTypeResolver.getMIMEType("abc.jpg"));
assertEquals("image/jpeg", FileTypeResolver.getMIMEType("abc.jPg"));
assertEquals("image/jpeg", FileTypeResolver.getMIMEType("abc.JPE"));
}
+ @Test
public void testCustomMimeType() {
assertEquals(FileTypeResolver.DEFAULT_MIME_TYPE,
FileTypeResolver.getMIMEType("vaadin.foo"));
package com.vaadin.tests.server;
+import org.junit.Test;
+
import com.vaadin.data.Container.PropertySetChangeEvent;
import com.vaadin.data.Container.PropertySetChangeListener;
import com.vaadin.data.Property.ValueChangeEvent;
public class IndexedContainerListenersTest extends
AbstractListenerMethodsTestBase {
+
+ @Test
public void testValueChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(IndexedContainer.class,
ValueChangeEvent.class, ValueChangeListener.class);
}
+ @Test
public void testPropertySetChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(IndexedContainer.class,
PropertySetChangeEvent.class, PropertySetChangeListener.class);
package com.vaadin.tests.server;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.fail;
+
import java.lang.reflect.Field;
import java.util.HashMap;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.server.KeyMapper;
-public class KeyMapperTest extends TestCase {
+public class KeyMapperTest {
+ @Test
public void testAdd() {
KeyMapper<Object> mapper = new KeyMapper<Object>();
Object o1 = new Object();
}
+ @Test
public void testRemoveAll() {
KeyMapper<Object> mapper = new KeyMapper<Object>();
Object o1 = new Object();
}
+ @Test
public void testRemove() {
KeyMapper<Object> mapper = new KeyMapper<Object>();
Object o1 = new Object();
package com.vaadin.tests.server;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
import com.vaadin.server.ClassResource;
import com.vaadin.ui.Embedded;
-public class MimeTypesTest extends TestCase {
+public class MimeTypesTest {
+ @Test
public void testEmbeddedPDF() {
Embedded e = new Embedded("A pdf", new ClassResource("file.pddf"));
assertEquals("Invalid mimetype", "application/octet-stream",
package com.vaadin.tests.server;
-import java.util.Date;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.util.Date;
import org.junit.Test;
import com.vaadin.data.util.PropertyFormatter;
@SuppressWarnings("unchecked")
-public class PropertyFormatterTest extends TestCase {
+public class PropertyFormatterTest {
class TestFormatter extends PropertyFormatter {
package com.vaadin.tests.server;
+import static org.junit.Assert.assertNotNull;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.server.VaadinSession;
import com.vaadin.ui.Form;
-public class SerializationTest extends TestCase {
+public class SerializationTest {
+ @Test
public void testValidators() throws Exception {
RegexpValidator validator = new RegexpValidator(".*", "Error");
validator.validate("aaa");
validator2.validate("aaa");
}
+ @Test
public void testForm() throws Exception {
Form f = new Form();
String propertyId = "My property";
}
+ @Test
public void testIndedexContainerItemIds() throws Exception {
IndexedContainer ic = new IndexedContainer();
ic.addContainerProperty("prop1", String.class, null);
serializeAndDeserialize(ic);
}
+ @Test
public void testMethodPropertyGetter() throws Exception {
MethodProperty<?> mp = new MethodProperty<Object>(new Data(),
"dummyGetter");
serializeAndDeserialize(mp);
}
+ @Test
public void testMethodPropertyGetterAndSetter() throws Exception {
MethodProperty<?> mp = new MethodProperty<Object>(new Data(),
"dummyGetterAndSetter");
serializeAndDeserialize(mp);
}
+ @Test
public void testMethodPropertyInt() throws Exception {
MethodProperty<?> mp = new MethodProperty<Object>(new Data(),
"dummyInt");
serializeAndDeserialize(mp);
}
+ @Test
public void testVaadinSession() throws Exception {
VaadinSession session = new VaadinSession(null);
import java.io.IOException;
import java.util.Arrays;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.server.communication.FileUploadHandler.SimpleMultiPartInputStream;
-public class SimpleMultiPartInputStreamTest extends TestCase {
+public class SimpleMultiPartInputStreamTest {
/**
* Check that the output for a given stream until boundary is as expected.
checkBoundaryDetection(input.getBytes(), boundary, expected.getBytes());
}
+ @Test
public void testSingleByteBoundaryAtEnd() throws Exception {
checkBoundaryDetection("xyz123" + getFullBoundary("a"), "a", "xyz123");
}
+ @Test
public void testSingleByteBoundaryInMiddle() throws Exception {
checkBoundaryDetection("xyz" + getFullBoundary("a") + "123", "a", "xyz");
}
+ @Test
public void testCorrectBoundaryAtEnd() throws Exception {
checkBoundaryDetection("xyz123" + getFullBoundary("abc"), "abc",
"xyz123");
}
+ @Test
public void testCorrectBoundaryNearEnd() throws Exception {
checkBoundaryDetection("xyz123" + getFullBoundary("abc") + "de", "abc",
"xyz123");
}
+ @Test
public void testCorrectBoundaryAtBeginning() throws Exception {
checkBoundaryDetection(getFullBoundary("abc") + "xyz123", "abc", "");
}
+ @Test
public void testRepeatingCharacterBoundary() throws Exception {
checkBoundaryDetection(getFullBoundary("aa") + "xyz123", "aa", "");
checkBoundaryDetection("axyz" + getFullBoundary("aa") + "123", "aa",
// + "1234567890", "\n\n", "");
// }
+ @Test
public void testRepeatingStringBoundary() throws Exception {
checkBoundaryDetection(getFullBoundary("abab") + "xyz123", "abab", "");
checkBoundaryDetection("abaxyz" + getFullBoundary("abab") + "123",
"xyz123");
}
+ @Test
public void testOverlappingBoundary() throws Exception {
checkBoundaryDetection("abc" + getFullBoundary("abcabd") + "xyz123",
"abcabd", "abc");
package com.vaadin.tests.server;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.server.LegacyCommunicationManager;
import com.vaadin.server.MockServletConfig;
import com.vaadin.ui.UI;
import com.vaadin.ui.Upload;
-public class StreamVariableMappingTest extends TestCase {
+public class StreamVariableMappingTest {
private static final String variableName = "myName";
private Upload owner;
private LegacyCommunicationManager cm;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
final VaadinSession application = new AlwaysLockedVaadinSession(null);
final UI uI = new UI() {
@Override
};
streamVariable = EasyMock.createMock(StreamVariable.class);
cm = createCommunicationManager();
-
- super.setUp();
}
+ @Test
public void testAddStreamVariable() {
owner.getUI().getConnectorTracker().registerConnector(owner);
String targetUrl = cm.getStreamVariableTargetUrl(owner, variableName,
assertSame(streamVariable, streamVariable2);
}
+ @Test
public void testRemoveVariable() {
ConnectorTracker tracker = owner.getUI().getConnectorTracker();
tracker.registerConnector(owner);
import java.util.HashSet;
import java.util.Set;
-import junit.framework.TestCase;
-
import org.easymock.EasyMock;
import org.junit.Assert;
import com.vaadin.tests.VaadinClasses;
import com.vaadin.ui.Component;
-public abstract class AbstractListenerMethodsTestBase extends TestCase {
+public abstract class AbstractListenerMethodsTestBase {
public static void main(String[] args) {
findAllListenerMethods();
SecurityException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
Collection<?> registeredListeners = getListeners(c, eventClass);
- assertEquals("Number of listeners", expectedListeners.length,
+ Assert.assertEquals("Number of listeners", expectedListeners.length,
registeredListeners.size());
Assert.assertArrayEquals(expectedListeners,
package com.vaadin.tests.server.component;
-import junit.framework.TestCase;
-
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.server.Sizeable.Unit;
import com.vaadin.shared.ui.label.LabelState;
import com.vaadin.ui.Label;
-public class ComponentSizeParseTest extends TestCase {
+public class ComponentSizeParseTest {
private final class LabelWithPublicState extends Label {
@Override
}
}
+ @Test
public void testAllTheUnit() {
testUnit("10.0px", 10, Unit.PIXELS);
testUnit("10.0pt", 10, Unit.POINTS);
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.server.component;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.vaadin.tests.VaadinClasses;
-import com.vaadin.ui.Field;
-import com.vaadin.ui.Slider;
-
-public class FieldDefaultValues {
-
- @Test
- public void testFieldsHaveDefaultValueAfterClear() throws Exception {
- for (Field<?> field : createFields()) {
- Object originalValue = field.getValue();
-
- field.clear();
-
- Object clearedValue = field.getValue();
-
- Assert.assertEquals("Expected to get default value after clearing "
- + field.getClass().getName(), originalValue, clearedValue);
- }
- }
-
- @Test
- public void testFieldsAreEmptyAfterClear() throws Exception {
- for (Field<?> field : createFields()) {
- field.clear();
-
- if (field instanceof Slider) {
- Assert.assertFalse(
- "Slider should not be empty even after being cleared",
- field.isEmpty());
-
- } else {
- Assert.assertTrue(field.getClass().getName()
- + " should be empty after being cleared",
- field.isEmpty());
- }
- }
- }
-
- @SuppressWarnings("rawtypes")
- private static List<Field<?>> createFields() throws InstantiationException,
- IllegalAccessException {
- List<Field<?>> fieldInstances = new ArrayList<Field<?>>();
-
- for (Class<? extends Field> fieldType : VaadinClasses.getFields()) {
- fieldInstances.add(fieldType.newInstance());
- }
- return fieldInstances;
- }
-
-}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.tests.VaadinClasses;
+import com.vaadin.ui.Field;
+import com.vaadin.ui.Slider;
+
+public class FieldDefaultValuesTest {
+
+ @Test
+ public void testFieldsHaveDefaultValueAfterClear() throws Exception {
+ for (Field<?> field : createFields()) {
+ Object originalValue = field.getValue();
+
+ field.clear();
+
+ Object clearedValue = field.getValue();
+
+ Assert.assertEquals("Expected to get default value after clearing "
+ + field.getClass().getName(), originalValue, clearedValue);
+ }
+ }
+
+ @Test
+ public void testFieldsAreEmptyAfterClear() throws Exception {
+ for (Field<?> field : createFields()) {
+ field.clear();
+
+ if (field instanceof Slider) {
+ Assert.assertFalse(
+ "Slider should not be empty even after being cleared",
+ field.isEmpty());
+
+ } else {
+ Assert.assertTrue(field.getClass().getName()
+ + " should be empty after being cleared",
+ field.isEmpty());
+ }
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ private static List<Field<?>> createFields() throws InstantiationException,
+ IllegalAccessException {
+ List<Field<?>> fieldInstances = new ArrayList<Field<?>>();
+
+ for (Class<? extends Field> fieldType : VaadinClasses.getFields()) {
+ fieldInstances.add(fieldType.newInstance());
+ }
+ return fieldInstances;
+ }
+
+}
import java.lang.reflect.Modifier;
import java.util.HashSet;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.tests.VaadinClasses;
import com.vaadin.ui.Component;
-public class FinalMethodTest extends TestCase {
+public class FinalMethodTest {
// public void testThatContainersHaveNoFinalMethods() {
// HashSet<Class<?>> tested = new HashSet<Class<?>>();
// }
// }
+ @Test
public void testThatComponentsHaveNoFinalMethods() {
HashSet<Class<?>> tested = new HashSet<Class<?>>();
for (Class<? extends Component> c : VaadinClasses.getComponents()) {
*/
package com.vaadin.tests.server.component;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.InputStream;
-import junit.framework.TestCase;
-
import org.jsoup.nodes.Document;
import org.jsoup.nodes.DocumentType;
import org.jsoup.nodes.Element;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.ui.Component;
import com.vaadin.ui.VerticalLayout;
* Test cases for checking that reading a design with no elements in the html
* body produces null as the root component.
*/
-public class ReadEmptyDesignTest extends TestCase {
+public class ReadEmptyDesignTest {
InputStream is;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() {
String html = createDesign().toString();
is = new ByteArrayInputStream(html.getBytes());
}
+ @Test
public void testReadComponent() {
Component root = Design.read(is);
assertNull("The root component should be null.", root);
}
+ @Test
public void testReadContext() {
DesignContext ctx = Design.read(is, null);
assertNotNull("The design context should not be null.", ctx);
assertNull("The root component should be null.", ctx.getRootComponent());
}
+ @Test
public void testReadContextWithRootParameter() {
try {
Component rootComponent = new VerticalLayout();
import java.util.Locale;
import java.util.Set;
-import junit.framework.TestCase;
-
+import org.junit.Before;
+import org.junit.Test;
import org.mockito.Mockito;
import com.vaadin.tests.VaadinClasses;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
-public class StateGetDoesNotMarkDirtyTest extends TestCase {
+public class StateGetDoesNotMarkDirtyTest {
private Set<String> excludedMethods = new HashSet<String>();
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() {
excludedMethods.add(Label.class.getName() + "getDataSourceValue");
excludedMethods.add("getConnectorId");
}
+ @Test
public void testGetDoesntMarkStateDirty() throws Exception {
for (Class<? extends Component> c : VaadinClasses.getComponents()) {
Component newInstance = construct(c);
import java.io.IOException;
import java.io.OutputStream;
-import junit.framework.TestCase;
-
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.ui.Component;
import com.vaadin.ui.declarative.Design;
* Test cases for checking that writing a component hierarchy with null root
* produces an html document that has no elements in the html body.
*/
-public class WriteEmptyDesignTest extends TestCase {
+public class WriteEmptyDesignTest {
+ @Test
public void testWriteComponent() throws IOException {
OutputStream os = new ByteArrayOutputStream();
Design.write((Component) null, os);
checkHtml(os.toString());
}
+ @Test
public void testWriteContext() throws IOException {
OutputStream os = new ByteArrayOutputStream();
DesignContext ctx = new DesignContext();
private void checkHtml(String html) {
Document doc = Jsoup.parse(html);
Element body = doc.body();
- assertEquals("There should be no elements in the html body.", "",
- body.html());
+ Assert.assertEquals("There should be no elements in the html body.",
+ "", body.html());
}
}
\ No newline at end of file
package com.vaadin.tests.server.component.absolutelayout;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
import com.vaadin.server.Sizeable;
import com.vaadin.server.Sizeable.Unit;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.Button;
-public class ComponentPositionTest extends TestCase {
+public class ComponentPositionTest {
private static final String CSS = "top:7.0px;right:7.0%;bottom:7.0pc;left:7.0em;z-index:7;";
private static final String PARTIAL_CSS = "top:7.0px;left:7.0em;";
/**
* Add component w/o giving positions, assert that everything is unset
*/
+ @Test
public void testNoPosition() {
AbsoluteLayout layout = new AbsoluteLayout();
Button b = new Button();
/**
* Add component, setting all attributes using CSS, assert getter agree
*/
+ @Test
public void testFullCss() {
AbsoluteLayout layout = new AbsoluteLayout();
Button b = new Button();
/**
* Add component, setting some attributes using CSS, assert getters agree
*/
+ @Test
public void testPartialCss() {
AbsoluteLayout layout = new AbsoluteLayout();
Button b = new Button();
* Add component setting all attributes using CSS, then reset using partial
* CSS; assert getters agree and the appropriate attributes are unset.
*/
+ @Test
public void testPartialCssReset() {
AbsoluteLayout layout = new AbsoluteLayout();
Button b = new Button();
* Add component, then set all position attributes with individual setters
* for value and units; assert getters agree.
*/
+ @Test
public void testSetPosition() {
final Float SIZE = Float.valueOf(12);
* Add component, then set all position attributes with combined setters for
* value and units; assert getters agree.
*/
+ @Test
public void testSetPosition2() {
final Float SIZE = Float.valueOf(12);
AbsoluteLayout layout = new AbsoluteLayout();
* Add component, set all attributes using CSS, unset some using method
* calls, assert getters agree.
*/
+ @Test
public void testUnsetPosition() {
AbsoluteLayout layout = new AbsoluteLayout();
Button b = new Button();
package com.vaadin.tests.server.component.abstractcomponent;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
import com.vaadin.ui.AbstractComponent;
-public class AbstractComponentStyleNamesTest extends TestCase {
+public class AbstractComponentStyleNamesTest {
+ @Test
public void testSetMultiple() {
AbstractComponent component = getComponent();
component.setStyleName("style1 style2");
assertEquals(component.getStyleName(), "style1 style2");
}
+ @Test
public void testSetAdd() {
AbstractComponent component = getComponent();
component.setStyleName("style1");
assertEquals(component.getStyleName(), "style1 style2");
}
+ @Test
public void testAddSame() {
AbstractComponent component = getComponent();
component.setStyleName("style1 style2");
assertEquals(component.getStyleName(), "style1 style2");
}
+ @Test
public void testSetRemove() {
AbstractComponent component = getComponent();
component.setStyleName("style1 style2");
assertEquals(component.getStyleName(), "style2");
}
+ @Test
public void testAddRemove() {
AbstractComponent component = getComponent();
component.addStyleName("style1");
assertEquals(component.getStyleName(), "style2");
}
+ @Test
public void testRemoveMultipleWithExtraSpaces() {
AbstractComponent component = getComponent();
component.setStyleName("style1 style2 style3");
assertEquals(component.getStyleName(), "style2");
}
+ @Test
public void testSetWithExtraSpaces() {
AbstractComponent component = getComponent();
component.setStyleName(" style1 style2 ");
package com.vaadin.tests.server.component.abstractcomponentcontainer;
+import org.junit.Test;
+
import com.vaadin.tests.server.component.AbstractListenerMethodsTestBase;
import com.vaadin.ui.HasComponents.ComponentAttachEvent;
import com.vaadin.ui.HasComponents.ComponentAttachListener;
public class AbstractComponentContainerListenersTest extends
AbstractListenerMethodsTestBase {
+
+ @Test
public void testComponentDetachListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(HorizontalLayout.class,
ComponentDetachEvent.class, ComponentDetachListener.class);
}
+ @Test
public void testComponentAttachListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(VerticalLayout.class,
ComponentAttachEvent.class, ComponentAttachListener.class);
package com.vaadin.tests.server.component.abstractfield;
-import junit.framework.TestCase;
+import static org.junit.Assert.fail;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.data.Validator.InvalidValueException;
import com.vaadin.data.util.MethodProperty;
import com.vaadin.tests.data.bean.Sex;
import com.vaadin.ui.TextField;
-public class AbsFieldValueConversionErrorTest extends TestCase {
+public class AbsFieldValueConversionErrorTest {
Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com",
34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town",
Country.FINLAND));
+ @Test
public void testValidateConversionErrorParameters() {
TextField tf = new TextField();
tf.setConverter(new StringToIntegerConverter());
}
+ @Test
public void testConvertToModelConversionErrorParameters() {
TextField tf = new TextField();
tf.setConverter(new StringToIntegerConverter());
}
+ @Test
public void testNullConversionMessages() {
TextField tf = new TextField();
tf.setConverter(new StringToIntegerConverter());
}
+ @Test
public void testDefaultConversionErrorMessage() {
TextField tf = new TextField();
tf.setConverter(new StringToIntegerConverter());
package com.vaadin.tests.server.component.abstractfield;
-import java.util.Locale;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.util.Locale;
import org.junit.Assert;
import org.junit.Test;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.TextField;
-public class AbsFieldValueConversionsTest extends TestCase {
+public class AbsFieldValueConversionsTest {
Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com",
34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town",
*/
private static final char FORMATTED_SPACE = 160;
+ @Test
public void testWithoutConversion() {
TextField tf = new TextField();
tf.setPropertyDataSource(new MethodProperty<String>(paulaBean,
assertEquals("abc", paulaBean.getFirstName());
}
+ @Test
public void testNonmodifiedBufferedFieldConversion() {
VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null));
TextField tf = new TextField("salary");
}
+ @Test
public void testModifiedBufferedFieldConversion() {
VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null));
TextField tf = new TextField("salary");
assertEquals("123,123", tf.getValue());
}
+ @Test
public void testStringIdentityConversion() {
TextField tf = new TextField();
tf.setConverter(new Converter<String, String>() {
assertEquals("abc", paulaBean.getFirstName());
}
+ @Test
public void testIntegerStringConversion() {
TextField tf = new TextField();
assertEquals("42", tf.getValue());
}
+ @Test
public void testChangeReadOnlyFieldLocale() {
VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null));
tf.getValue());
}
+ @Test
public void testBooleanNullConversion() {
CheckBox cb = new CheckBox();
cb.setConverter(new Converter<Boolean, Boolean>() {
}
+ @Test
public void testNumberDoubleConverterChange() {
final VaadinSession a = new AlwaysLockedVaadinSession(null);
VaadinSession.setCurrent(a);
package com.vaadin.tests.server.component.abstractfield;
+import org.junit.Test;
+
import com.vaadin.data.Property.ReadOnlyStatusChangeEvent;
import com.vaadin.data.Property.ReadOnlyStatusChangeListener;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.CheckBox;
public class AbstractFieldListenersTest extends AbstractListenerMethodsTestBase {
+
+ @Test
public void testReadOnlyStatusChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(CheckBox.class,
ReadOnlyStatusChangeEvent.class,
ReadOnlyStatusChangeListener.class);
}
+ @Test
public void testValueChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(CheckBox.class, ValueChangeEvent.class,
ValueChangeListener.class);
package com.vaadin.tests.server.component.abstractfield;
+import static org.junit.Assert.assertEquals;
+
import java.math.BigDecimal;
import java.util.Locale;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.data.util.MethodProperty;
import com.vaadin.server.VaadinSession;
import com.vaadin.tests.util.AlwaysLockedVaadinSession;
import com.vaadin.ui.TextField;
-public class DefaultConverterFactoryTest extends TestCase {
+public class DefaultConverterFactoryTest {
public static class FloatBean {
float f1;
paulaBean.setRent(rent);
}
+ @Test
public void testFloatConversion() {
VaadinSession sess = new AlwaysLockedVaadinSession(null);
VaadinSession.setCurrent(sess);
assertEquals(24f, tf.getPropertyDataSource().getValue());
}
+ @Test
public void testLongConversion() {
VaadinSession sess = new AlwaysLockedVaadinSession(null);
VaadinSession.setCurrent(sess);
assertEquals(1982739187239L, tf.getPropertyDataSource().getValue());
}
+ @Test
public void testDefaultNumberConversion() {
VaadinSession app = new AlwaysLockedVaadinSession(null);
VaadinSession.setCurrent(app);
package com.vaadin.tests.server.component.abstractselect;
+import org.junit.Test;
+
import com.vaadin.data.Container.ItemSetChangeEvent;
import com.vaadin.data.Container.ItemSetChangeListener;
import com.vaadin.data.Container.PropertySetChangeEvent;
public class AbstractSelectListenersTest extends
AbstractListenerMethodsTestBase {
+
+ @Test
public void testItemSetChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(ComboBox.class, ItemSetChangeEvent.class,
ItemSetChangeListener.class);
}
+ @Test
public void testPropertySetChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(ComboBox.class, PropertySetChangeEvent.class,
PropertySetChangeListener.class);
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.abstractselect;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.server.ThemeResource;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.OptionGroup;
+
+public class OptionGroupDeclarativeTest extends
+ DeclarativeTestBase<OptionGroup> {
+
+ private OptionGroup og;
+
+ @Before
+ public void init() {
+ og = new OptionGroup();
+ }
+
+ @Test
+ public void testBasicSyntax() {
+
+ String expected = "<vaadin-option-group />";
+ testReadWrite(expected);
+
+ }
+
+ @Test
+ public void testOptionSyntax() {
+
+ og.addItems("foo", "bar", "baz", "bang");
+
+ //@formatter:off
+ String expected =
+ "<vaadin-option-group>"
+ + "<option>foo</option>"
+ + "<option>bar</option>"
+ + "<option>baz</option>"
+ + "<option>bang</option>"
+ + "</vaadin-option-group>";
+ //@formatter:on
+
+ testReadWrite(expected);
+
+ }
+
+ @Test
+ public void testDisabledOptionSyntax() {
+
+ og.addItems("foo", "bar", "baz", "bang");
+ og.setItemEnabled("baz", false);
+
+ //@formatter:off
+ String expected =
+ "<vaadin-option-group>"
+ + "<option>foo</option>"
+ + "<option>bar</option>"
+ + "<option disabled>baz</option>"
+ + "<option>bang</option>"
+ + "</vaadin-option-group>";
+ //@formatter:on
+
+ testReadWrite(expected);
+
+ }
+
+ @Test
+ public void testIconSyntax() {
+
+ og.addItems("foo", "bar", "baz", "bang");
+ og.setItemIcon("bar", new ThemeResource("foobar.png"));
+
+ //@formatter:off
+ String expected =
+ "<vaadin-option-group>"
+ + "<option>foo</option>"
+ + "<option icon='theme://foobar.png'>bar</option>"
+ + "<option>baz</option>"
+ + "<option>bang</option>"
+ + "</vaadin-option-group>";
+ //@formatter:on
+
+ testReadWrite(expected);
+
+ }
+
+ @Test
+ public void testHTMLCaption() {
+
+ og.addItems("foo", "bar", "baz", "bang");
+
+ og.setHtmlContentAllowed(true);
+
+ og.setItemCaption("foo", "<b>True</b>");
+ og.setItemCaption("bar", "<font color='red'>False</font>");
+
+ //@formatter:off
+ String expected =
+ "<vaadin-option-group html-content-allowed>"
+ + "<option item-id=\"foo\"><b>True</b></option>"
+ + "<option item-id=\"bar\"><font color='red'>False</font></option>"
+ + "<option>baz</option>"
+ + "<option>bang</option>"
+ + "</vaadin-option-group>";
+ //@formatter:on
+
+ testReadWrite(expected);
+ }
+
+ @Test
+ public void testPlaintextCaption() {
+
+ og.addItems("foo", "bar", "baz", "bang");
+
+ og.setItemCaption("foo", "<b>True</b>");
+ og.setItemCaption("bar", "<font color=\"red\">False</font>");
+
+ //@formatter:off
+ String expected =
+ "<vaadin-option-group>"
+ + "<option item-id=\"foo\"><b>True</b></option>"
+ + "<option item-id=\"bar\"><font color=\"red\">False</font></option>"
+ + "<option>baz</option>"
+ + "<option>bang</option>"
+ + "</vaadin-option-group>";
+ //@formatter:on
+
+ testReadWrite(expected);
+ }
+
+ private void testReadWrite(String design) {
+ testWrite(design, og, true);
+ testRead(design, og);
+ }
+
+ @Override
+ public OptionGroup testRead(String design, OptionGroup expected) {
+
+ OptionGroup read = super.testRead(design, expected);
+ testWrite(design, read, true);
+
+ return read;
+ }
+
+}
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.server.component.abstractselect;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.vaadin.server.ThemeResource;
-import com.vaadin.tests.design.DeclarativeTestBase;
-import com.vaadin.ui.OptionGroup;
-
-public class OptionGroupDeclarativeTests extends
- DeclarativeTestBase<OptionGroup> {
-
- private OptionGroup og;
-
- @Before
- public void init() {
- og = new OptionGroup();
- }
-
- @Test
- public void testBasicSyntax() {
-
- String expected = "<vaadin-option-group />";
- testReadWrite(expected);
-
- }
-
- @Test
- public void testOptionSyntax() {
-
- og.addItems("foo", "bar", "baz", "bang");
-
- //@formatter:off
- String expected =
- "<vaadin-option-group>"
- + "<option>foo</option>"
- + "<option>bar</option>"
- + "<option>baz</option>"
- + "<option>bang</option>"
- + "</vaadin-option-group>";
- //@formatter:on
-
- testReadWrite(expected);
-
- }
-
- @Test
- public void testDisabledOptionSyntax() {
-
- og.addItems("foo", "bar", "baz", "bang");
- og.setItemEnabled("baz", false);
-
- //@formatter:off
- String expected =
- "<vaadin-option-group>"
- + "<option>foo</option>"
- + "<option>bar</option>"
- + "<option disabled>baz</option>"
- + "<option>bang</option>"
- + "</vaadin-option-group>";
- //@formatter:on
-
- testReadWrite(expected);
-
- }
-
- @Test
- public void testIconSyntax() {
-
- og.addItems("foo", "bar", "baz", "bang");
- og.setItemIcon("bar", new ThemeResource("foobar.png"));
-
- //@formatter:off
- String expected =
- "<vaadin-option-group>"
- + "<option>foo</option>"
- + "<option icon='theme://foobar.png'>bar</option>"
- + "<option>baz</option>"
- + "<option>bang</option>"
- + "</vaadin-option-group>";
- //@formatter:on
-
- testReadWrite(expected);
-
- }
-
- @Test
- public void testHTMLCaption() {
-
- og.addItems("foo", "bar", "baz", "bang");
-
- og.setHtmlContentAllowed(true);
-
- og.setItemCaption("foo", "<b>True</b>");
- og.setItemCaption("bar", "<font color='red'>False</font>");
-
- //@formatter:off
- String expected =
- "<vaadin-option-group html-content-allowed>"
- + "<option item-id=\"foo\"><b>True</b></option>"
- + "<option item-id=\"bar\"><font color='red'>False</font></option>"
- + "<option>baz</option>"
- + "<option>bang</option>"
- + "</vaadin-option-group>";
- //@formatter:on
-
- testReadWrite(expected);
- }
-
- @Test
- public void testPlaintextCaption() {
-
- og.addItems("foo", "bar", "baz", "bang");
-
- og.setItemCaption("foo", "<b>True</b>");
- og.setItemCaption("bar", "<font color=\"red\">False</font>");
-
- //@formatter:off
- String expected =
- "<vaadin-option-group>"
- + "<option item-id=\"foo\"><b>True</b></option>"
- + "<option item-id=\"bar\"><font color=\"red\">False</font></option>"
- + "<option>baz</option>"
- + "<option>bang</option>"
- + "</vaadin-option-group>";
- //@formatter:on
-
- testReadWrite(expected);
- }
-
- private void testReadWrite(String design) {
- testWrite(design, og, true);
- testRead(design, og);
- }
-
- @Override
- public OptionGroup testRead(String design, OptionGroup expected) {
-
- OptionGroup read = super.testRead(design, expected);
- testWrite(design, read, true);
-
- return read;
- }
-
-}
--- /dev/null
+package com.vaadin.tests.server.component.abstractselect;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.ui.OptionGroup;
+
+public class OptionGroupTest {
+
+ private OptionGroup optionGroup;
+
+ @Before
+ public void setup() {
+ optionGroup = new OptionGroup();
+ }
+
+ @Test
+ public void itemsAreAdded() {
+ optionGroup.addItems("foo", "bar");
+
+ Collection<?> itemIds = optionGroup.getItemIds();
+
+ assertEquals(2, itemIds.size());
+ assertTrue(itemIds.contains("foo"));
+ assertTrue(itemIds.contains("bar"));
+ }
+}
+++ /dev/null
-package com.vaadin.tests.server.component.abstractselect;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collection;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.vaadin.ui.OptionGroup;
-
-public class OptionGroupTests {
-
- private OptionGroup optionGroup;
-
- @Before
- public void setup() {
- optionGroup = new OptionGroup();
- }
-
- @Test
- public void itemsAreAdded() {
- optionGroup.addItems("foo", "bar");
-
- Collection<?> itemIds = optionGroup.getItemIds();
-
- assertEquals(2, itemIds.size());
- assertTrue(itemIds.contains("foo"));
- assertTrue(itemIds.contains("bar"));
- }
-}
package com.vaadin.tests.server.component.abstracttextfield;
+import org.junit.Test;
+
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
public class AbstractTextFieldListenersTest extends
AbstractListenerMethodsTestBase {
+
+ @Test
public void testTextChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(TextField.class, TextChangeEvent.class,
TextChangeListener.class);
}
+ @Test
public void testFocusListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(TextField.class, FocusEvent.class,
FocusListener.class);
}
+ @Test
public void testBlurListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(TextField.class, BlurEvent.class,
BlurListener.class);
package com.vaadin.tests.server.component.button;
+import org.junit.Test;
+
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.ui.Button.ClickListener;
public class ButtonListenersTest extends AbstractListenerMethodsTestBase {
+
+ @Test
public void testFocusListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Button.class, FocusEvent.class,
FocusListener.class);
}
+ @Test
public void testBlurListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Button.class, BlurEvent.class,
BlurListener.class);
}
+ @Test
public void testClickListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Button.class, ClickEvent.class,
ClickListener.class);
*/
package com.vaadin.tests.server.component.calendar;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.util.Date;
import java.util.List;
-import junit.framework.TestCase;
-
+import org.junit.Before;
import org.junit.Test;
import com.vaadin.data.Container.Indexed;
import com.vaadin.ui.components.calendar.event.BasicEvent;
import com.vaadin.ui.components.calendar.event.CalendarEvent;
-public class ContainerDataSourceTest extends TestCase {
+public class ContainerDataSourceTest {
private Calendar calendar;
- @Override
+ @Before
public void setUp() {
calendar = new Calendar();
}
import java.util.Date;
import java.util.Locale;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.data.Property;
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.ui.DateField;
-public class DateFieldConverterTest extends TestCase {
+public class DateFieldConverterTest {
private Property<Long> date;
private DateField datefield;
- @Override
+ @Before
public void setUp() {
date = new ObjectProperty<Long>(0L);
datefield = new DateField();
/*
* See #12193.
*/
+ @Test
public void testResolution() {
datefield.setValue(new Date(110, 0, 1));
datefield.setResolution(Resolution.MINUTE);
package com.vaadin.tests.server.component.datefield;
+import org.junit.Test;
+
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.ui.DateField;
public class DateFieldListenersTest extends AbstractListenerMethodsTestBase {
+
+ @Test
public void testFocusListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(DateField.class, FocusEvent.class,
FocusListener.class);
}
+ @Test
public void testBlurListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(DateField.class, BlurEvent.class,
BlurListener.class);
import java.util.ArrayList;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.tests.util.TestUtil;
-public class ResolutionTest extends TestCase {
+public class ResolutionTest {
+ @Test
public void testResolutionHigherOrEqualToYear() {
Iterable<Resolution> higherOrEqual = Resolution
.getResolutionsHigherOrEqualTo(Resolution.YEAR);
TestUtil.assertIterableEquals(expected, higherOrEqual);
}
+ @Test
public void testResolutionHigherOrEqualToDay() {
Iterable<Resolution> higherOrEqual = Resolution
.getResolutionsHigherOrEqualTo(Resolution.DAY);
}
+ @Test
public void testResolutionLowerThanDay() {
Iterable<Resolution> higherOrEqual = Resolution
.getResolutionsLowerThan(Resolution.DAY);
}
+ @Test
public void testResolutionLowerThanSecond() {
Iterable<Resolution> higherOrEqual = Resolution
.getResolutionsLowerThan(Resolution.SECOND);
TestUtil.assertIterableEquals(expected, higherOrEqual);
}
+ @Test
public void testResolutionLowerThanYear() {
Iterable<Resolution> higherOrEqual = Resolution
.getResolutionsLowerThan(Resolution.YEAR);
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.server.component.grid;
-
-import java.util.Iterator;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.vaadin.ui.Component;
-import com.vaadin.ui.Grid;
-import com.vaadin.ui.Grid.FooterCell;
-import com.vaadin.ui.Grid.HeaderCell;
-import com.vaadin.ui.Label;
-
-public class GridChildren {
-
- @Test
- public void componentsInMergedHeader() {
- Grid grid = new Grid();
- grid.addColumn("foo");
- grid.addColumn("bar");
- grid.addColumn("baz");
- HeaderCell merged = grid.getDefaultHeaderRow()
- .join("foo", "bar", "baz");
- Label label = new Label();
- merged.setComponent(label);
- Iterator<Component> i = grid.iterator();
- Assert.assertEquals(label, i.next());
- Assert.assertFalse(i.hasNext());
- }
-
- @Test
- public void componentsInMergedFooter() {
- Grid grid = new Grid();
- grid.addColumn("foo");
- grid.addColumn("bar");
- grid.addColumn("baz");
- FooterCell merged = grid.addFooterRowAt(0).join("foo", "bar", "baz");
- Label label = new Label();
- merged.setComponent(label);
- Iterator<Component> i = grid.iterator();
- Assert.assertEquals(label, i.next());
- Assert.assertFalse(i.hasNext());
- }
-}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.grid;
+
+import java.util.Iterator;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.FooterCell;
+import com.vaadin.ui.Grid.HeaderCell;
+import com.vaadin.ui.Label;
+
+public class GridChildrenTest {
+
+ @Test
+ public void componentsInMergedHeader() {
+ Grid grid = new Grid();
+ grid.addColumn("foo");
+ grid.addColumn("bar");
+ grid.addColumn("baz");
+ HeaderCell merged = grid.getDefaultHeaderRow()
+ .join("foo", "bar", "baz");
+ Label label = new Label();
+ merged.setComponent(label);
+ Iterator<Component> i = grid.iterator();
+ Assert.assertEquals(label, i.next());
+ Assert.assertFalse(i.hasNext());
+ }
+
+ @Test
+ public void componentsInMergedFooter() {
+ Grid grid = new Grid();
+ grid.addColumn("foo");
+ grid.addColumn("bar");
+ grid.addColumn("baz");
+ FooterCell merged = grid.addFooterRowAt(0).join("foo", "bar", "baz");
+ Label label = new Label();
+ merged.setComponent(label);
+ Iterator<Component> i = grid.iterator();
+ Assert.assertEquals(label, i.next());
+ Assert.assertFalse(i.hasNext());
+ }
+}
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.server.component.grid;
-
-import static org.easymock.EasyMock.and;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.isA;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import org.easymock.Capture;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.vaadin.data.util.IndexedContainer;
-import com.vaadin.server.KeyMapper;
-import com.vaadin.shared.ui.grid.GridColumnState;
-import com.vaadin.shared.ui.grid.GridState;
-import com.vaadin.shared.util.SharedUtil;
-import com.vaadin.ui.Grid;
-import com.vaadin.ui.Grid.Column;
-import com.vaadin.ui.Grid.ColumnResizeEvent;
-import com.vaadin.ui.Grid.ColumnResizeListener;
-import com.vaadin.ui.TextField;
-
-public class GridColumns {
-
- private Grid grid;
-
- private GridState state;
-
- private Method getStateMethod;
-
- private Field columnIdGeneratorField;
-
- private KeyMapper<Object> columnIdMapper;
-
- @Before
- @SuppressWarnings("unchecked")
- public void setup() throws Exception {
- IndexedContainer ds = new IndexedContainer();
- for (int c = 0; c < 10; c++) {
- ds.addContainerProperty("column" + c, String.class, "");
- }
- ds.addContainerProperty("noSort", Object.class, null);
- grid = new Grid(ds);
-
- getStateMethod = Grid.class.getDeclaredMethod("getState");
- getStateMethod.setAccessible(true);
-
- state = (GridState) getStateMethod.invoke(grid);
-
- columnIdGeneratorField = Grid.class.getDeclaredField("columnKeys");
- columnIdGeneratorField.setAccessible(true);
-
- columnIdMapper = (KeyMapper<Object>) columnIdGeneratorField.get(grid);
- }
-
- @Test
- public void testColumnGeneration() throws Exception {
-
- for (Object propertyId : grid.getContainerDataSource()
- .getContainerPropertyIds()) {
-
- // All property ids should get a column
- Column column = grid.getColumn(propertyId);
- assertNotNull(column);
-
- // Humanized property id should be the column header by default
- assertEquals(
- SharedUtil.camelCaseToHumanFriendly(propertyId.toString()),
- grid.getDefaultHeaderRow().getCell(propertyId).getText());
- }
- }
-
- @Test
- public void testModifyingColumnProperties() throws Exception {
-
- // Modify first column
- Column column = grid.getColumn("column1");
- assertNotNull(column);
-
- column.setHeaderCaption("CustomHeader");
- assertEquals("CustomHeader", column.getHeaderCaption());
- assertEquals(column.getHeaderCaption(), grid.getDefaultHeaderRow()
- .getCell("column1").getText());
-
- column.setWidth(100);
- assertEquals(100, column.getWidth(), 0.49d);
- assertEquals(column.getWidth(), getColumnState("column1").width, 0.49d);
-
- try {
- column.setWidth(-1);
- fail("Setting width to -1 should throw exception");
- } catch (IllegalArgumentException iae) {
- // expected
- }
-
- assertEquals(100, column.getWidth(), 0.49d);
- assertEquals(100, getColumnState("column1").width, 0.49d);
- }
-
- @Test
- public void testRemovingColumnByRemovingPropertyFromContainer()
- throws Exception {
-
- Column column = grid.getColumn("column1");
- assertNotNull(column);
-
- // Remove column
- grid.getContainerDataSource().removeContainerProperty("column1");
-
- try {
- column.setHeaderCaption("asd");
-
- fail("Succeeded in modifying a detached column");
- } catch (IllegalStateException ise) {
- // Detached state should throw exception
- }
-
- try {
- column.setWidth(123);
- fail("Succeeded in modifying a detached column");
- } catch (IllegalStateException ise) {
- // Detached state should throw exception
- }
-
- assertNull(grid.getColumn("column1"));
- assertNull(getColumnState("column1"));
- }
-
- @Test
- public void testAddingColumnByAddingPropertyToContainer() throws Exception {
- grid.getContainerDataSource().addContainerProperty("columnX",
- String.class, "");
- Column column = grid.getColumn("columnX");
- assertNotNull(column);
- }
-
- @Test
- public void testHeaderVisiblility() throws Exception {
-
- assertTrue(grid.isHeaderVisible());
- assertTrue(state.header.visible);
-
- grid.setHeaderVisible(false);
- assertFalse(grid.isHeaderVisible());
- assertFalse(state.header.visible);
-
- grid.setHeaderVisible(true);
- assertTrue(grid.isHeaderVisible());
- assertTrue(state.header.visible);
- }
-
- @Test
- public void testFooterVisibility() throws Exception {
-
- assertTrue(grid.isFooterVisible());
- assertTrue(state.footer.visible);
-
- grid.setFooterVisible(false);
- assertFalse(grid.isFooterVisible());
- assertFalse(state.footer.visible);
-
- grid.setFooterVisible(true);
- assertTrue(grid.isFooterVisible());
- assertTrue(state.footer.visible);
- }
-
- @Test
- public void testSetFrozenColumnCount() {
- assertEquals("Grid should not start with a frozen column", 0,
- grid.getFrozenColumnCount());
- grid.setFrozenColumnCount(2);
- assertEquals("Freezing two columns should freeze two columns", 2,
- grid.getFrozenColumnCount());
- }
-
- @Test
- public void testSetFrozenColumnCountThroughColumn() {
- assertEquals("Grid should not start with a frozen column", 0,
- grid.getFrozenColumnCount());
- grid.getColumns().get(2).setLastFrozenColumn();
- assertEquals(
- "Setting the third column as last frozen should freeze three columns",
- 3, grid.getFrozenColumnCount());
- }
-
- @Test
- public void testFrozenColumnRemoveColumn() {
- assertEquals("Grid should not start with a frozen column", 0,
- grid.getFrozenColumnCount());
-
- int containerSize = grid.getContainerDataSource()
- .getContainerPropertyIds().size();
- grid.setFrozenColumnCount(containerSize);
-
- Object propertyId = grid.getContainerDataSource()
- .getContainerPropertyIds().iterator().next();
-
- grid.getContainerDataSource().removeContainerProperty(propertyId);
- assertEquals(
- "Frozen column count should update when removing last row",
- containerSize - 1, grid.getFrozenColumnCount());
- }
-
- @Test
- public void testReorderColumns() {
- Set<?> containerProperties = new LinkedHashSet<Object>(grid
- .getContainerDataSource().getContainerPropertyIds());
- Object[] properties = new Object[] { "column3", "column2", "column6" };
- grid.setColumnOrder(properties);
-
- int i = 0;
- // Test sorted columns are first in order
- for (Object property : properties) {
- containerProperties.remove(property);
- assertEquals(columnIdMapper.key(property),
- state.columnOrder.get(i++));
- }
-
- // Test remaining columns are in original order
- for (Object property : containerProperties) {
- assertEquals(columnIdMapper.key(property),
- state.columnOrder.get(i++));
- }
-
- try {
- grid.setColumnOrder("foo", "bar", "baz");
- fail("Grid allowed sorting with non-existent properties");
- } catch (IllegalArgumentException e) {
- // All ok
- }
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testRemoveColumnThatDoesNotExist() {
- grid.removeColumn("banana phone");
- }
-
- @Test(expected = IllegalStateException.class)
- public void testSetNonSortableColumnSortable() {
- Column noSortColumn = grid.getColumn("noSort");
- assertFalse("Object property column should not be sortable.",
- noSortColumn.isSortable());
- noSortColumn.setSortable(true);
- }
-
- @Test
- public void testColumnsEditableByDefault() {
- for (Column c : grid.getColumns()) {
- assertTrue(c + " should be editable", c.isEditable());
- }
- }
-
- @Test
- public void testPropertyAndColumnEditorFieldsMatch() {
- Column column1 = grid.getColumn("column1");
- column1.setEditorField(new TextField());
- assertSame(column1.getEditorField(), grid.getColumn("column1")
- .getEditorField());
-
- Column column2 = grid.getColumn("column2");
- column2.setEditorField(new TextField());
- assertSame(column2.getEditorField(), column2.getEditorField());
- }
-
- @Test
- public void testUneditableColumnHasNoField() {
- Column col = grid.getColumn("column1");
-
- col.setEditable(false);
-
- assertFalse("Column should be uneditable", col.isEditable());
- assertNull("Uneditable column should not be auto-assigned a Field",
- col.getEditorField());
- }
-
- private GridColumnState getColumnState(Object propertyId) {
- String columnId = columnIdMapper.key(propertyId);
- for (GridColumnState columnState : state.columns) {
- if (columnState.id.equals(columnId)) {
- return columnState;
- }
- }
- return null;
- }
-
- @Test
- public void testAddAndRemoveSortableColumn() {
- boolean sortable = grid.getColumn("column1").isSortable();
- grid.removeColumn("column1");
- grid.addColumn("column1");
- assertEquals("Column sortability changed when re-adding", sortable,
- grid.getColumn("column1").isSortable());
- }
-
- @Test
- public void testSetColumns() {
- grid.setColumns("column7", "column0", "column9");
- Iterator<Column> it = grid.getColumns().iterator();
- assertEquals(it.next().getPropertyId(), "column7");
- assertEquals(it.next().getPropertyId(), "column0");
- assertEquals(it.next().getPropertyId(), "column9");
- assertFalse(it.hasNext());
- }
-
- @Test
- public void testAddingColumnsWithSetColumns() {
- Grid g = new Grid();
- g.setColumns("c1", "c2", "c3");
- Iterator<Column> it = g.getColumns().iterator();
- assertEquals(it.next().getPropertyId(), "c1");
- assertEquals(it.next().getPropertyId(), "c2");
- assertEquals(it.next().getPropertyId(), "c3");
- assertFalse(it.hasNext());
- }
-
- @Test(expected = IllegalStateException.class)
- public void testAddingColumnsWithSetColumnsNonDefaultContainer() {
- grid.setColumns("column1", "column2", "column50");
- }
-
- @Test
- public void testDefaultColumnHidingToggleCaption() {
- Column firstColumn = grid.getColumns().get(0);
- firstColumn.setHeaderCaption("headerCaption");
- assertEquals(null, firstColumn.getHidingToggleCaption());
- }
-
- @Test
- public void testOverriddenColumnHidingToggleCaption() {
- Column firstColumn = grid.getColumns().get(0);
- firstColumn.setHidingToggleCaption("hidingToggleCaption");
- firstColumn.setHeaderCaption("headerCaption");
- assertEquals("hidingToggleCaption",
- firstColumn.getHidingToggleCaption());
- }
-
- @Test
- public void testColumnSetWidthFiresResizeEvent() {
- final Column firstColumn = grid.getColumns().get(0);
-
- // prepare a listener mock that captures the argument
- ColumnResizeListener mock = EasyMock
- .createMock(ColumnResizeListener.class);
- Capture<ColumnResizeEvent> capturedEvent = new Capture<ColumnResizeEvent>();
- mock.columnResize(and(capture(capturedEvent),
- isA(ColumnResizeEvent.class)));
- EasyMock.expectLastCall().once();
-
- // Tell it to wait for the call
- EasyMock.replay(mock);
-
- // Cause a resize event
- grid.addColumnResizeListener(mock);
- firstColumn.setWidth(firstColumn.getWidth() + 10);
-
- // Verify the method was called
- EasyMock.verify(mock);
-
- // Asserts on the captured event
- ColumnResizeEvent event = capturedEvent.getValue();
- assertEquals("Event column was not first column.", firstColumn,
- event.getColumn());
- assertFalse("Event should not be userOriginated",
- event.isUserOriginated());
- }
-
- @Test
- public void textHeaderCaptionIsReturned() {
- Column firstColumn = grid.getColumns().get(0);
-
- firstColumn.setHeaderCaption("text");
-
- assertThat(firstColumn.getHeaderCaption(), is("text"));
- }
-
- @Test
- public void defaultCaptionIsReturnedForHtml() {
- Column firstColumn = grid.getColumns().get(0);
-
- grid.getDefaultHeaderRow().getCell("column0").setHtml("<b>html</b>");
-
- assertThat(firstColumn.getHeaderCaption(), is("Column0"));
- }
-}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.grid;
+
+import static org.easymock.EasyMock.and;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.isA;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.server.KeyMapper;
+import com.vaadin.shared.ui.grid.GridColumnState;
+import com.vaadin.shared.ui.grid.GridState;
+import com.vaadin.shared.util.SharedUtil;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.Column;
+import com.vaadin.ui.Grid.ColumnResizeEvent;
+import com.vaadin.ui.Grid.ColumnResizeListener;
+import com.vaadin.ui.TextField;
+
+public class GridColumnsTest {
+
+ private Grid grid;
+
+ private GridState state;
+
+ private Method getStateMethod;
+
+ private Field columnIdGeneratorField;
+
+ private KeyMapper<Object> columnIdMapper;
+
+ @Before
+ @SuppressWarnings("unchecked")
+ public void setup() throws Exception {
+ IndexedContainer ds = new IndexedContainer();
+ for (int c = 0; c < 10; c++) {
+ ds.addContainerProperty("column" + c, String.class, "");
+ }
+ ds.addContainerProperty("noSort", Object.class, null);
+ grid = new Grid(ds);
+
+ getStateMethod = Grid.class.getDeclaredMethod("getState");
+ getStateMethod.setAccessible(true);
+
+ state = (GridState) getStateMethod.invoke(grid);
+
+ columnIdGeneratorField = Grid.class.getDeclaredField("columnKeys");
+ columnIdGeneratorField.setAccessible(true);
+
+ columnIdMapper = (KeyMapper<Object>) columnIdGeneratorField.get(grid);
+ }
+
+ @Test
+ public void testColumnGeneration() throws Exception {
+
+ for (Object propertyId : grid.getContainerDataSource()
+ .getContainerPropertyIds()) {
+
+ // All property ids should get a column
+ Column column = grid.getColumn(propertyId);
+ assertNotNull(column);
+
+ // Humanized property id should be the column header by default
+ assertEquals(
+ SharedUtil.camelCaseToHumanFriendly(propertyId.toString()),
+ grid.getDefaultHeaderRow().getCell(propertyId).getText());
+ }
+ }
+
+ @Test
+ public void testModifyingColumnProperties() throws Exception {
+
+ // Modify first column
+ Column column = grid.getColumn("column1");
+ assertNotNull(column);
+
+ column.setHeaderCaption("CustomHeader");
+ assertEquals("CustomHeader", column.getHeaderCaption());
+ assertEquals(column.getHeaderCaption(), grid.getDefaultHeaderRow()
+ .getCell("column1").getText());
+
+ column.setWidth(100);
+ assertEquals(100, column.getWidth(), 0.49d);
+ assertEquals(column.getWidth(), getColumnState("column1").width, 0.49d);
+
+ try {
+ column.setWidth(-1);
+ fail("Setting width to -1 should throw exception");
+ } catch (IllegalArgumentException iae) {
+ // expected
+ }
+
+ assertEquals(100, column.getWidth(), 0.49d);
+ assertEquals(100, getColumnState("column1").width, 0.49d);
+ }
+
+ @Test
+ public void testRemovingColumnByRemovingPropertyFromContainer()
+ throws Exception {
+
+ Column column = grid.getColumn("column1");
+ assertNotNull(column);
+
+ // Remove column
+ grid.getContainerDataSource().removeContainerProperty("column1");
+
+ try {
+ column.setHeaderCaption("asd");
+
+ fail("Succeeded in modifying a detached column");
+ } catch (IllegalStateException ise) {
+ // Detached state should throw exception
+ }
+
+ try {
+ column.setWidth(123);
+ fail("Succeeded in modifying a detached column");
+ } catch (IllegalStateException ise) {
+ // Detached state should throw exception
+ }
+
+ assertNull(grid.getColumn("column1"));
+ assertNull(getColumnState("column1"));
+ }
+
+ @Test
+ public void testAddingColumnByAddingPropertyToContainer() throws Exception {
+ grid.getContainerDataSource().addContainerProperty("columnX",
+ String.class, "");
+ Column column = grid.getColumn("columnX");
+ assertNotNull(column);
+ }
+
+ @Test
+ public void testHeaderVisiblility() throws Exception {
+
+ assertTrue(grid.isHeaderVisible());
+ assertTrue(state.header.visible);
+
+ grid.setHeaderVisible(false);
+ assertFalse(grid.isHeaderVisible());
+ assertFalse(state.header.visible);
+
+ grid.setHeaderVisible(true);
+ assertTrue(grid.isHeaderVisible());
+ assertTrue(state.header.visible);
+ }
+
+ @Test
+ public void testFooterVisibility() throws Exception {
+
+ assertTrue(grid.isFooterVisible());
+ assertTrue(state.footer.visible);
+
+ grid.setFooterVisible(false);
+ assertFalse(grid.isFooterVisible());
+ assertFalse(state.footer.visible);
+
+ grid.setFooterVisible(true);
+ assertTrue(grid.isFooterVisible());
+ assertTrue(state.footer.visible);
+ }
+
+ @Test
+ public void testSetFrozenColumnCount() {
+ assertEquals("Grid should not start with a frozen column", 0,
+ grid.getFrozenColumnCount());
+ grid.setFrozenColumnCount(2);
+ assertEquals("Freezing two columns should freeze two columns", 2,
+ grid.getFrozenColumnCount());
+ }
+
+ @Test
+ public void testSetFrozenColumnCountThroughColumn() {
+ assertEquals("Grid should not start with a frozen column", 0,
+ grid.getFrozenColumnCount());
+ grid.getColumns().get(2).setLastFrozenColumn();
+ assertEquals(
+ "Setting the third column as last frozen should freeze three columns",
+ 3, grid.getFrozenColumnCount());
+ }
+
+ @Test
+ public void testFrozenColumnRemoveColumn() {
+ assertEquals("Grid should not start with a frozen column", 0,
+ grid.getFrozenColumnCount());
+
+ int containerSize = grid.getContainerDataSource()
+ .getContainerPropertyIds().size();
+ grid.setFrozenColumnCount(containerSize);
+
+ Object propertyId = grid.getContainerDataSource()
+ .getContainerPropertyIds().iterator().next();
+
+ grid.getContainerDataSource().removeContainerProperty(propertyId);
+ assertEquals(
+ "Frozen column count should update when removing last row",
+ containerSize - 1, grid.getFrozenColumnCount());
+ }
+
+ @Test
+ public void testReorderColumns() {
+ Set<?> containerProperties = new LinkedHashSet<Object>(grid
+ .getContainerDataSource().getContainerPropertyIds());
+ Object[] properties = new Object[] { "column3", "column2", "column6" };
+ grid.setColumnOrder(properties);
+
+ int i = 0;
+ // Test sorted columns are first in order
+ for (Object property : properties) {
+ containerProperties.remove(property);
+ assertEquals(columnIdMapper.key(property),
+ state.columnOrder.get(i++));
+ }
+
+ // Test remaining columns are in original order
+ for (Object property : containerProperties) {
+ assertEquals(columnIdMapper.key(property),
+ state.columnOrder.get(i++));
+ }
+
+ try {
+ grid.setColumnOrder("foo", "bar", "baz");
+ fail("Grid allowed sorting with non-existent properties");
+ } catch (IllegalArgumentException e) {
+ // All ok
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testRemoveColumnThatDoesNotExist() {
+ grid.removeColumn("banana phone");
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testSetNonSortableColumnSortable() {
+ Column noSortColumn = grid.getColumn("noSort");
+ assertFalse("Object property column should not be sortable.",
+ noSortColumn.isSortable());
+ noSortColumn.setSortable(true);
+ }
+
+ @Test
+ public void testColumnsEditableByDefault() {
+ for (Column c : grid.getColumns()) {
+ assertTrue(c + " should be editable", c.isEditable());
+ }
+ }
+
+ @Test
+ public void testPropertyAndColumnEditorFieldsMatch() {
+ Column column1 = grid.getColumn("column1");
+ column1.setEditorField(new TextField());
+ assertSame(column1.getEditorField(), grid.getColumn("column1")
+ .getEditorField());
+
+ Column column2 = grid.getColumn("column2");
+ column2.setEditorField(new TextField());
+ assertSame(column2.getEditorField(), column2.getEditorField());
+ }
+
+ @Test
+ public void testUneditableColumnHasNoField() {
+ Column col = grid.getColumn("column1");
+
+ col.setEditable(false);
+
+ assertFalse("Column should be uneditable", col.isEditable());
+ assertNull("Uneditable column should not be auto-assigned a Field",
+ col.getEditorField());
+ }
+
+ private GridColumnState getColumnState(Object propertyId) {
+ String columnId = columnIdMapper.key(propertyId);
+ for (GridColumnState columnState : state.columns) {
+ if (columnState.id.equals(columnId)) {
+ return columnState;
+ }
+ }
+ return null;
+ }
+
+ @Test
+ public void testAddAndRemoveSortableColumn() {
+ boolean sortable = grid.getColumn("column1").isSortable();
+ grid.removeColumn("column1");
+ grid.addColumn("column1");
+ assertEquals("Column sortability changed when re-adding", sortable,
+ grid.getColumn("column1").isSortable());
+ }
+
+ @Test
+ public void testSetColumns() {
+ grid.setColumns("column7", "column0", "column9");
+ Iterator<Column> it = grid.getColumns().iterator();
+ assertEquals(it.next().getPropertyId(), "column7");
+ assertEquals(it.next().getPropertyId(), "column0");
+ assertEquals(it.next().getPropertyId(), "column9");
+ assertFalse(it.hasNext());
+ }
+
+ @Test
+ public void testAddingColumnsWithSetColumns() {
+ Grid g = new Grid();
+ g.setColumns("c1", "c2", "c3");
+ Iterator<Column> it = g.getColumns().iterator();
+ assertEquals(it.next().getPropertyId(), "c1");
+ assertEquals(it.next().getPropertyId(), "c2");
+ assertEquals(it.next().getPropertyId(), "c3");
+ assertFalse(it.hasNext());
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testAddingColumnsWithSetColumnsNonDefaultContainer() {
+ grid.setColumns("column1", "column2", "column50");
+ }
+
+ @Test
+ public void testDefaultColumnHidingToggleCaption() {
+ Column firstColumn = grid.getColumns().get(0);
+ firstColumn.setHeaderCaption("headerCaption");
+ assertEquals(null, firstColumn.getHidingToggleCaption());
+ }
+
+ @Test
+ public void testOverriddenColumnHidingToggleCaption() {
+ Column firstColumn = grid.getColumns().get(0);
+ firstColumn.setHidingToggleCaption("hidingToggleCaption");
+ firstColumn.setHeaderCaption("headerCaption");
+ assertEquals("hidingToggleCaption",
+ firstColumn.getHidingToggleCaption());
+ }
+
+ @Test
+ public void testColumnSetWidthFiresResizeEvent() {
+ final Column firstColumn = grid.getColumns().get(0);
+
+ // prepare a listener mock that captures the argument
+ ColumnResizeListener mock = EasyMock
+ .createMock(ColumnResizeListener.class);
+ Capture<ColumnResizeEvent> capturedEvent = new Capture<ColumnResizeEvent>();
+ mock.columnResize(and(capture(capturedEvent),
+ isA(ColumnResizeEvent.class)));
+ EasyMock.expectLastCall().once();
+
+ // Tell it to wait for the call
+ EasyMock.replay(mock);
+
+ // Cause a resize event
+ grid.addColumnResizeListener(mock);
+ firstColumn.setWidth(firstColumn.getWidth() + 10);
+
+ // Verify the method was called
+ EasyMock.verify(mock);
+
+ // Asserts on the captured event
+ ColumnResizeEvent event = capturedEvent.getValue();
+ assertEquals("Event column was not first column.", firstColumn,
+ event.getColumn());
+ assertFalse("Event should not be userOriginated",
+ event.isUserOriginated());
+ }
+
+ @Test
+ public void textHeaderCaptionIsReturned() {
+ Column firstColumn = grid.getColumns().get(0);
+
+ firstColumn.setHeaderCaption("text");
+
+ assertThat(firstColumn.getHeaderCaption(), is("text"));
+ }
+
+ @Test
+ public void defaultCaptionIsReturnedForHtml() {
+ Column firstColumn = grid.getColumns().get(0);
+
+ grid.getDefaultHeaderRow().getCell("column0").setHtml("<b>html</b>");
+
+ assertThat(firstColumn.getHeaderCaption(), is("Column0"));
+ }
+}
+++ /dev/null
-/*
- * Copyright 2000-2013 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.server.component.grid;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collection;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.vaadin.data.util.IndexedContainer;
-import com.vaadin.event.SelectionEvent;
-import com.vaadin.event.SelectionEvent.SelectionListener;
-import com.vaadin.ui.Grid;
-import com.vaadin.ui.Grid.SelectionMode;
-import com.vaadin.ui.Grid.SelectionModel;
-
-public class GridSelection {
-
- private static class MockSelectionChangeListener implements
- SelectionListener {
- private SelectionEvent event;
-
- @Override
- public void select(final SelectionEvent event) {
- this.event = event;
- }
-
- public Collection<?> getAdded() {
- return event.getAdded();
- }
-
- public Collection<?> getRemoved() {
- return event.getRemoved();
- }
-
- public void clearEvent() {
- /*
- * This method is not strictly needed as the event will simply be
- * overridden, but it's good practice, and makes the code more
- * obvious.
- */
- event = null;
- }
-
- public boolean eventHasHappened() {
- return event != null;
- }
- }
-
- private Grid grid;
- private MockSelectionChangeListener mockListener;
-
- private final Object itemId1Present = "itemId1Present";
- private final Object itemId2Present = "itemId2Present";
-
- private final Object itemId1NotPresent = "itemId1NotPresent";
- private final Object itemId2NotPresent = "itemId2NotPresent";
-
- @Before
- public void setup() {
- final IndexedContainer container = new IndexedContainer();
- container.addItem(itemId1Present);
- container.addItem(itemId2Present);
- for (int i = 2; i < 10; i++) {
- container.addItem(new Object());
- }
-
- assertEquals("init size", 10, container.size());
- assertTrue("itemId1Present", container.containsId(itemId1Present));
- assertTrue("itemId2Present", container.containsId(itemId2Present));
- assertFalse("itemId1NotPresent",
- container.containsId(itemId1NotPresent));
- assertFalse("itemId2NotPresent",
- container.containsId(itemId2NotPresent));
-
- grid = new Grid(container);
-
- mockListener = new MockSelectionChangeListener();
- grid.addSelectionListener(mockListener);
-
- assertFalse("eventHasHappened", mockListener.eventHasHappened());
- }
-
- @Test
- public void defaultSelectionModeIsSingle() {
- assertTrue(grid.getSelectionModel() instanceof SelectionModel.Single);
- }
-
- @Test(expected = IllegalStateException.class)
- public void getSelectedRowThrowsExceptionMulti() {
- grid.setSelectionMode(SelectionMode.MULTI);
- grid.getSelectedRow();
- }
-
- @Test(expected = IllegalStateException.class)
- public void getSelectedRowThrowsExceptionNone() {
- grid.setSelectionMode(SelectionMode.NONE);
- grid.getSelectedRow();
- }
-
- @Test(expected = IllegalStateException.class)
- public void selectThrowsExceptionNone() {
- grid.setSelectionMode(SelectionMode.NONE);
- grid.select(itemId1Present);
- }
-
- @Test(expected = IllegalStateException.class)
- public void deselectRowThrowsExceptionNone() {
- grid.setSelectionMode(SelectionMode.NONE);
- grid.deselect(itemId1Present);
- }
-
- @Test
- public void selectionModeMapsToMulti() {
- assertTrue(grid.setSelectionMode(SelectionMode.MULTI) instanceof SelectionModel.Multi);
- }
-
- @Test
- public void selectionModeMapsToSingle() {
- assertTrue(grid.setSelectionMode(SelectionMode.SINGLE) instanceof SelectionModel.Single);
- }
-
- @Test
- public void selectionModeMapsToNone() {
- assertTrue(grid.setSelectionMode(SelectionMode.NONE) instanceof SelectionModel.None);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void selectionModeNullThrowsException() {
- grid.setSelectionMode(null);
- }
-
- @Test
- public void noSelectModel_isSelected() {
- grid.setSelectionMode(SelectionMode.NONE);
- assertFalse("itemId1Present", grid.isSelected(itemId1Present));
- assertFalse("itemId1NotPresent", grid.isSelected(itemId1NotPresent));
- }
-
- @Test(expected = IllegalStateException.class)
- public void noSelectModel_getSelectedRow() {
- grid.setSelectionMode(SelectionMode.NONE);
- grid.getSelectedRow();
- }
-
- @Test
- public void noSelectModel_getSelectedRows() {
- grid.setSelectionMode(SelectionMode.NONE);
- assertTrue(grid.getSelectedRows().isEmpty());
- }
-
- @Test
- public void selectionCallsListenerMulti() {
- grid.setSelectionMode(SelectionMode.MULTI);
- selectionCallsListener();
- }
-
- @Test
- public void selectionCallsListenerSingle() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- selectionCallsListener();
- }
-
- private void selectionCallsListener() {
- grid.select(itemId1Present);
- assertEquals("added size", 1, mockListener.getAdded().size());
- assertEquals("added item", itemId1Present, mockListener.getAdded()
- .iterator().next());
- assertEquals("removed size", 0, mockListener.getRemoved().size());
- }
-
- @Test
- public void deselectionCallsListenerMulti() {
- grid.setSelectionMode(SelectionMode.MULTI);
- deselectionCallsListener();
- }
-
- @Test
- public void deselectionCallsListenerSingle() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- deselectionCallsListener();
- }
-
- private void deselectionCallsListener() {
- grid.select(itemId1Present);
- mockListener.clearEvent();
-
- grid.deselect(itemId1Present);
- assertEquals("removed size", 1, mockListener.getRemoved().size());
- assertEquals("removed item", itemId1Present, mockListener.getRemoved()
- .iterator().next());
- assertEquals("removed size", 0, mockListener.getAdded().size());
- }
-
- @Test
- public void deselectPresentButNotSelectedItemIdShouldntFireListenerMulti() {
- grid.setSelectionMode(SelectionMode.MULTI);
- deselectPresentButNotSelectedItemIdShouldntFireListener();
- }
-
- @Test
- public void deselectPresentButNotSelectedItemIdShouldntFireListenerSingle() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- deselectPresentButNotSelectedItemIdShouldntFireListener();
- }
-
- private void deselectPresentButNotSelectedItemIdShouldntFireListener() {
- grid.deselect(itemId1Present);
- assertFalse(mockListener.eventHasHappened());
- }
-
- @Test
- public void deselectNotPresentItemIdShouldNotThrowExceptionMulti() {
- grid.setSelectionMode(SelectionMode.MULTI);
- grid.deselect(itemId1NotPresent);
- }
-
- @Test
- public void deselectNotPresentItemIdShouldNotThrowExceptionSingle() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- grid.deselect(itemId1NotPresent);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void selectNotPresentItemIdShouldThrowExceptionMulti() {
- grid.setSelectionMode(SelectionMode.MULTI);
- grid.select(itemId1NotPresent);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void selectNotPresentItemIdShouldThrowExceptionSingle() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- grid.select(itemId1NotPresent);
- }
-
- @Test
- public void selectAllMulti() {
- grid.setSelectionMode(SelectionMode.MULTI);
- final SelectionModel.Multi select = (SelectionModel.Multi) grid
- .getSelectionModel();
- select.selectAll();
- assertEquals("added size", 10, mockListener.getAdded().size());
- assertEquals("removed size", 0, mockListener.getRemoved().size());
- assertTrue("itemId1Present",
- mockListener.getAdded().contains(itemId1Present));
- assertTrue("itemId2Present",
- mockListener.getAdded().contains(itemId2Present));
- }
-
- @Test
- public void deselectAllMulti() {
- grid.setSelectionMode(SelectionMode.MULTI);
- final SelectionModel.Multi select = (SelectionModel.Multi) grid
- .getSelectionModel();
- select.selectAll();
- mockListener.clearEvent();
-
- select.deselectAll();
- assertEquals("removed size", 10, mockListener.getRemoved().size());
- assertEquals("added size", 0, mockListener.getAdded().size());
- assertTrue("itemId1Present",
- mockListener.getRemoved().contains(itemId1Present));
- assertTrue("itemId2Present",
- mockListener.getRemoved().contains(itemId2Present));
- assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
- }
-
- @Test
- public void gridDeselectAllMultiAllSelected() {
- grid.setSelectionMode(SelectionMode.MULTI);
- final SelectionModel.Multi select = (SelectionModel.Multi) grid
- .getSelectionModel();
- select.selectAll();
- mockListener.clearEvent();
-
- assertTrue(grid.deselectAll());
- assertEquals("removed size", 10, mockListener.getRemoved().size());
- assertEquals("added size", 0, mockListener.getAdded().size());
- assertTrue("itemId1Present",
- mockListener.getRemoved().contains(itemId1Present));
- assertTrue("itemId2Present",
- mockListener.getRemoved().contains(itemId2Present));
- assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
-
- }
-
- @Test
- public void gridDeselectAllMultiOneSelected() {
- grid.setSelectionMode(SelectionMode.MULTI);
- final SelectionModel.Multi select = (SelectionModel.Multi) grid
- .getSelectionModel();
- select.select(itemId2Present);
- mockListener.clearEvent();
-
- assertTrue(grid.deselectAll());
- assertEquals("removed size", 1, mockListener.getRemoved().size());
- assertEquals("added size", 0, mockListener.getAdded().size());
- assertFalse("itemId1Present",
- mockListener.getRemoved().contains(itemId1Present));
- assertTrue("itemId2Present",
- mockListener.getRemoved().contains(itemId2Present));
- assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
-
- }
-
- @Test
- public void gridDeselectAllSingleNoneSelected() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- assertFalse(grid.deselectAll());
- assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
- }
-
- @Test
- public void gridDeselectAllSingleOneSelected() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- final SelectionModel.Single select = (SelectionModel.Single) grid
- .getSelectionModel();
- select.select(itemId2Present);
- mockListener.clearEvent();
-
- assertTrue(grid.deselectAll());
- assertEquals("removed size", 1, mockListener.getRemoved().size());
- assertEquals("added size", 0, mockListener.getAdded().size());
- assertFalse("itemId1Present",
- mockListener.getRemoved().contains(itemId1Present));
- assertTrue("itemId2Present",
- mockListener.getRemoved().contains(itemId2Present));
- assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
-
- }
-
- @Test
- public void gridDeselectAllMultiNoneSelected() {
- grid.setSelectionMode(SelectionMode.MULTI);
-
- assertFalse(grid.deselectAll());
- assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
-
- }
-
- @Test
- public void reselectionDeselectsPreviousSingle() {
- grid.setSelectionMode(SelectionMode.SINGLE);
- grid.select(itemId1Present);
- mockListener.clearEvent();
-
- grid.select(itemId2Present);
- assertEquals("added size", 1, mockListener.getAdded().size());
- assertEquals("removed size", 1, mockListener.getRemoved().size());
- assertEquals("added item", itemId2Present, mockListener.getAdded()
- .iterator().next());
- assertEquals("removed item", itemId1Present, mockListener.getRemoved()
- .iterator().next());
- assertEquals("selectedRows is correct", itemId2Present,
- grid.getSelectedRow());
- }
-}
--- /dev/null
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.grid;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.event.SelectionEvent;
+import com.vaadin.event.SelectionEvent.SelectionListener;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.SelectionMode;
+import com.vaadin.ui.Grid.SelectionModel;
+
+public class GridSelectionTest {
+
+ private static class MockSelectionChangeListener implements
+ SelectionListener {
+ private SelectionEvent event;
+
+ @Override
+ public void select(final SelectionEvent event) {
+ this.event = event;
+ }
+
+ public Collection<?> getAdded() {
+ return event.getAdded();
+ }
+
+ public Collection<?> getRemoved() {
+ return event.getRemoved();
+ }
+
+ public void clearEvent() {
+ /*
+ * This method is not strictly needed as the event will simply be
+ * overridden, but it's good practice, and makes the code more
+ * obvious.
+ */
+ event = null;
+ }
+
+ public boolean eventHasHappened() {
+ return event != null;
+ }
+ }
+
+ private Grid grid;
+ private MockSelectionChangeListener mockListener;
+
+ private final Object itemId1Present = "itemId1Present";
+ private final Object itemId2Present = "itemId2Present";
+
+ private final Object itemId1NotPresent = "itemId1NotPresent";
+ private final Object itemId2NotPresent = "itemId2NotPresent";
+
+ @Before
+ public void setup() {
+ final IndexedContainer container = new IndexedContainer();
+ container.addItem(itemId1Present);
+ container.addItem(itemId2Present);
+ for (int i = 2; i < 10; i++) {
+ container.addItem(new Object());
+ }
+
+ assertEquals("init size", 10, container.size());
+ assertTrue("itemId1Present", container.containsId(itemId1Present));
+ assertTrue("itemId2Present", container.containsId(itemId2Present));
+ assertFalse("itemId1NotPresent",
+ container.containsId(itemId1NotPresent));
+ assertFalse("itemId2NotPresent",
+ container.containsId(itemId2NotPresent));
+
+ grid = new Grid(container);
+
+ mockListener = new MockSelectionChangeListener();
+ grid.addSelectionListener(mockListener);
+
+ assertFalse("eventHasHappened", mockListener.eventHasHappened());
+ }
+
+ @Test
+ public void defaultSelectionModeIsSingle() {
+ assertTrue(grid.getSelectionModel() instanceof SelectionModel.Single);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void getSelectedRowThrowsExceptionMulti() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ grid.getSelectedRow();
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void getSelectedRowThrowsExceptionNone() {
+ grid.setSelectionMode(SelectionMode.NONE);
+ grid.getSelectedRow();
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void selectThrowsExceptionNone() {
+ grid.setSelectionMode(SelectionMode.NONE);
+ grid.select(itemId1Present);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void deselectRowThrowsExceptionNone() {
+ grid.setSelectionMode(SelectionMode.NONE);
+ grid.deselect(itemId1Present);
+ }
+
+ @Test
+ public void selectionModeMapsToMulti() {
+ assertTrue(grid.setSelectionMode(SelectionMode.MULTI) instanceof SelectionModel.Multi);
+ }
+
+ @Test
+ public void selectionModeMapsToSingle() {
+ assertTrue(grid.setSelectionMode(SelectionMode.SINGLE) instanceof SelectionModel.Single);
+ }
+
+ @Test
+ public void selectionModeMapsToNone() {
+ assertTrue(grid.setSelectionMode(SelectionMode.NONE) instanceof SelectionModel.None);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void selectionModeNullThrowsException() {
+ grid.setSelectionMode(null);
+ }
+
+ @Test
+ public void noSelectModel_isSelected() {
+ grid.setSelectionMode(SelectionMode.NONE);
+ assertFalse("itemId1Present", grid.isSelected(itemId1Present));
+ assertFalse("itemId1NotPresent", grid.isSelected(itemId1NotPresent));
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void noSelectModel_getSelectedRow() {
+ grid.setSelectionMode(SelectionMode.NONE);
+ grid.getSelectedRow();
+ }
+
+ @Test
+ public void noSelectModel_getSelectedRows() {
+ grid.setSelectionMode(SelectionMode.NONE);
+ assertTrue(grid.getSelectedRows().isEmpty());
+ }
+
+ @Test
+ public void selectionCallsListenerMulti() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ selectionCallsListener();
+ }
+
+ @Test
+ public void selectionCallsListenerSingle() {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ selectionCallsListener();
+ }
+
+ private void selectionCallsListener() {
+ grid.select(itemId1Present);
+ assertEquals("added size", 1, mockListener.getAdded().size());
+ assertEquals("added item", itemId1Present, mockListener.getAdded()
+ .iterator().next());
+ assertEquals("removed size", 0, mockListener.getRemoved().size());
+ }
+
+ @Test
+ public void deselectionCallsListenerMulti() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ deselectionCallsListener();
+ }
+
+ @Test
+ public void deselectionCallsListenerSingle() {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ deselectionCallsListener();
+ }
+
+ private void deselectionCallsListener() {
+ grid.select(itemId1Present);
+ mockListener.clearEvent();
+
+ grid.deselect(itemId1Present);
+ assertEquals("removed size", 1, mockListener.getRemoved().size());
+ assertEquals("removed item", itemId1Present, mockListener.getRemoved()
+ .iterator().next());
+ assertEquals("removed size", 0, mockListener.getAdded().size());
+ }
+
+ @Test
+ public void deselectPresentButNotSelectedItemIdShouldntFireListenerMulti() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ deselectPresentButNotSelectedItemIdShouldntFireListener();
+ }
+
+ @Test
+ public void deselectPresentButNotSelectedItemIdShouldntFireListenerSingle() {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ deselectPresentButNotSelectedItemIdShouldntFireListener();
+ }
+
+ private void deselectPresentButNotSelectedItemIdShouldntFireListener() {
+ grid.deselect(itemId1Present);
+ assertFalse(mockListener.eventHasHappened());
+ }
+
+ @Test
+ public void deselectNotPresentItemIdShouldNotThrowExceptionMulti() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ grid.deselect(itemId1NotPresent);
+ }
+
+ @Test
+ public void deselectNotPresentItemIdShouldNotThrowExceptionSingle() {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ grid.deselect(itemId1NotPresent);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void selectNotPresentItemIdShouldThrowExceptionMulti() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ grid.select(itemId1NotPresent);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void selectNotPresentItemIdShouldThrowExceptionSingle() {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ grid.select(itemId1NotPresent);
+ }
+
+ @Test
+ public void selectAllMulti() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ final SelectionModel.Multi select = (SelectionModel.Multi) grid
+ .getSelectionModel();
+ select.selectAll();
+ assertEquals("added size", 10, mockListener.getAdded().size());
+ assertEquals("removed size", 0, mockListener.getRemoved().size());
+ assertTrue("itemId1Present",
+ mockListener.getAdded().contains(itemId1Present));
+ assertTrue("itemId2Present",
+ mockListener.getAdded().contains(itemId2Present));
+ }
+
+ @Test
+ public void deselectAllMulti() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ final SelectionModel.Multi select = (SelectionModel.Multi) grid
+ .getSelectionModel();
+ select.selectAll();
+ mockListener.clearEvent();
+
+ select.deselectAll();
+ assertEquals("removed size", 10, mockListener.getRemoved().size());
+ assertEquals("added size", 0, mockListener.getAdded().size());
+ assertTrue("itemId1Present",
+ mockListener.getRemoved().contains(itemId1Present));
+ assertTrue("itemId2Present",
+ mockListener.getRemoved().contains(itemId2Present));
+ assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
+ }
+
+ @Test
+ public void gridDeselectAllMultiAllSelected() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ final SelectionModel.Multi select = (SelectionModel.Multi) grid
+ .getSelectionModel();
+ select.selectAll();
+ mockListener.clearEvent();
+
+ assertTrue(grid.deselectAll());
+ assertEquals("removed size", 10, mockListener.getRemoved().size());
+ assertEquals("added size", 0, mockListener.getAdded().size());
+ assertTrue("itemId1Present",
+ mockListener.getRemoved().contains(itemId1Present));
+ assertTrue("itemId2Present",
+ mockListener.getRemoved().contains(itemId2Present));
+ assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
+
+ }
+
+ @Test
+ public void gridDeselectAllMultiOneSelected() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+ final SelectionModel.Multi select = (SelectionModel.Multi) grid
+ .getSelectionModel();
+ select.select(itemId2Present);
+ mockListener.clearEvent();
+
+ assertTrue(grid.deselectAll());
+ assertEquals("removed size", 1, mockListener.getRemoved().size());
+ assertEquals("added size", 0, mockListener.getAdded().size());
+ assertFalse("itemId1Present",
+ mockListener.getRemoved().contains(itemId1Present));
+ assertTrue("itemId2Present",
+ mockListener.getRemoved().contains(itemId2Present));
+ assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
+
+ }
+
+ @Test
+ public void gridDeselectAllSingleNoneSelected() {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ assertFalse(grid.deselectAll());
+ assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
+ }
+
+ @Test
+ public void gridDeselectAllSingleOneSelected() {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ final SelectionModel.Single select = (SelectionModel.Single) grid
+ .getSelectionModel();
+ select.select(itemId2Present);
+ mockListener.clearEvent();
+
+ assertTrue(grid.deselectAll());
+ assertEquals("removed size", 1, mockListener.getRemoved().size());
+ assertEquals("added size", 0, mockListener.getAdded().size());
+ assertFalse("itemId1Present",
+ mockListener.getRemoved().contains(itemId1Present));
+ assertTrue("itemId2Present",
+ mockListener.getRemoved().contains(itemId2Present));
+ assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
+
+ }
+
+ @Test
+ public void gridDeselectAllMultiNoneSelected() {
+ grid.setSelectionMode(SelectionMode.MULTI);
+
+ assertFalse(grid.deselectAll());
+ assertTrue("selectedRows is empty", grid.getSelectedRows().isEmpty());
+
+ }
+
+ @Test
+ public void reselectionDeselectsPreviousSingle() {
+ grid.setSelectionMode(SelectionMode.SINGLE);
+ grid.select(itemId1Present);
+ mockListener.clearEvent();
+
+ grid.select(itemId2Present);
+ assertEquals("added size", 1, mockListener.getAdded().size());
+ assertEquals("removed size", 1, mockListener.getRemoved().size());
+ assertEquals("added item", itemId2Present, mockListener.getAdded()
+ .iterator().next());
+ assertEquals("removed item", itemId1Present, mockListener.getRemoved()
+ .iterator().next());
+ assertEquals("selectedRows is correct", itemId2Present,
+ grid.getSelectedRow());
+ }
+}
import static org.easymock.EasyMock.verify;
import org.easymock.EasyMock;
+import org.junit.Test;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.ui.Label.ValueChangeEvent;
public class LabelListenersTest extends AbstractListenerMethodsTestBase {
+
+ @Test
public void testValueChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Label.class, ValueChangeEvent.class,
ValueChangeListener.class);
}
+ @Test
public void testValueChangeFiredWhenSettingValue() {
Label underTest = new Label();
}
+ @Test
public void testValueChangeFiredWhenSettingPropertyDataSource() {
// setup
Label underTest = new Label();
}
+ @Test
public void testValueChangeNotFiredWhenNotSettingValue() {
Label underTest = new Label();
// setup the mock listener
verify(mockListener);
}
+ @Test
public void testNoValueChangeFiredWhenSettingPropertyDataSourceToNull() {
Label underTest = new Label();
// setup the mock Listener
import java.util.HashSet;
import java.util.Set;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.Command;
import com.vaadin.ui.MenuBar.MenuItem;
-public class MenuBarIdsTest extends TestCase implements Command {
+public class MenuBarIdsTest implements Command {
private MenuItem lastSelectedItem;
private MenuItem menuFile;
private MenuBar menuBar;
- @Override
+ @Before
public void setUp() {
menuBar = new MenuBar();
menuFile = menuBar.addItem("File", this);
menuItems.add(menuFileExit);
}
+ @Test
public void testMenubarIdUniqueness() {
// Ids within a menubar must be unique
assertUniqueIds(menuBar);
private static void assertUniqueIds(Set<Object> ids, MenuItem item) {
int id = item.getId();
System.out.println("Item " + item.getText() + ", id: " + id);
- assertFalse(ids.contains(id));
+ Assert.assertFalse(ids.contains(id));
ids.add(id);
if (item.getChildren() != null) {
for (MenuItem subItem : item.getChildren()) {
@Override
public void menuSelected(MenuItem selectedItem) {
- assertNull("lastSelectedItem was not cleared before selecting an item",
+ Assert.assertNull(
+ "lastSelectedItem was not cleared before selecting an item",
lastSelectedItem);
lastSelectedItem = selectedItem;
package com.vaadin.tests.server.component.optiongroup;
+import org.junit.Test;
+
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.ui.OptionGroup;
public class OptionGroupListenersTest extends AbstractListenerMethodsTestBase {
+
+ @Test
public void testFocusListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(OptionGroup.class, FocusEvent.class,
FocusListener.class);
}
+ @Test
public void testBlurListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(OptionGroup.class, BlurEvent.class,
BlurListener.class);
import java.util.Iterator;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
-public class OrderedLayoutTest extends TestCase {
+public class OrderedLayoutTest {
+ @Test
public void testVLIteration() {
testIndexing(new VerticalLayout(), 10);
}
+ @Test
public void testHLIteration() {
testIndexing(new HorizontalLayout(), 12);
}
package com.vaadin.tests.server.component.select;
+import org.junit.Test;
+
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.ui.Select;
public class SelectListenersTest extends AbstractListenerMethodsTestBase {
+
+ @Test
public void testFocusListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Select.class, FocusEvent.class,
FocusListener.class);
}
+ @Test
public void testBlurListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Select.class, BlurEvent.class,
BlurListener.class);
package com.vaadin.tests.server.component.table;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
* Test case for testing the footer API
*
*/
-public class FooterTest extends TestCase {
+public class FooterTest {
/**
* Tests if setting the footer visibility works properly
*/
+ @Test
public void testFooterVisibility() {
Table table = new Table("Test table", createContainer());
/**
* Tests adding footers to the columns
*/
+ @Test
public void testAddingFooters() {
Table table = new Table("Test table", createContainer());
/**
* Test removing footers
*/
+ @Test
public void testRemovingFooters() {
Table table = new Table("Test table", createContainer());
table.setColumnFooter("col1", "Footer1");
package com.vaadin.tests.server.component.table;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.util.Arrays;
import java.util.Set;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.data.Container;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.shared.ui.MultiSelectMode;
import com.vaadin.ui.Table;
-public class MultipleSelectionTest extends TestCase {
+public class MultipleSelectionTest {
/**
* Tests weather the multiple select mode is set when using Table.set
*/
+ @Test
@SuppressWarnings("unchecked")
public void testSetMultipleItems() {
Table table = new Table("", createTestContainer());
* Tests setting the multiselect mode of the Table. The multiselect mode
* affects how mouse selection is made in the table by the user.
*/
+ @Test
public void testSetMultiSelectMode() {
Table table = new Table("", createTestContainer());
package com.vaadin.tests.server.component.table;
+import org.junit.Test;
+
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.tests.server.component.AbstractListenerMethodsTestBase;
import com.vaadin.ui.Table.HeaderClickListener;
public class TableListenersTest extends AbstractListenerMethodsTestBase {
+
+ @Test
public void testColumnResizeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Table.class, ColumnResizeEvent.class,
ColumnResizeListener.class);
}
+ @Test
public void testItemClickListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Table.class, ItemClickEvent.class,
ItemClickListener.class);
}
+ @Test
public void testFooterClickListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Table.class, FooterClickEvent.class,
FooterClickListener.class);
}
+ @Test
public void testHeaderClickListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Table.class, HeaderClickEvent.class,
HeaderClickListener.class);
}
+ @Test
public void testColumnReorderListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Table.class, ColumnReorderEvent.class,
ColumnReorderListener.class);
*/
package com.vaadin.tests.server.component.table;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
-import junit.framework.TestCase;
-
+import org.junit.Before;
import org.junit.Test;
import com.vaadin.data.Container;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.ui.Table;
-/**
- *
- * @since
- * @author Vaadin Ltd
- */
-public class TablePropertyValueConverterTest extends TestCase {
+public class TablePropertyValueConverterTest {
protected TestableTable table;
protected Collection<?> initialProperties;
DerivedClass.class.isAssignableFrom(BaseClass.class));
}
- @Override
+ @Before
public void setUp() {
table = new TestableTable("Test table", createContainer(new String[] {
"col1", "col2", "col3" }));
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.server.component.table;
-
-import org.easymock.EasyMock;
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.vaadin.data.Property.ValueChangeListener;
-import com.vaadin.ui.Table;
-
-/**
- * Tests for 'selectable' property of {@link Table} class.
- *
- * @author Vaadin Ltd
- */
-public class TableSelectable {
-
- @Test
- public void setSelectable_explicitSelectable_tableIsSelectable() {
- Table table = new Table();
- table.setSelectable(true);
-
- Assert.assertTrue(table.isSelectable());
- }
-
- @Test
- public void addValueChangeListener_explicitSelectable_tableIsSelectable() {
- TestTable table = new TestTable();
- table.addValueChangeListener(EasyMock
- .createMock(ValueChangeListener.class));
-
- Assert.assertTrue(table.isSelectable());
- Assert.assertTrue(table.markAsDirtyCalled);
- }
-
- @Test
- public void tableIsNotSelectableByDefult() {
- Table table = new Table();
-
- Assert.assertFalse(table.isSelectable());
- }
-
- @Test
- public void setSelectable_explicitNotSelectable_tableIsNotSelectable() {
- Table table = new Table();
- table.setSelectable(false);
- table.addValueChangeListener(EasyMock
- .createMock(ValueChangeListener.class));
-
- Assert.assertFalse(table.isSelectable());
- }
-
- private static final class TestTable extends Table {
- @Override
- public void markAsDirty() {
- markAsDirtyCalled = true;
- }
-
- private boolean markAsDirtyCalled;
- }
-}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.table;
+
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.ui.Table;
+
+/**
+ * Tests for 'selectable' property of {@link Table} class.
+ *
+ * @author Vaadin Ltd
+ */
+public class TableSelectableTest {
+
+ @Test
+ public void setSelectable_explicitSelectable_tableIsSelectable() {
+ Table table = new Table();
+ table.setSelectable(true);
+
+ Assert.assertTrue(table.isSelectable());
+ }
+
+ @Test
+ public void addValueChangeListener_explicitSelectable_tableIsSelectable() {
+ TestTable table = new TestTable();
+ table.addValueChangeListener(EasyMock
+ .createMock(ValueChangeListener.class));
+
+ Assert.assertTrue(table.isSelectable());
+ Assert.assertTrue(table.markAsDirtyCalled);
+ }
+
+ @Test
+ public void tableIsNotSelectableByDefult() {
+ Table table = new Table();
+
+ Assert.assertFalse(table.isSelectable());
+ }
+
+ @Test
+ public void setSelectable_explicitNotSelectable_tableIsNotSelectable() {
+ Table table = new Table();
+ table.setSelectable(false);
+ table.addValueChangeListener(EasyMock
+ .createMock(ValueChangeListener.class));
+
+ Assert.assertFalse(table.isSelectable());
+ }
+
+ private static final class TestTable extends Table {
+ @Override
+ public void markAsDirty() {
+ markAsDirtyCalled = true;
+ }
+
+ private boolean markAsDirtyCalled;
+ }
+}
package com.vaadin.tests.server.component.table;
-import junit.framework.TestCase;
-
import org.apache.commons.lang.SerializationUtils;
+import org.junit.Test;
import com.vaadin.ui.Table;
-public class TableSerializationTest extends TestCase {
+public class TableSerializationTest {
+ @Test
public void testSerialization() {
Table t = new Table();
byte[] ser = SerializationUtils.serialize(t);
}
+ @Test
public void testSerializationWithRowHeaders() {
Table t = new Table();
t.setRowHeaderMode(Table.ROW_HEADER_MODE_EXPLICIT);
package com.vaadin.tests.server.component.textfield;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.data.validator.RangeValidator;
import com.vaadin.tests.data.converter.ConverterFactoryTest.ConvertTo42;
import com.vaadin.ui.TextField;
-public class TextFieldWithConverterAndValidatorTest extends TestCase {
+public class TextFieldWithConverterAndValidatorTest {
private TextField field;
private ObjectProperty<Integer> property;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUp() {
field = new TextField();
field.setInvalidAllowed(false);
}
+ @Test
public void testConvert42AndValidator() {
property = new ObjectProperty<Integer>(123);
field.setConverter(new ConvertTo42());
package com.vaadin.tests.server.component.textfield;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.util.Collections;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.PropertyFormatter;
import com.vaadin.ui.TextField;
-public class TextFieldWithPropertyFormatterTest extends TestCase {
+public class TextFieldWithPropertyFormatterTest {
private static final String INPUT_VALUE = "foo";
private static final String PARSED_VALUE = "BAR";
private int listenerCalled;
private int repainted;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() {
field = new TextField() {
@Override
repainted = 0;
}
+ @Test
public void testWithServerApi() {
checkInitialState();
assertEquals(FORMATTED_VALUE, field.getValue());
}
+ @Test
public void testWithSimulatedClientSideChange() {
checkInitialState();
package com.vaadin.tests.server.component.textfield;
-import junit.framework.TestCase;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.data.Validator;
import com.vaadin.data.Validator.InvalidValueException;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.ui.TextField;
-public class TextFieldWithValidatorTest extends TestCase {
+public class TextFieldWithValidatorTest {
private TextField field;
private ObjectProperty<String> property;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() {
field = new TextField();
field.setInvalidAllowed(false);
field.setPropertyDataSource(property);
}
+ @Test
public void testMultipleValidators() {
field.addValidator(new StringLengthValidator(
"Length not between 1 and 3", 1, 3, false));
}
}
+ @Test
public void testRemoveValidator() {
Validator validator1 = new StringLengthValidator(
"Length not between 1 and 3", 1, 3, false);
field.setValue("abcd");
}
+ @Test
public void testRemoveAllValidators() {
Validator validator1 = new StringLengthValidator(
"Length not between 1 and 3", 1, 3, false);
field.setValue("abcd");
}
+ @Test
public void testEmailValidator() {
field.addValidator(new EmailValidator("Invalid e-mail address"));
}
}
+ @Test
public void testRegexpValidator() {
field.addValidator(new RegexpValidator("pattern", true,
"Validation failed"));
package com.vaadin.tests.server.component.tree;
+import static org.junit.Assert.assertEquals;
+
import java.util.ArrayList;
import java.util.List;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.ui.Tree;
import com.vaadin.ui.Tree.CollapseEvent;
import com.vaadin.ui.Tree.ExpandEvent;
import com.vaadin.ui.Tree.ExpandListener;
-public class ListenersTest extends TestCase implements ExpandListener,
- CollapseListener {
+public class ListenersTest implements ExpandListener, CollapseListener {
private int expandCalled;
private int collapseCalled;
private Object lastExpanded;
private Object lastCollapsed;
- @Override
- protected void setUp() {
+ @Before
+ public void setUp() {
expandCalled = 0;
}
+ @Test
public void testExpandListener() {
Tree tree = createTree(10, 20, false);
tree.addListener((ExpandListener) this);
return tree;
}
+ @Test
public void testCollapseListener() {
Tree tree = createTree(7, 15, true);
tree.addListener((CollapseListener) this);
package com.vaadin.tests.server.component.tree;
+import org.junit.Test;
+
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.tests.server.component.AbstractListenerMethodsTestBase;
import com.vaadin.ui.Tree.ExpandListener;
public class TreeListenersTest extends AbstractListenerMethodsTestBase {
+
+ @Test
public void testExpandListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Tree.class, ExpandEvent.class,
ExpandListener.class);
}
+ @Test
public void testItemClickListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Tree.class, ItemClickEvent.class,
ItemClickListener.class);
}
+ @Test
public void testCollapseListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Tree.class, CollapseEvent.class,
CollapseListener.class);
package com.vaadin.tests.server.component.treetable;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
import com.vaadin.ui.TreeTable;
-public class EmptyTreeTableTest extends TestCase {
+public class EmptyTreeTableTest {
+
+ @Test
public void testLastId() {
TreeTable treeTable = new TreeTable();
package com.vaadin.tests.server.component.treetable;
-import junit.framework.TestCase;
+import org.junit.Test;
import com.vaadin.ui.TreeTable;
-public class TreeTableSetContainerNullTest extends TestCase {
+public class TreeTableSetContainerNullTest {
+ @Test
public void testNullContainer() {
TreeTable treeTable = new TreeTable();
package com.vaadin.tests.server.component.ui;
+import static org.junit.Assert.assertEquals;
+
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import junit.framework.TestCase;
-
import org.easymock.EasyMock;
+import org.junit.Test;
import com.vaadin.server.DefaultDeploymentConfiguration;
import com.vaadin.server.DefaultUIProvider;
import com.vaadin.tests.util.AlwaysLockedVaadinSession;
import com.vaadin.ui.UI;
-public class CustomUIClassLoaderTest extends TestCase {
+public class CustomUIClassLoaderTest {
/**
* Stub root
* @throws Exception
* if thrown
*/
+ @Test
public void testWithDefaultClassLoader() throws Exception {
VaadinSession application = createStubApplication();
application.setConfiguration(createConfigurationMock());
* @throws Exception
* if thrown
*/
+ @Test
public void testWithClassLoader() throws Exception {
LoggingClassLoader loggingClassLoader = new LoggingClassLoader();
package com.vaadin.tests.server.component.upload;
+import org.junit.Test;
+
import com.vaadin.server.StreamVariable.StreamingProgressEvent;
import com.vaadin.tests.server.component.AbstractListenerMethodsTestBase;
import com.vaadin.ui.Upload;
import com.vaadin.ui.Upload.SucceededListener;
public class UploadListenersTest extends AbstractListenerMethodsTestBase {
+
+ @Test
public void testProgressListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Upload.class, StreamingProgressEvent.class,
ProgressListener.class);
}
+ @Test
public void testSucceededListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Upload.class, SucceededEvent.class,
SucceededListener.class);
}
+ @Test
public void testStartedListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Upload.class, StartedEvent.class,
StartedListener.class);
}
+ @Test
public void testFailedListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Upload.class, FailedEvent.class,
FailedListener.class);
}
+ @Test
public void testFinishedListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Upload.class, FinishedEvent.class,
FinishedListener.class);
package com.vaadin.tests.server.component.window;
+import org.junit.Test;
+
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import com.vaadin.event.FieldEvents.FocusEvent;
import com.vaadin.ui.Window.ResizeListener;
public class WindowListenersTest extends AbstractListenerMethodsTestBase {
+
+ @Test
public void testFocusListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Window.class, FocusEvent.class,
FocusListener.class);
}
+ @Test
public void testBlurListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Window.class, BlurEvent.class,
BlurListener.class);
}
+ @Test
public void testResizeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Window.class, ResizeEvent.class,
ResizeListener.class);
}
+ @Test
public void testCloseListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(Window.class, CloseEvent.class,
CloseListener.class);
package com.vaadin.tests.server.componentcontainer;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.Layout;
-public abstract class AbstractIndexedLayoutTestBase extends TestCase {
+public abstract class AbstractIndexedLayoutTestBase {
private Layout layout;
protected abstract Layout createLayout();
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() {
layout = createLayout();
}
return layout;
}
+ @Test
public void testAddRemoveComponent() {
Label c1 = new Label();
Label c2 = new Label();
protected abstract int getComponentIndex(Component c);
+ @Test
public void testGetComponentIndex() {
Label c1 = new Label();
Label c2 = new Label();
assertEquals(-1, getComponentIndex(c1));
}
+ @Test
public void testGetComponent() {
Label c1 = new Label();
Label c2 = new Label();
import java.util.List;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.tests.VaadinClasses;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.Label;
import com.vaadin.ui.components.colorpicker.ColorPickerPreview;
-public class AddRemoveComponentTest extends TestCase {
+public class AddRemoveComponentTest {
+ @Test
public void testRemoveComponentFromWrongContainer()
throws InstantiationException, IllegalAccessException {
List<Class<? extends ComponentContainer>> containerClasses = VaadinClasses
hl.addComponent(label);
componentContainer.removeComponent(label);
- assertEquals(
- "Parent no longer correct for " + componentContainer.getClass(),
- hl, label.getParent());
+ Assert.assertEquals("Parent no longer correct for "
+ + componentContainer.getClass(), hl, label.getParent());
}
}
package com.vaadin.tests.server.componentcontainer;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
import java.util.Iterator;
import java.util.NoSuchElementException;
package com.vaadin.tests.server.components;
-import junit.framework.TestCase;
-
import org.easymock.EasyMock;
+import org.junit.Test;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
* override {@link #setValue(AbstractField)} to set the field value via
* <code>changeVariables()</code>.
*/
-public abstract class AbstractFieldValueChangeTestBase<T> extends TestCase {
+public abstract class AbstractFieldValueChangeTestBase<T> {
private AbstractField<T> field;
private ValueChangeListener listener;
- protected void setUp(AbstractField<T> field) throws Exception {
+ protected void setUp(AbstractField<T> field) {
this.field = field;
listener = EasyMock.createStrictMock(ValueChangeListener.class);
/**
* Test that listeners are not called when they have been unregistered.
*/
+ @Test
public void testRemoveListener() {
getField().setPropertyDataSource(new ObjectProperty<String>(""));
getField().setBuffered(false);
* Field value change notifications closely mirror value changes of the data
* source behind the field.
*/
+ @Test
public void testNonBuffered() {
getField().setPropertyDataSource(new ObjectProperty<String>(""));
getField().setBuffered(false);
import java.util.HashMap;
import java.util.Map;
+import org.junit.Before;
+
import com.vaadin.ui.AbstractField;
import com.vaadin.ui.ComboBox;
*/
public class ComboBoxValueChangeTest extends
AbstractFieldValueChangeTestBase<Object> {
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() {
ComboBox combo = new ComboBox();
combo.addItem("myvalue");
super.setUp(combo);
package com.vaadin.tests.server.components;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
import java.util.Iterator;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.AbsoluteLayout.ComponentPosition;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
-public class ComponentAttachDetachListenerTest extends TestCase {
+public class ComponentAttachDetachListenerTest {
private AbstractOrderedLayout olayout;
private GridLayout gridlayout;
componentPosition = null;
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() {
olayout = new HorizontalLayout();
olayout.addComponentAttachListener(new MyAttachListener());
customlayout.addComponentDetachListener(new MyDetachListener());
}
+ @Test
public void testOrderedLayoutAttachListener() {
// Reset state variables
resetVariables();
assertFalse(indexOfComponent == -1);
}
+ @Test
public void testOrderedLayoutDetachListener() {
// Add a component to detach
Component comp = new Label();
assertEquals(-1, indexOfComponent);
}
+ @Test
public void testGridLayoutAttachListener() {
// Reset state variables
resetVariables();
assertNotNull(componentArea);
}
+ @Test
public void testGridLayoutDetachListener() {
// Add a component to detach
Component comp = new Label();
assertNull(componentArea);
}
+ @Test
public void testAbsoluteLayoutAttachListener() {
// Reset state variables
resetVariables();
assertNotNull(componentPosition);
}
+ @Test
public void testAbsoluteLayoutDetachListener() {
// Add a component to detach
Component comp = new Label();
assertNull(componentPosition);
}
+ @Test
public void testCSSLayoutAttachListener() {
// Reset state variables
resetVariables();
assertTrue(foundInContainer);
}
+ @Test
public void testCSSLayoutDetachListener() {
// Add a component to detach
Component comp = new Label();
assertFalse(foundInContainer);
}
+ @Test
public void testCustomLayoutAttachListener() {
// Reset state variables
resetVariables();
foundInContainer);
}
+ @Test
public void testCustomLayoutDetachListener() {
// Add a component to detach
Component comp = new Label();
package com.vaadin.tests.server.components;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Label;
-public class GridLayoutLastRowRemovalTest extends TestCase {
+public class GridLayoutLastRowRemovalTest {
+ @Test
public void testRemovingLastRow() {
GridLayout grid = new GridLayout(2, 1);
grid.addComponent(new Label("Col1"));
import org.easymock.EasyMock;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.ObjectProperty;
public class TextFieldValueChangeTest extends
AbstractFieldValueChangeTestBase<String> {
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() {
super.setUp(new TextField());
}
* Case where the text field only uses its internal buffer, no external
* property data source.
*/
+ @Test
public void testNoDataSource() {
getField().setPropertyDataSource(null);
*
* TODO make test field type agnostic (eg. combobox)
*/
+ @Test
public void testValueChangeEventPropagationWithReadThrough() {
ObjectProperty<String> property = new ObjectProperty<String>("");
getField().setPropertyDataSource(property);
*
* TODO make test field type agnostic (eg. combobox)
*/
+ @Test
public void testValueChangePropagationWithReadThroughOff() {
final String initialValue = "initial";
ObjectProperty<String> property = new ObjectProperty<String>(
import java.util.HashMap;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.ResizeEvent;
import com.vaadin.ui.Window.ResizeListener;
-public class WindowTest extends TestCase {
+public class WindowTest {
private Window window;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() {
window = new Window();
new LegacyWindow().addWindow(window);
}
+ @Test
public void testCloseListener() {
CloseListener cl = EasyMock.createMock(Window.CloseListener.class);
}
+ @Test
public void testResizeListener() {
ResizeListener rl = EasyMock.createMock(Window.ResizeListener.class);
package com.vaadin.tests.server.navigator;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
import com.vaadin.navigator.Navigator.ClassBasedViewProvider;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Label;
-public class ClassBasedViewProviderTest extends TestCase {
+public class ClassBasedViewProviderTest {
public static class TestView extends Label implements View {
public String parameters = null;
}
+ @Test(expected = IllegalArgumentException.class)
public void testCreateProviderWithNullName() throws Exception {
- try {
- new ClassBasedViewProvider(null, TestView.class);
- fail("Should not be able to create view provider with null name");
- } catch (IllegalArgumentException e) {
- }
+ new ClassBasedViewProvider(null, TestView.class);
+ fail("Should not be able to create view provider with null name");
}
+ @Test
public void testCreateProviderWithEmptyStringName() throws Exception {
new ClassBasedViewProvider("", TestView.class);
}
+ @Test(expected = IllegalArgumentException.class)
public void testCreateProviderNullViewClass() throws Exception {
- try {
- new ClassBasedViewProvider("test", null);
- fail("Should not be able to create view provider with null view class");
- } catch (IllegalArgumentException e) {
- }
+ new ClassBasedViewProvider("test", null);
+ fail("Should not be able to create view provider with null view class");
}
+ @Test
public void testViewNameGetter() throws Exception {
ClassBasedViewProvider provider1 = new ClassBasedViewProvider("",
TestView.class);
provider2.getViewName());
}
+ @Test
public void testViewClassGetter() throws Exception {
ClassBasedViewProvider provider = new ClassBasedViewProvider("test",
TestView.class);
provider.getViewClass());
}
+ @Test
public void testGetViewNameForNullString() throws Exception {
ClassBasedViewProvider provider = new ClassBasedViewProvider("test",
TestView.class);
provider.getViewName((String) null));
}
+ @Test
public void testGetViewNameForEmptyString() throws Exception {
ClassBasedViewProvider provider1 = new ClassBasedViewProvider("",
TestView.class);
provider2.getViewName(""));
}
+ @Test
public void testGetViewNameWithParameters() throws Exception {
ClassBasedViewProvider provider = new ClassBasedViewProvider("test",
TestView.class);
"test", provider.getViewName("test/params/are/here"));
}
+ @Test
public void testGetView() throws Exception {
ClassBasedViewProvider provider = new ClassBasedViewProvider("test",
TestView.class);
assertEquals("Incorrect view type", TestView.class, view.getClass());
}
+ @Test
public void testGetViewIncorrectViewName() throws Exception {
ClassBasedViewProvider provider = new ClassBasedViewProvider("test",
TestView.class);
package com.vaadin.tests.server.navigator;
-import java.util.LinkedList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
+import java.util.LinkedList;
import org.easymock.EasyMock;
import org.easymock.IArgumentMatcher;
import org.easymock.IMocksControl;
import org.junit.Assert;
+import org.junit.Test;
import com.vaadin.navigator.NavigationStateManager;
import com.vaadin.navigator.Navigator;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
-public class NavigatorTest extends TestCase {
+public class NavigatorTest {
// TODO test internal parameters (and absence of them)
// TODO test listeners blocking navigation, multiple listeners
return new Navigator(createMockUI(), manager, display);
}
+ @Test(expected = NullPointerException.class)
public void testDestroy_unsetNavigatorInUIAndUriFragmentManager() {
TestPage page = new TestPage();
UI ui = new TestUI(page);
ui.getNavigator());
UriFragmentManager manager = (UriFragmentManager) navigator
.getStateManager();
- try {
- manager.uriFragmentChanged(EasyMock
- .createMock(UriFragmentChangedEvent.class));
- Assert.assertTrue(
- "Expected null pointer exception after call uriFragmentChanged "
- + "for destroyed navigator", false);
- } catch (NullPointerException e) {
- }
+
+ manager.uriFragmentChanged(EasyMock
+ .createMock(UriFragmentChangedEvent.class));
+ Assert.fail("Expected null pointer exception after call uriFragmentChanged "
+ + "for destroyed navigator");
}
+ @Test
public void testBasicNavigation() {
IMocksControl control = EasyMock.createControl();
NavigationStateManager manager = control
assertEquals("test1/params", navigator.getState());
}
+ @Test
public void testMainView() {
IMocksControl control = EasyMock.createControl();
NavigationStateManager manager = control
navigator.navigateTo("test1/params");
}
+ @Test
public void testListeners() {
IMocksControl control = EasyMock.createControl();
NavigationStateManager manager = control
}
}
+ @Test
public void testComponentContainerViewDisplay() {
abstract class TestView implements Component, View {
}
assertEquals(1, container.getComponentCount());
}
+ @Test
public void testBlockNavigation() {
IMocksControl control = EasyMock.createControl();
NavigationStateManager manager = control
}
}
+ @Test
public void testAddViewInstance() throws Exception {
View view = new TestView();
view, navigator.getView("test"));
}
+ @Test
public void testAddViewInstanceSameName() throws Exception {
View view1 = new TestView();
View view2 = new TestView2();
view2, navigator.getView("test"));
}
+ @Test
public void testAddViewClass() throws Exception {
TestNavigator navigator = new TestNavigator();
view.getClass());
}
+ @Test
public void testAddViewClassSameName() throws Exception {
TestNavigator navigator = new TestNavigator();
TestView2.class, navigator.getView("test").getClass());
}
+ @Test
public void testAddViewInstanceAndClassSameName() throws Exception {
TestNavigator navigator = new TestNavigator();
TestView.class, navigator.getView("test").getClass());
}
+ @Test
public void testAddViewWithNullName() throws Exception {
Navigator navigator = new TestNavigator();
}
}
+ @Test(expected = IllegalArgumentException.class)
public void testAddViewWithNullInstance() throws Exception {
Navigator navigator = new TestNavigator();
- try {
- navigator.addView("test", (View) null);
- fail("addView() accepted null view instance");
- } catch (IllegalArgumentException e) {
- }
+ navigator.addView("test", (View) null);
+ fail("addView() accepted null view instance");
}
+ @Test(expected = IllegalArgumentException.class)
public void testAddViewWithNullClass() throws Exception {
Navigator navigator = new TestNavigator();
- try {
- navigator.addView("test", (Class<View>) null);
- fail("addView() accepted null view class");
- } catch (IllegalArgumentException e) {
- }
+ navigator.addView("test", (Class<View>) null);
+ fail("addView() accepted null view class");
}
+ @Test
public void testRemoveViewInstance() throws Exception {
View view = new TestView();
assertNull("View not removed", navigator.getView("test"));
}
+ @Test
public void testRemoveViewInstanceNothingElse() throws Exception {
View view = new TestView();
View view2 = new TestView2();
assertEquals("Removed extra views", view2, navigator.getView("test2"));
}
+ @Test
public void testRemoveViewClass() throws Exception {
TestNavigator navigator = new TestNavigator();
assertNull("View not removed", navigator.getView("test"));
}
+ @Test
public void testRemoveViewClassNothingElse() throws Exception {
TestNavigator navigator = new TestNavigator();
navigator.getView("test2").getClass());
}
+ @Test
public void testGetViewNestedNames() throws Exception {
TestNavigator navigator = new TestNavigator();
.getClass());
}
+ @Test
public void testGetViewLongestPrefixOrder() throws Exception {
TestNavigator navigator = new TestNavigator();
.getView("test").getClass());
}
+ @Test
public void testNavigateToUnknownView() {
TestNavigator navigator = new TestNavigator();
navigator.navigateTo("doesnotexist2");
}
+ @Test
public void testShowViewEnterOrder() {
IMocksControl control = EasyMock.createStrictControl();
navigator.navigateTo("view");
}
+ @Test(expected = IllegalArgumentException.class)
public void testNullViewProvider() {
IMocksControl control = EasyMock.createControl();
NavigationStateManager manager = control
// create navigator to test
Navigator navigator = createNavigator(manager, display);
- try {
- navigator.addProvider(null);
- fail("Should not be allowed to add a null view provider");
- } catch (IllegalArgumentException e) {
- // Expected
- }
+ navigator.addProvider(null);
+ fail("Should not be allowed to add a null view provider");
+
}
}
Assert.assertEquals(2, causes.length);
}
+ @Test
public void testBeanValidationNotAddedTwice() {
// See ticket #11045
BeanFieldGroup<BeanToValidate> fieldGroup = new BeanFieldGroup<BeanToValidate>(
try {
nameField.validate();
} catch (InvalidValueException e) {
- // NOTE: causes are empty if only one validation fails
- Assert.assertEquals(0, e.getCauses().length);
+ // The 1 cause is from BeanValidator, where it tells what failed
+ // 1 validation exception never gets wrapped.
+ Assert.assertEquals(1, e.getCauses().length);
}
// Create new, identical bean to cause duplicate validator unless #11045
try {
nameField.validate();
} catch (InvalidValueException e) {
- // NOTE: if more than one validation fails, we get the number of
- // failed validations
- Assert.assertEquals(0, e.getCauses().length);
+ // The 1 cause is from BeanValidator, where it tells what failed
+ // 1 validation exception never gets wrapped.
+ Assert.assertEquals(1, e.getCauses().length);
}
}
package com.vaadin.tests.server.validation;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
import com.vaadin.data.validator.IntegerRangeValidator;
-public class RangeValidatorTest extends TestCase {
+public class RangeValidatorTest {
// This test uses IntegerRangeValidator for simplicity.
// IntegerRangeValidator contains no code so we really are testing
// RangeValidator
+ @Test
public void testMinValueNonInclusive() {
IntegerRangeValidator iv = new IntegerRangeValidator("Failed", 0, 10);
iv.setMinValueIncluded(false);
assertFalse(iv.isValid(-1));
}
+ @Test
public void testMinMaxValuesInclusive() {
IntegerRangeValidator iv = new IntegerRangeValidator("Failed", 0, 10);
assertTrue(iv.isValid(0));
assertFalse(iv.isValid(-1));
}
+ @Test
public void testMaxValueNonInclusive() {
IntegerRangeValidator iv = new IntegerRangeValidator("Failed", 0, 10);
iv.setMaxValueIncluded(false);
assertFalse(iv.isValid(-1));
}
+ @Test
public void testMinMaxValuesNonInclusive() {
IntegerRangeValidator iv = new IntegerRangeValidator("Failed", 0, 10);
iv.setMinValueIncluded(false);
*/
package com.vaadin.tests.util;
-import java.io.Serializable;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.io.Serializable;
import org.apache.commons.lang.SerializationUtils;
+import org.junit.Test;
import com.vaadin.ui.UniqueSerializable;
-public class UniqueSerializableTest extends TestCase implements Serializable {
+public class UniqueSerializableTest implements Serializable {
+ @Test
public void testUniqueness() {
UniqueSerializable o1 = new UniqueSerializable() {
};
assertFalse(o1.equals(o2));
}
+ @Test
public void testSerialization() {
UniqueSerializable o1 = new UniqueSerializable() {
};
--- /dev/null
+package com.vaadin.ui;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Date;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNull.nullValue;
+
+public class DateFieldTestCase {
+
+ private DateField dateField;
+ private Date date;
+
+ @Before
+ public void setup() {
+ dateField = new DateField();
+ date = new Date();
+ }
+
+ @Test
+ public void rangeStartIsSetToNull() {
+ dateField.setRangeStart(null);
+
+ assertThat(dateField.getRangeStart(), is(nullValue()));
+ }
+
+ @Test
+ public void rangeStartIsImmutable() {
+ long expectedTime = date.getTime();
+
+ dateField.setRangeStart(date);
+ date.setTime(expectedTime + 1);
+
+ assertThat(dateField.getRangeStart().getTime(), is(expectedTime));
+ }
+
+ @Test
+ public void rangeEndIsSetToNull() {
+ dateField.setRangeEnd(null);
+
+ assertThat(dateField.getRangeEnd(), is(nullValue()));
+ }
+
+ @Test
+ public void rangeEndIsImmutable() {
+ long expectedTime = date.getTime();
+
+ dateField.setRangeEnd(date);
+ date.setTime(expectedTime + 1);
+
+ assertThat(dateField.getRangeEnd().getTime(), is(expectedTime));
+ }
+}
+++ /dev/null
-package com.vaadin.ui;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Date;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsNull.nullValue;
-
-public class DateFieldTests {
-
- private DateField dateField;
- private Date date;
-
- @Before
- public void setup() {
- dateField = new DateField();
- date = new Date();
- }
-
- @Test
- public void rangeStartIsSetToNull() {
- dateField.setRangeStart(null);
-
- assertThat(dateField.getRangeStart(), is(nullValue()));
- }
-
- @Test
- public void rangeStartIsImmutable() {
- long expectedTime = date.getTime();
-
- dateField.setRangeStart(date);
- date.setTime(expectedTime + 1);
-
- assertThat(dateField.getRangeStart().getTime(), is(expectedTime));
- }
-
- @Test
- public void rangeEndIsSetToNull() {
- dateField.setRangeEnd(null);
-
- assertThat(dateField.getRangeEnd(), is(nullValue()));
- }
-
- @Test
- public void rangeEndIsImmutable() {
- long expectedTime = date.getTime();
-
- dateField.setRangeEnd(date);
- date.setTime(expectedTime + 1);
-
- assertThat(dateField.getRangeEnd().getTime(), is(expectedTime));
- }
-}