You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by my...@apache.org on 2018/01/22 15:13:18 UTC

[fineract-cn-test] 13/32: Added date checking support for use in checking password expiration.

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

myrle pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-test.git

commit 02a5c5550f93a568b56e01de21216e4d1b6fa333
Author: myrle-krantz <mk...@mifos.org>
AuthorDate: Tue Apr 11 18:05:51 2017 +0200

    Added date checking support for use in checking password expiration.
---
 .../mifos/core/test/domain/DateStampChecker.java   | 59 ++++++++++++++++++++++
 .../core/test/domain/DateStampCheckerTest.java     | 43 ++++++++++++++++
 2 files changed, 102 insertions(+)

diff --git a/src/main/java/io/mifos/core/test/domain/DateStampChecker.java b/src/main/java/io/mifos/core/test/domain/DateStampChecker.java
new file mode 100644
index 0000000..936035e
--- /dev/null
+++ b/src/main/java/io/mifos/core/test/domain/DateStampChecker.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.test.domain;
+
+import io.mifos.core.lang.DateConverter;
+import org.junit.Assert;
+
+import java.time.Clock;
+import java.time.LocalDate;
+import java.time.temporal.ChronoUnit;
+
+/**
+ * Support class for testing that the correct time stamp is returned
+ *
+ * @author Myrle Krantz
+ */
+@SuppressWarnings("WeakerAccess")
+public class DateStampChecker {
+  private final LocalDate expectedDateStamp;
+  private final int maximumDelta;
+
+  public static DateStampChecker inTheFuture(final int offset)
+  {
+    return new DateStampChecker(LocalDate.now(Clock.systemUTC()).plusDays(offset), 0);
+  }
+
+  private DateStampChecker(final LocalDate expectedDateStamp, final int maximumDelta) {
+    this.expectedDateStamp = expectedDateStamp;
+    this.maximumDelta = maximumDelta;
+  }
+
+  public void assertCorrect(final String dateStamp)
+  {
+    Assert.assertTrue("Delta from expected should have been less than " +
+                    maximumDelta + ". Timestamp string was " + dateStamp + ".",
+            isCorrect(dateStamp));
+  }
+
+  public boolean isCorrect(final String dateStamp) {
+    final LocalDate parsedDateStamp = DateConverter.dateFromIsoString(dateStamp);
+
+    final long deltaFromExpected = parsedDateStamp.until(expectedDateStamp, ChronoUnit.DAYS);
+
+    return deltaFromExpected <= maximumDelta;
+  }
+}
diff --git a/src/test/java/io/mifos/core/test/domain/DateStampCheckerTest.java b/src/test/java/io/mifos/core/test/domain/DateStampCheckerTest.java
new file mode 100644
index 0000000..743666e
--- /dev/null
+++ b/src/test/java/io/mifos/core/test/domain/DateStampCheckerTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017 The Mifos Initiative.
+ *
+ * Licensed 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 io.mifos.core.test.domain;
+
+import io.mifos.core.lang.DateConverter;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.time.Clock;
+import java.time.LocalDate;
+import java.time.temporal.ChronoUnit;
+
+/**
+ *
+ * @author Myrle Krantz
+ */
+public class DateStampCheckerTest {
+  @Test
+  public void inTheFuture() throws Exception {
+    final DateStampChecker checker = DateStampChecker.inTheFuture(5);
+    final LocalDate now = LocalDate.now(Clock.systemUTC());
+    final LocalDate fiveDaysFromNow = now.plus(5, ChronoUnit.DAYS);
+    final String fiveDaysFromNowAsString = DateConverter.toIsoString(fiveDaysFromNow);
+    checker.assertCorrect(fiveDaysFromNowAsString);
+
+    final String nowAsString = DateConverter.toIsoString(now);
+    Assert.assertFalse(checker.isCorrect(nowAsString));
+
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
myrle@apache.org.