diff options
author | Dominic Lunanuova <dgl@research.att.com> | 2019-04-12 13:31:26 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-12 13:31:26 +0000 |
commit | d07718b9a29bc895a5acce89dd1c5368b5279b98 (patch) | |
tree | 5b7a6caf9e9a4cf6a21285b2e37caed4066de48c /src/test/java | |
parent | 8ffbb006be9f5ef23dc6f4fbec8a1a3999dadcb1 (diff) | |
parent | 57850893ab80ef3e144e500f9342ed53bfe33823 (diff) |
Merge "Junits for classes in util package"
Diffstat (limited to 'src/test/java')
3 files changed, 114 insertions, 49 deletions
diff --git a/src/test/java/org/onap/dmaap/dbcapi/util/DmaapTimestampTest.java b/src/test/java/org/onap/dmaap/dbcapi/util/DmaapTimestampTest.java new file mode 100644 index 0000000..33d1d17 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/util/DmaapTimestampTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.dmaap.dbcapi.util; + +import org.junit.Test; + +import java.util.Date; + +import static org.junit.Assert.assertTrue; + +public class DmaapTimestampTest { + + private DmaapTimestamp dmaapTimestamp = new DmaapTimestamp(); + + @Test + public void mark_shouldUpdateTimestamp() { + dmaapTimestamp = new DmaapTimestamp(new Date(10)); + Date timestamp = dmaapTimestamp.getVal(); + + dmaapTimestamp.mark(); + + assertTrue(timestamp.before(dmaapTimestamp.getVal())); + } +}
\ No newline at end of file diff --git a/src/test/java/org/onap/dmaap/dbcapi/util/RandomIntegerTest.java b/src/test/java/org/onap/dmaap/dbcapi/util/RandomIntegerTest.java index bd5f9cd..1184cdb 100644 --- a/src/test/java/org/onap/dmaap/dbcapi/util/RandomIntegerTest.java +++ b/src/test/java/org/onap/dmaap/dbcapi/util/RandomIntegerTest.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * org.onap.dmaap * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. * ================================================================================ * 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. @@ -19,59 +19,22 @@ */ package org.onap.dmaap.dbcapi.util; -import org.onap.dmaap.dbcapi.model.*; -import org.onap.dmaap.dbcapi.service.*; -import org.onap.dmaap.dbcapi.testframework.ReflectionHarness; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import java.util.*; -import java.sql.*; - -public class RandomIntegerTest { - - private static final String fmt = "%24s: %s%n"; - - ReflectionHarness rh = new ReflectionHarness(); - - RandomInteger ri; - - @Before - public void setUp() throws Exception { - ri = new RandomInteger( 12434 ); - } +import static org.junit.Assert.assertTrue; - @After - public void tearDown() throws Exception { - } - - - @Test - public void test1() { - - - rh.reflect( "org.onap.dmaap.dbcapi.util.RandomInteger", "get", "" ); - - } - - @Test - public void test2() { - String v = "Validate"; - rh.reflect( "org.onap.dmaap.dbcapi.util.RandomInteger", "set", v ); - - } +public class RandomIntegerTest { - @Test - public void test3() { - int i = ri.next(); + private static final int RANGE = 10; + private RandomInteger ri = new RandomInteger(RANGE); - } + @Test + public void next_shouldReturnIntegerFromGivenRange() { + int next = ri.next(); + assertTrue(next >= 0 && next <= RANGE); + } } diff --git a/src/test/java/org/onap/dmaap/dbcapi/util/RandomStringTest.java b/src/test/java/org/onap/dmaap/dbcapi/util/RandomStringTest.java new file mode 100644 index 0000000..e549dc3 --- /dev/null +++ b/src/test/java/org/onap/dmaap/dbcapi/util/RandomStringTest.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dmaap + * ================================================================================ + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.dmaap.dbcapi.util; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class RandomStringTest { + + private static final int LENGTH = 10; + @Rule + public ExpectedException thrown = ExpectedException.none(); + private RandomString randomString = new RandomString(LENGTH); + + @Test + public void nextString_shouldReturnStringWithGivenLength() { + + String nextString = randomString.nextString(); + + assertEquals(LENGTH, nextString.length()); + } + + @Test + public void nextString_shouldReturnAlphanumeric() { + + String nextString = randomString.nextString(); + + assertTrue(nextString.matches("[a-z0-9]*")); + } + + @Test + public void constructor_shouldThrowExceptionForNegativeLength() { + + thrown.expect(IllegalArgumentException.class); + + new RandomString(-1); + } +}
\ No newline at end of file |