1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.beanutils2.converters;
18
19 import java.time.Instant;
20 import java.time.ZoneId;
21 import java.time.ZonedDateTime;
22 import java.util.Calendar;
23
24 /**
25 * Test Case for the ZonedDateTimeConverter class.
26 */
27 public class ZonedDateTimeConverterTest extends AbstractDateConverterTest<ZonedDateTime> {
28
29 /**
30 * Gets the expected type
31 *
32 * @return The expected type
33 */
34 @Override
35 protected Class<ZonedDateTime> getExpectedType() {
36 return ZonedDateTime.class;
37 }
38
39 /**
40 * Create the Converter with no default value.
41 *
42 * @return A new Converter
43 */
44 @Override
45 protected ZonedDateTimeConverter makeConverter() {
46 return new ZonedDateTimeConverter();
47 }
48
49 /**
50 * Create the Converter with a default value.
51 *
52 * @param defaultValue The default value
53 * @return A new Converter
54 */
55 @Override
56 protected ZonedDateTimeConverter makeConverter(final ZonedDateTime defaultValue) {
57 return new ZonedDateTimeConverter(defaultValue);
58 }
59
60 /**
61 * Convert from a Calendar to the appropriate Date type
62 *
63 * @param value The Calendar value to convert
64 * @return The converted value
65 */
66 @Override
67 protected ZonedDateTime toType(final Calendar value) {
68 return ZonedDateTime.ofInstant(Instant.ofEpochMilli(value.getTimeInMillis()), ZoneId.systemDefault());
69 }
70 }