Skip to main content
summaryrefslogtreecommitdiffstats
blob: b865ae832c32cdd6aeec4e8ef109f78d820407e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************************************
 * Copyright (c) 2008 Ketan Padegaonkar and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Ketan Padegaonkar - initial API and implementation
 *******************************************************************************/
package org.eclipse.swtbot.swt.finder.widgets;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.util.Calendar;
import java.util.Date;

import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swtbot.swt.finder.test.AbstractControlExampleTest;
import org.junit.Before;
import org.junit.Test;

/**
 * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 * @version $Id$
 */
public class SWTBotDateTimeTest extends AbstractControlExampleTest {

	private SWTBotDateTime	dateTime;

	@Test
	public void findsDateTime() throws Exception {
		assertEquals(DateTime.class, dateTime.widget.getClass());
	}

	@Test
	public void setsAndGetsDateOnDateTime() throws Exception {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(0);
		calendar.set(2012, 10, 20, 0, 0, 0);
		Date expected = calendar.getTime();
		assertFalse(expected.equals(dateTime.getDate()));
		dateTime.setDate(expected);
		Date actual = dateTime.getDate();
		assertEquals(expected, actual);
	}

	@Test
	public void shouldHandleInvalidDates() throws Exception {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(0);
		calendar.set(2011, 1, 3, 0, 0, 0);
		Date expected = calendar.getTime();
		assertFalse(expected.equals(dateTime.getDate()));
		dateTime.setDate(expected);

		calendar = Calendar.getInstance();
		calendar.setTimeInMillis(0);
		calendar.set(2010, 11, 31, 0, 0, 0);
		dateTime.setDate(calendar.getTime());
		assertEquals(calendar.getTime(), dateTime.getDate());
	}

	@Test
	public void bug347824() throws Exception {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(0);
		calendar.set(2011, Calendar.MAY, 31, 0, 0, 0);
		Date expected = calendar.getTime();
		assertFalse(expected.equals(dateTime.getDate()));
		dateTime.setDate(expected);
		assertEquals(expected, dateTime.getDate());
		
		calendar = Calendar.getInstance();
		calendar.setTimeInMillis(0);
		calendar.set(2010, Calendar.SEPTEMBER, 28, 0, 0, 0);
		dateTime.setDate(calendar.getTime());
		assertEquals(calendar.getTime(), dateTime.getDate());
	}
	
	@Test
	public void sendsNotification() throws Exception {
		bot.checkBox("Listen").click();
		SWTBotDateTime dateTime = bot.dateTimeInGroup("DateTime");
		dateTime.setDate(new Date());
		// FIXME https://bugs.eclipse.org/bugs/show_bug.cgi?id=206715
		// FIXED > 071107 for all platforms.
		String expectedLinux = "Selection [13]: SelectionEvent{DateTime";
		String expectedWindows = "Selection [13]: SelectionEvent{DateTime {DateTime";
		String text = bot.textInGroup("Listeners").getText();
		assertThat(text, anyOf(containsString(expectedLinux), containsString(expectedWindows)));
		assertThat(text, containsString(" data=null item=null detail=0 x=0 y=0 width=0 height=0 stateMask=0 text=null doit=true}"));
	}

	@Before
	public void prepareExample() throws Exception {
		bot.tabItem("DateTime").activate();
		dateTime = bot.dateTimeInGroup("DateTime");
	}
}

Back to the top