This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new fa8e6d097ba Add test cases on TemporalHandlerFactory (#33700)
fa8e6d097ba is described below

commit fa8e6d097ba4cb205a9e33e649d58f371ba02826
Author: Liang Zhang <zhangli...@apache.org>
AuthorDate: Sun Nov 17 22:07:54 2024 +0800

    Add test cases on TemporalHandlerFactory (#33700)
    
    * Add ShardingSphereTemporal
    
    * Add ShardingSphereTemporal
    
    * Add ShardingSphereTemporal
    
    * Add TemporalParser
    
    * Add TemporalParser
    
    * Add TemporalParser
    
    * Add TemporalParser
    
    * Add TemporalParser
    
    * Add TemporalParser
    
    * Add TemporalParser
    
    * Add TemporalHandler
    
    * Add TemporalHandler
    
    * Add TemporalHandler
    
    * Add TemporalHandler
    
    * Add TemporalHandler
    
    * Add TemporalHandler
    
    * Add TemporalHandler
    
    * Add test cases on TemporalHandlerFactory
    
    * Add test cases on TemporalHandlerFactory
---
 .../temporal/TemporalHandlerFactoryTest.java       | 69 ++++++++++++++++++++++
 .../type/LocalDateTemporalHandlerTest.java         | 53 +++++++++++++++++
 .../type/LocalDateTimeTemporalHandlerTest.java     | 53 +++++++++++++++++
 .../type/LocalTimeTemporalHandlerTest.java         | 53 +++++++++++++++++
 .../temporal/type/MonthTemporalHandlerTest.java    | 57 ++++++++++++++++++
 .../type/YearMonthTemporalHandlerTest.java         | 53 +++++++++++++++++
 .../temporal/type/YearTemporalHandlerTest.java     | 53 +++++++++++++++++
 7 files changed, 391 insertions(+)

diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/TemporalHandlerFactoryTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/TemporalHandlerFactoryTest.java
new file mode 100644
index 00000000000..ec98ce58c01
--- /dev/null
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/TemporalHandlerFactoryTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.shardingsphere.sharding.algorithm.sharding.datetime.temporal;
+
+import 
org.apache.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type.LocalDateTemporalHandler;
+import 
org.apache.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type.LocalDateTimeTemporalHandler;
+import 
org.apache.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type.LocalTimeTemporalHandler;
+import 
org.apache.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type.MonthTemporalHandler;
+import 
org.apache.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type.YearMonthTemporalHandler;
+import 
org.apache.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type.YearTemporalHandler;
+import org.junit.jupiter.api.Test;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.Month;
+import java.time.Year;
+import java.time.YearMonth;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class TemporalHandlerFactoryTest {
+    
+    @Test
+    void assertNewInstanceWithLocalDate() {
+        assertThat(TemporalHandlerFactory.newInstance(LocalDate.now()), 
instanceOf(LocalDateTemporalHandler.class));
+    }
+    
+    @Test
+    void assertNewInstanceWithLocalTime() {
+        assertThat(TemporalHandlerFactory.newInstance(LocalTime.now()), 
instanceOf(LocalTimeTemporalHandler.class));
+    }
+    
+    @Test
+    void assertNewInstanceWithLocalDateTime() {
+        assertThat(TemporalHandlerFactory.newInstance(LocalDateTime.now()), 
instanceOf(LocalDateTimeTemporalHandler.class));
+    }
+    
+    @Test
+    void assertNewInstanceWithYearMonth() {
+        assertThat(TemporalHandlerFactory.newInstance(YearMonth.now()), 
instanceOf(YearMonthTemporalHandler.class));
+    }
+    
+    @Test
+    void assertNewInstanceWithYear() {
+        assertThat(TemporalHandlerFactory.newInstance(Year.now()), 
instanceOf(YearTemporalHandler.class));
+    }
+    
+    @Test
+    void assertNewInstanceWithMonth() {
+        assertThat(TemporalHandlerFactory.newInstance(Month.JANUARY), 
instanceOf(MonthTemporalHandler.class));
+    }
+}
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/LocalDateTemporalHandlerTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/LocalDateTemporalHandlerTest.java
new file mode 100644
index 00000000000..be75f36e0a2
--- /dev/null
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/LocalDateTemporalHandlerTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class LocalDateTemporalHandlerTest {
+    
+    private final LocalDateTemporalHandler temporalHandler = new 
LocalDateTemporalHandler();
+    
+    @Test
+    void assertParse() {
+        assertThat(temporalHandler.parse("2020-01-01", 
DateTimeFormatter.ISO_LOCAL_DATE), is(LocalDate.of(2020, 1, 1)));
+    }
+    
+    @Test
+    void assertConvertTo() {
+        assertThat(temporalHandler.convertTo(LocalDate.of(2020, 1, 1)), 
is(LocalDate.of(2020, 1, 1)));
+    }
+    
+    @Test
+    void assertIsAfter() {
+        assertFalse(temporalHandler.isAfter(LocalDate.of(2020, 1, 1), 
LocalDate.of(2020, 1, 2), 1));
+    }
+    
+    @Test
+    void assertAdd() {
+        assertThat(temporalHandler.add(LocalDate.of(2020, 1, 1), 1, 
ChronoUnit.DAYS), is(LocalDate.of(2020, 1, 2)));
+    }
+}
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/LocalDateTimeTemporalHandlerTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/LocalDateTimeTemporalHandlerTest.java
new file mode 100644
index 00000000000..b79bc368af3
--- /dev/null
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/LocalDateTimeTemporalHandlerTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class LocalDateTimeTemporalHandlerTest {
+    
+    private final LocalDateTimeTemporalHandler temporalHandler = new 
LocalDateTimeTemporalHandler();
+    
+    @Test
+    void assertParse() {
+        assertThat(temporalHandler.parse("2020-01-01T00:00:00", 
DateTimeFormatter.ISO_LOCAL_DATE_TIME), is(LocalDateTime.of(2020, 1, 1, 0, 0, 
0)));
+    }
+    
+    @Test
+    void assertConvertTo() {
+        assertThat(temporalHandler.convertTo(LocalDateTime.of(2020, 1, 1, 0, 
0, 0)), is(LocalDateTime.of(2020, 1, 1, 0, 0, 0)));
+    }
+    
+    @Test
+    void assertIsAfter() {
+        assertFalse(temporalHandler.isAfter(LocalDateTime.of(2020, 1, 1, 0, 0, 
0), LocalDateTime.of(2020, 1, 1, 0, 0, 0), 1));
+    }
+    
+    @Test
+    void assertAdd() {
+        assertThat(temporalHandler.add(LocalDateTime.of(2020, 1, 1, 0, 0, 0), 
1, ChronoUnit.DAYS), is(LocalDateTime.of(2020, 1, 2, 0, 0, 0)));
+    }
+}
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/LocalTimeTemporalHandlerTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/LocalTimeTemporalHandlerTest.java
new file mode 100644
index 00000000000..dedd4ad532f
--- /dev/null
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/LocalTimeTemporalHandlerTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.LocalTime;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class LocalTimeTemporalHandlerTest {
+    
+    private final LocalTimeTemporalHandler temporalHandler = new 
LocalTimeTemporalHandler();
+    
+    @Test
+    void assertParse() {
+        assertThat(temporalHandler.parse("00:00:00", 
DateTimeFormatter.ISO_LOCAL_TIME), is(LocalTime.of(0, 0, 0)));
+    }
+    
+    @Test
+    void assertConvertTo() {
+        assertThat(temporalHandler.convertTo(LocalTime.of(0, 0, 0)), 
is(LocalTime.of(0, 0, 0)));
+    }
+    
+    @Test
+    void assertIsAfter() {
+        assertFalse(temporalHandler.isAfter(LocalTime.of(0, 0, 0), 
LocalTime.of(0, 0, 0), 1));
+    }
+    
+    @Test
+    void assertAdd() {
+        assertThat(temporalHandler.add(LocalTime.of(0, 0, 0), 1, 
ChronoUnit.HOURS), is(LocalTime.of(1, 0, 0)));
+    }
+}
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/MonthTemporalHandlerTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/MonthTemporalHandlerTest.java
new file mode 100644
index 00000000000..ea14225e0d8
--- /dev/null
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/MonthTemporalHandlerTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Month;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class MonthTemporalHandlerTest {
+    
+    private final MonthTemporalHandler temporalHandler = new 
MonthTemporalHandler();
+    
+    @Test
+    void assertParse() {
+        assertThat(temporalHandler.parse("1", 
DateTimeFormatter.ofPattern("M")), is(Month.JANUARY));
+    }
+    
+    @Test
+    void assertConvertTo() {
+        assertThat(temporalHandler.convertTo(Month.of(1)), is(Month.JANUARY));
+    }
+    
+    @Test
+    void assertIsAfter() {
+        assertFalse(temporalHandler.isAfter(Month.JANUARY, Month.FEBRUARY, 1));
+        assertTrue(temporalHandler.isAfter(Month.FEBRUARY, Month.JANUARY, 1));
+        assertFalse(temporalHandler.isAfter(Month.OCTOBER, Month.DECEMBER, 1));
+        assertTrue(temporalHandler.isAfter(Month.OCTOBER, Month.NOVEMBER, 3));
+    }
+    
+    @Test
+    void assertAdd() {
+        assertThat(temporalHandler.add(Month.JANUARY, 1, ChronoUnit.MONTHS), 
is(Month.FEBRUARY));
+    }
+}
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/YearMonthTemporalHandlerTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/YearMonthTemporalHandlerTest.java
new file mode 100644
index 00000000000..b202057766f
--- /dev/null
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/YearMonthTemporalHandlerTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.YearMonth;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class YearMonthTemporalHandlerTest {
+    
+    private final YearMonthTemporalHandler temporalHandler = new 
YearMonthTemporalHandler();
+    
+    @Test
+    void assertParse() {
+        assertThat(temporalHandler.parse("2000-01", 
DateTimeFormatter.ofPattern("yyyy-MM")), is(YearMonth.of(2000, 1)));
+    }
+    
+    @Test
+    void assertConvertTo() {
+        assertThat(temporalHandler.convertTo(YearMonth.of(2000, 1)), 
is(YearMonth.of(2000, 1)));
+    }
+    
+    @Test
+    void assertIsAfter() {
+        assertFalse(temporalHandler.isAfter(YearMonth.of(2000, 1), 
YearMonth.of(2000, 1), 1));
+    }
+    
+    @Test
+    void assertAdd() {
+        assertThat(temporalHandler.add(YearMonth.of(2000, 1), 1, 
ChronoUnit.MONTHS), is(YearMonth.of(2000, 2)));
+    }
+}
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/YearTemporalHandlerTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/YearTemporalHandlerTest.java
new file mode 100644
index 00000000000..6d4ff189a36
--- /dev/null
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/temporal/type/YearTemporalHandlerTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.shardingsphere.sharding.algorithm.sharding.datetime.temporal.type;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Year;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+class YearTemporalHandlerTest {
+    
+    private final YearTemporalHandler temporalHandler = new 
YearTemporalHandler();
+    
+    @Test
+    void assertParse() {
+        assertThat(temporalHandler.parse("2000", 
DateTimeFormatter.ofPattern("yyyy")), is(Year.of(2000)));
+    }
+    
+    @Test
+    void assertConvertTo() {
+        assertThat(temporalHandler.convertTo(Year.of(2000)), 
is(Year.of(2000)));
+    }
+    
+    @Test
+    void assertIsAfter() {
+        assertFalse(temporalHandler.isAfter(Year.of(2000), Year.of(2001), 1));
+    }
+    
+    @Test
+    void assertAdd() {
+        assertThat(temporalHandler.add(Year.of(2000), 1, ChronoUnit.YEARS), 
is(Year.of(2001)));
+    }
+}

Reply via email to