You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/12/04 09:39:20 UTC
[isis] branch master updated: ISIS-2464: remove TestClock(s)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 0f9c544 ISIS-2464: remove TestClock(s)
0f9c544 is described below
commit 0f9c5440932f5219f8cbb93f9a9dcaa70e01f406
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Dec 4 10:39:02 2020 +0100
ISIS-2464: remove TestClock(s)
---
.../org/apache/isis/applib/clock/VirtualClock.java | 15 ++++-
.../org/apache/isis/applib/clock/TestClock.java | 69 ---------------------
.../JavaSqlDateValueSemanticsProviderTest.java | 1 -
.../JavaUtilDateValueSemanticsProviderTest.java | 20 +++++-
.../core/metamodel/facets/value/TestClock.java | 71 ----------------------
5 files changed, 31 insertions(+), 145 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/clock/VirtualClock.java b/api/applib/src/main/java/org/apache/isis/applib/clock/VirtualClock.java
index 042b79a..d32cbad 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/clock/VirtualClock.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/clock/VirtualClock.java
@@ -24,6 +24,8 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import javax.xml.datatype.XMLGregorianCalendar;
@@ -73,11 +75,22 @@ public interface VirtualClock extends Serializable {
return new VirtualClock_withOffset(offsetMillis);
}
+ /**
+ * Always return the time as given {@link Instant} {@code frozenAt}
+ */
static VirtualClock frozenAt(@NonNull Instant frozenAt) {
- // positive if the resulting clock is in the future
return new VirtualClock_frozen(frozenAt);
}
+ /**
+ * Always return the time as 2003/8/17 21:30:25
+ */
+ static VirtualClock frozenTestClock() {
+ val frozenAt = Instant.from(
+ ZonedDateTime.of(2003, 7, 17, 21, 30, 25, 0, ZoneId.from(ZoneOffset.UTC)));
+ return frozenAt(frozenAt);
+ }
+
// -- UTILITY
/**
diff --git a/api/applib/src/test/java/org/apache/isis/applib/clock/TestClock.java b/api/applib/src/test/java/org/apache/isis/applib/clock/TestClock.java
deleted file mode 100644
index 3240349..0000000
--- a/api/applib/src/test/java/org/apache/isis/applib/clock/TestClock.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.isis.applib.clock;
-
-import java.time.Instant;
-import java.util.Calendar;
-import java.util.Locale;
-import java.util.TimeZone;
-
-public class TestClock implements VirtualClock {
-
- private static final long serialVersionUID = 2415098176083010262L;
-
- public static final TimeZone timeZone;
-
- public static void initialize() {
- new TestClock();
-
- Locale.setDefault(Locale.UK);
- TimeZone.setDefault(timeZone);
- }
-
- private TestClock() {
- super();
- }
-
- static {
- timeZone = TimeZone.getTimeZone("Etc/UTC");
- }
-
- /**
- * Always return the time as 2003/8/17 21:30:25
- */
- @Override
- public Instant now() {
- final Calendar c = Calendar.getInstance();
- c.setTimeZone(timeZone);
-
- c.set(Calendar.MILLISECOND, 0);
-
- c.set(Calendar.YEAR, 2003);
- c.set(Calendar.MONTH, 7);
- c.set(Calendar.DAY_OF_MONTH, 17);
-
- c.set(Calendar.HOUR_OF_DAY, 21);
- c.set(Calendar.MINUTE, 30);
- c.set(Calendar.SECOND, 25);
-
- return Instant.ofEpochMilli(c.getTime().getTime());
- }
-
-}
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/JavaSqlDateValueSemanticsProviderTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/JavaSqlDateValueSemanticsProviderTest.java
index b44dacf..585dd3d 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/JavaSqlDateValueSemanticsProviderTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/JavaSqlDateValueSemanticsProviderTest.java
@@ -46,7 +46,6 @@ public class JavaSqlDateValueSemanticsProviderTest extends ValueSemanticsProvide
@Before
public void setUpObjects() throws Exception {
- TestClock.initialize();
date = new Date(0);
holder = new FacetHolderImpl();
((MetaModelContextAware)holder).setMetaModelContext(super.metaModelContext);
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/JavaUtilDateValueSemanticsProviderTest.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/JavaUtilDateValueSemanticsProviderTest.java
index ea0c94b..e67ddb8 100644
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/JavaUtilDateValueSemanticsProviderTest.java
+++ b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/JavaUtilDateValueSemanticsProviderTest.java
@@ -22,6 +22,7 @@ package org.apache.isis.core.metamodel.facets.value;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import java.util.Locale;
import java.util.TimeZone;
import org.junit.Before;
@@ -37,6 +38,8 @@ import org.apache.isis.core.metamodel.facets.object.parseable.TextEntryParseExce
import org.apache.isis.core.metamodel.facets.object.value.vsp.ValueSemanticsProviderAndFacetAbstract;
import org.apache.isis.core.metamodel.facets.value.dateutil.JavaUtilDateValueSemanticsProvider;
+import lombok.val;
+
public class JavaUtilDateValueSemanticsProviderTest extends ValueSemanticsProviderAbstractTestCase {
private java.util.Date date;
@@ -45,7 +48,6 @@ public class JavaUtilDateValueSemanticsProviderTest extends ValueSemanticsProvid
@Before
public void setUpObjects() throws Exception {
- TestClock.initialize();
date = new java.util.Date(0);
holder = new FacetHolderImpl();
@@ -77,14 +79,26 @@ public class JavaUtilDateValueSemanticsProviderTest extends ValueSemanticsProvid
@Test
public void testParse() throws Exception {
- final Object newValue = getValue().parseTextEntry(null, "1980-01-01 10:40");
+ // prepare environment
+ val defaultLocale = Locale.getDefault();
+ val defaultTimezone = TimeZone.getDefault();
+ Locale.setDefault(Locale.UK);
+ TimeZone.setDefault(TimeZone.getTimeZone("Etc/UTC"));
+
+ val parsedDate = getValue().parseTextEntry(null, "1980-01-01 10:40");
+
+ // restore environment
+ Locale.setDefault(defaultLocale);
+ TimeZone.setDefault(defaultTimezone);
+
+
final Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
calendar.set(1980, 0, 1, 10, 40, 0);
calendar.set(Calendar.MILLISECOND, 0);
- assertEquals(calendar.getTime(), newValue);
+ assertEquals(calendar.getTime(), parsedDate);
}
// -- HELPER
diff --git a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/TestClock.java b/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/TestClock.java
deleted file mode 100644
index 6c49ddd..0000000
--- a/core/metamodel/src/test/java/org/apache/isis/core/metamodel/facets/value/TestClock.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.isis.core.metamodel.facets.value;
-
-import java.time.Instant;
-import java.util.Calendar;
-import java.util.Locale;
-import java.util.TimeZone;
-
-import org.apache.isis.applib.clock.VirtualClock;
-
-public class TestClock implements VirtualClock {
-
- private static final long serialVersionUID = 1L;
-
- public static final TimeZone timeZone;
-
- public static void initialize() {
- new TestClock();
-
- Locale.setDefault(Locale.UK);
- TimeZone.setDefault(timeZone);
- }
-
- private TestClock() {
- super();
- }
-
- static {
- timeZone = TimeZone.getTimeZone("Etc/UTC");
- }
-
- /**
- * Always return the time as 2003/8/17 21:30:25
- */
- @Override
- public Instant now() {
- final Calendar c = Calendar.getInstance();
- c.setTimeZone(timeZone);
-
- c.set(Calendar.MILLISECOND, 0);
-
- c.set(Calendar.YEAR, 2003);
- c.set(Calendar.MONTH, 7);
- c.set(Calendar.DAY_OF_MONTH, 17);
-
- c.set(Calendar.HOUR_OF_DAY, 21);
- c.set(Calendar.MINUTE, 30);
- c.set(Calendar.SECOND, 25);
-
- return Instant.ofEpochMilli(c.getTime().getTime());
- }
-
-}