summaryrefslogtreecommitdiffstats
path: root/src/org.gluster.storage.management.core/junit/org/gluster/storage/management/core/utils/DateUtilTest.java
blob: df782b00437bcef60387169a8b4f7ba4dd0bdc93 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package org.gluster.storage.management.core.utils;

import static org.junit.Assert.assertEquals;

import java.util.Date;

import org.gluster.storage.management.core.constants.CoreConstants;
import org.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import org.gluster.storage.management.core.utils.DateUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


/**
 * The class <code>DateUtilTest</code> contains tests for the class <code>{@link DateUtil}</code>.
 *
 * @generatedBy CodePro at 9/27/11 12:31 PM
 * @author root
 * @version $Revision: 1.0 $
 */
public class DateUtilTest {

	private Date date = DateUtil.getDate(2011, 9, 29, 11, 17, 38, 10);

	/**
	 * Run the String dateToString(Date) method test.
	 *
	 * @throws Exception
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Test
	public void testDateToString_1()
		throws Exception {
		String result = DateUtil.dateToString(date);

		assertEquals("09/29/2011 11:17:38", result);
	}

	/**
	 * Run the String dateToString(Date,String) method test.
	 *
	 * @throws Exception
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Test
	public void testDateToString_2()
		throws Exception {
		String dateFormat = "";

		String result = DateUtil.dateToString(date, dateFormat);
		assertEquals("", result);
	}
	
	/**
	 * Run the String dateToString(Date,String) method test.
	 *
	 * @throws Exception
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Test
	public void testDateToString_3()
		throws Exception {
		String dateFormat = CoreConstants.PURE_DATE_FORMAT;

		String result = DateUtil.dateToString(date, dateFormat);
		assertEquals("09/29/2011", result);
	}

	/**
	 * Run the String formatDate(Date) method test.
	 *
	 * @throws Exception
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Test
	public void testFormatDate_1()
		throws Exception {
		String result = DateUtil.formatDate(date);

		assertEquals("09/29/2011", result);
	}
	
	/**
	 * Run the String formatDate(Date) method test.
	 *
	 * @throws Exception
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Test
	public void testFormatDate_2()
		throws Exception {
		Date date1 = DateUtil.getDate(1965, 1, 12, 0, 0, 0, 0);
		String result = DateUtil.formatDate(date1);
		assertEquals("01/12/1965", result);
	}

	/**
	 * Run the String formatTime(Date) method test.
	 *
	 * @throws Exception
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Test
	public void testFormatTime_1()
		throws Exception {
		String result = DateUtil.formatTime(date);

		// add additional test code here
		assertEquals("11:17:38.010", result);
	}

	/**
	 * Run the Date stringToDate(String) method test.
	 *
	 * @throws Exception
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Test(expected=GlusterRuntimeException.class)
	public void testStringToDate_1() 
		throws Exception {
		DateUtil.stringToDate("");
	}
	
	/**
	 * Run the Date stringToDate(String) method test.
	 *
	 * @throws Exception
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Test(expected=GlusterRuntimeException.class)
	public void testStringToDate_2() 
		throws Exception {
		String testDate = "09/29/2011";
		DateUtil.stringToDate(testDate);
	}

	/**
	 * Run the Date stringToDate(String,String) method test.
	 *
	 * @throws Exception
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Test
	public void testStringToDate_3()
		throws Exception {
		String dateFormat = "MM/dd/yyyy";
		String input = "09/29/2011"; // MM/dd/yyyy HH:mm:ss
		Date expectedDate = DateUtil.getDate(2011, 9, 29, 0, 0, 0, 0);
		
		Date result = DateUtil.stringToDate(input, dateFormat);
		assertEquals(expectedDate, result);
	}

	/**
	 * Run the Date stringToDate(String,String) method test.
	 *
	 * @throws Exception
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Test(expected = GlusterRuntimeException.class)
	public void testStringToDate_4()
		throws Exception {
			String inputDate = "";
			String dateFormat = "";

			DateUtil.stringToDate(inputDate, dateFormat);
	}

	/**
	 * Perform pre-test initialization.
	 *
	 * @throws Exception
	 *         if the initialization fails for some reason
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@Before
	public void setUp()
		throws Exception {
		// add additional set up code here
	}

	/**
	 * Perform post-test clean-up.
	 *
	 * @throws Exception
	 *         if the clean-up fails for some reason
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	@After
	public void tearDown()
		throws Exception {
		// Add additional tear down code here
	}

	/**
	 * Launch the test.
	 *
	 * @param args the command line arguments
	 *
	 * @generatedBy CodePro at 9/27/11 12:31 PM
	 */
	public static void main(String[] args) {
		new org.junit.runner.JUnitCore().run(DateUtilTest.class);
	}
}