From 5a001a2c32ad3742e34cf3bed60e6ae08c640c19 Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Sat, 6 Dec 2014 07:44:07 -0500 Subject: [PATCH] moved withinRange to a utility class Former-commit-id: d7bd22e42e6a96306e17229e449b9b052ddcb627 --- .../update/StandardUpdateIntegrationTest.java | 23 ------ .../dependencycheck/utils/DateUtilTest.java | 71 +++++++++++++++++++ 2 files changed, 71 insertions(+), 23 deletions(-) create mode 100644 dependency-check-core/src/test/java/org/owasp/dependencycheck/utils/DateUtilTest.java diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/StandardUpdateIntegrationTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/StandardUpdateIntegrationTest.java index 4a0a4a377..332a5cab2 100644 --- a/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/StandardUpdateIntegrationTest.java +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/update/StandardUpdateIntegrationTest.java @@ -18,8 +18,6 @@ package org.owasp.dependencycheck.data.update; import java.net.MalformedURLException; -import java.util.Calendar; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; import org.owasp.dependencycheck.BaseTest; @@ -47,26 +45,6 @@ public class StandardUpdateIntegrationTest extends BaseTest { instance.closeDataStores(); } - /** - * Test of withinRange method, of class StandardUpdate. - */ - @Test - public void testWithinRange() throws Exception { - Calendar c = Calendar.getInstance(); - - long current = c.getTimeInMillis(); - long lastRun = c.getTimeInMillis() - (3 * (1000 * 60 * 60 * 24)); - int range = 7; // 7 days - StandardUpdate instance = getStandardUpdateTask(); - boolean expResult = true; - boolean result = instance.withinRange(lastRun, current, range); - assertEquals(expResult, result); - - lastRun = c.getTimeInMillis() - (8 * (1000 * 60 * 60 * 24)); - expResult = false; - result = instance.withinRange(lastRun, current, range); - assertEquals(expResult, result); - } // test removed as it is duplicative of the EngineIntegrationTest and the NvdCveUpdaterIntergraionTest // /** // * Test of update method, of class StandardUpdate. @@ -77,7 +55,6 @@ public class StandardUpdateIntegrationTest extends BaseTest { // instance.update(); // //TODO make this an actual test // } - /** * Test of updatesNeeded method, of class StandardUpdate. */ diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/utils/DateUtilTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/utils/DateUtilTest.java new file mode 100644 index 000000000..657b95737 --- /dev/null +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/utils/DateUtilTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2014 OWASP. + * + * 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 org.owasp.dependencycheck.utils; + +import java.util.Calendar; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author Jeremy Long + */ +public class DateUtilTest { + + public DateUtilTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of withinDateRange method, of class DateUtil. + */ + @Test + public void testWithinDateRange() { + Calendar c = Calendar.getInstance(); + + long current = c.getTimeInMillis(); + long lastRun = c.getTimeInMillis() - (3 * (1000 * 60 * 60 * 24)); + int range = 7; // 7 days + boolean expResult = true; + boolean result = DateUtil.withinDateRange(lastRun, current, range); + assertEquals(expResult, result); + + lastRun = c.getTimeInMillis() - (8 * (1000 * 60 * 60 * 24)); + expResult = false; + result = DateUtil.withinDateRange(lastRun, current, range); + assertEquals(expResult, result); + } + +}