jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1648232 - /jmeter/trunk/test/src/org/apache/jorphan/util/TestConverter.java
Date Sun, 28 Dec 2014 17:37:29 GMT
Author: fschumacher
Date: Sun Dec 28 17:37:29 2014
New Revision: 1648232

URL: http://svn.apache.org/r1648232
Log:
Test cases for getCalendar(Object, Calendar) and getDate(Object, Date) in Converter

Added:
    jmeter/trunk/test/src/org/apache/jorphan/util/TestConverter.java

Added: jmeter/trunk/test/src/org/apache/jorphan/util/TestConverter.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jorphan/util/TestConverter.java?rev=1648232&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jorphan/util/TestConverter.java (added)
+++ jmeter/trunk/test/src/org/apache/jorphan/util/TestConverter.java Sun Dec 28 17:37:29 2014
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.jorphan.util;
+
+import java.text.DateFormat;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+/**
+ * Tests for {@link Converter}
+ *
+ */
+public class TestConverter extends TestCase {
+
+    /**
+     * Test {@link Converter#getCalendar(Object, Calendar)} with a given Date
+     * and null as default value
+     */
+    @Test
+    public void testGetCalendarObjectCalendarWithTimeAndNullDefault() {
+        Calendar cal = new GregorianCalendar();
+        Date time = cal.getTime();
+        assertEquals(cal, Converter.getCalendar(time, null));
+    }
+
+    /**
+     * Test {@link Converter#getCalendar(Object, Calendar)} with null as Date
+     * and a sensible default value
+     */
+    @Test
+    public void testGetCalendarObjectCalendarWithNullAndCalendarAsDefault() {
+        Calendar cal = new GregorianCalendar();
+        assertEquals(cal, Converter.getCalendar(null, cal));
+    }
+
+    /**
+     * Test {@link Converter#getCalendar(Object, Calendar)} with correctly
+     * formatted strings and <code>null</code> as default value
+     */
+    @Test
+    public void testGetCalendarObjectCalendarWithValidStringAndNullDefault() {
+        Calendar cal = new GregorianCalendar();
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.SECOND, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        Date time = cal.getTime();
+        for (int formatId : Arrays.asList(DateFormat.SHORT, DateFormat.MEDIUM,
+                DateFormat.LONG, DateFormat.FULL)) {
+            DateFormat formatter = DateFormat.getDateInstance(formatId);
+            assertEquals(cal,
+                    Converter.getCalendar(formatter.format(time), null));
+        }
+    }
+
+    /**
+     * Test {@link Converter#getCalendar(Object, Calendar)} with an invalid
+     * string and <code>null</code> as default value
+     */
+    @Test
+    public void testGetCalendarObjectCalendarWithInvalidStringAndNullDefault() {
+        assertEquals(null, Converter.getCalendar("invalid date", null));
+    }
+
+    /**
+     * Test {@link Converter#getDate(Object, Date)} with a given Date
+     * and null as default value
+     */
+    @Test
+    public void testGetDateObjectDateWithTimeAndNullDefault() {
+        Date time = new Date();
+        assertEquals(time, Converter.getDate(time, null));
+    }
+
+    /**
+     * Test {@link Converter#getDate(Object, Date)} with null as Date
+     * and a sensible default value
+     */
+    @Test
+    public void testGetDateObjectDateWithNullAndDateAsDefault() {
+        Date date = new Date();
+        assertEquals(date, Converter.getDate(null, date));
+    }
+
+    /**
+     * Test {@link Converter#getDate(Object, Date)} with correctly
+     * formatted strings and <code>null</code> as default value
+     */
+    @Test
+    public void testGetDateObjectDateWithValidStringAndNullDefault() {
+        Calendar cal = new GregorianCalendar();
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.SECOND, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        Date time = cal.getTime();
+        for (int formatId : Arrays.asList(DateFormat.SHORT, DateFormat.MEDIUM,
+                DateFormat.LONG, DateFormat.FULL)) {
+            DateFormat formatter = DateFormat.getDateInstance(formatId);
+            assertEquals(time,
+                    Converter.getDate(formatter.format(time), null));
+        }
+    }
+
+    /**
+     * Test {@link Converter#getDate(Object, Date)} with an invalid
+     * string and <code>null</code> as default value
+     */
+    @Test
+    public void testGetDateObjectDateWithInvalidStringAndNullDefault() {
+        assertEquals(null, Converter.getDate("invalid date", null));
+    }
+
+}



Mime
View raw message