diff options
author | Jim Hahn <jrh3@att.com> | 2021-02-10 16:17:10 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-02-10 17:17:34 -0500 |
commit | b7097d21c25a48c9d209548ac8afdc09b1679457 (patch) | |
tree | ee7a911622c333818a9ac30f2cae68aee7eb6601 /models-interactions/model-impl/appc/src/test | |
parent | f04d89c55ab4dfa94dfed1cc9b65471d1d3140c5 (diff) |
More sonars in models
Addressed the following:
- make constructors protected
- check exception type
- too many assertions
- remove annotation lists
- use "<>"
- reduce cognitive complexity
- extract constant
- multiple method calls in one assert
- don't use eq() in verify()
- indentation
Issue-ID: POLICY-2905
Change-Id: I25bb3951f781250e9cdfe8f5f3b80cb63e129184
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-impl/appc/src/test')
2 files changed, 39 insertions, 99 deletions
diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java index 30d4ed910..686e6a416 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.function.BiConsumer; import org.junit.Test; public class CommonHeaderTest { @@ -94,67 +95,28 @@ public class CommonHeaderTest { assertEquals(commonHeader, clonedCommonHeader); - commonHeader.setApiVer(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setApiVer(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setApiVer(KANSAS); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setApiVer(KANSAS); - assertEquals(commonHeader, copiedCommonHeader); + checkField(KANSAS, CommonHeader::setApiVer); + checkField(flagSet, CommonHeader::setFlags); + checkField(DOROTHY, CommonHeader::setOriginatorId); + checkField(requestId, CommonHeader::setRequestId); + checkField(requestTrackSet, CommonHeader::setRequestTrack); + checkField(CAN_I_GO_HOME, CommonHeader::setSubRequestId); + checkField(timestamp, CommonHeader::setTimeStamp); + } - commonHeader.setFlags(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setFlags(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setFlags(flagSet); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setFlags(flagSet); - assertEquals(commonHeader, copiedCommonHeader); + private <T> void checkField(T value, BiConsumer<CommonHeader, T> setter) { + CommonHeader header1 = new CommonHeader(); + CommonHeader header2 = new CommonHeader(header1); - commonHeader.setOriginatorId(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setOriginatorId(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setOriginatorId(DOROTHY); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setOriginatorId(DOROTHY); - assertEquals(commonHeader, copiedCommonHeader); + setter.accept(header2, null); - commonHeader.setRequestId(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setRequestId(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setRequestId(requestId); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setRequestId(requestId); - assertEquals(commonHeader, copiedCommonHeader); + setter.accept(header1, value); + assertNotEquals(header1, header2); - commonHeader.setRequestTrack(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setRequestTrack(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setRequestTrack(requestTrackSet); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setRequestTrack(requestTrackSet); - assertEquals(commonHeader, copiedCommonHeader); + setter.accept(header2, value); + assertEquals(header1, header2); - commonHeader.setSubRequestId(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setSubRequestId(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setSubRequestId(CAN_I_GO_HOME); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setSubRequestId(CAN_I_GO_HOME); - assertEquals(commonHeader, copiedCommonHeader); - - commonHeader.setTimeStamp(null); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setTimeStamp(null); - assertEquals(commonHeader, copiedCommonHeader); - commonHeader.setTimeStamp(timestamp); - assertNotEquals(commonHeader, copiedCommonHeader); - copiedCommonHeader.setTimeStamp(timestamp); - assertEquals(commonHeader, copiedCommonHeader); + setter.accept(header1, null); + assertNotEquals(header1, header2); } } diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java index 43686a747..5bff56b78 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,6 +27,7 @@ import static org.junit.Assert.assertNotNull; import java.util.HashMap; import java.util.Map; +import java.util.function.BiConsumer; import org.junit.Test; public class RequestTest { @@ -77,49 +78,26 @@ public class RequestTest { assertNotEquals(request, null); assertNotEquals(request, (Object) "Hello"); - request.setCommonHeader(null); - assertNotEquals(request, copiedRequest); - copiedRequest.setCommonHeader(null); - assertEquals(request, copiedRequest); - request.setCommonHeader(commonHeader); - assertNotEquals(request, copiedRequest); - copiedRequest.setCommonHeader(commonHeader); - assertEquals(request, copiedRequest); + checkField(commonHeader, Request::setCommonHeader); + checkField(GO_TO_OZ, Request::setAction); + checkField(WIZARD, Request::setObjectId); + checkField("Oz", Request::setTargetId); + checkField(payload, Request::setPayload); + } - request.setAction(null); - assertNotEquals(request, copiedRequest); - copiedRequest.setAction(null); - assertEquals(request, copiedRequest); - request.setAction(GO_TO_OZ); - assertNotEquals(request, copiedRequest); - copiedRequest.setAction(GO_TO_OZ); - assertEquals(request, copiedRequest); + private <T> void checkField(T value, BiConsumer<Request, T> setter) { + Request request1 = new Request(); + Request request2 = new Request(); - request.setObjectId(null); - assertNotEquals(request, copiedRequest); - copiedRequest.setObjectId(null); - assertEquals(request, copiedRequest); - request.setObjectId(WIZARD); - assertNotEquals(request, copiedRequest); - copiedRequest.setObjectId(WIZARD); - assertEquals(request, copiedRequest); + setter.accept(request2, null); - request.setTargetId(null); - assertNotEquals(request, copiedRequest); - copiedRequest.setTargetId(null); - assertEquals(request, copiedRequest); - request.setTargetId("Oz"); - assertNotEquals(request, copiedRequest); - copiedRequest.setTargetId("Oz"); - assertEquals(request, copiedRequest); + setter.accept(request1, value); + assertNotEquals(request1, request2); - request.setPayload(new HashMap<>()); - assertNotEquals(request, copiedRequest); - copiedRequest.setPayload(new HashMap<>()); - assertEquals(request, copiedRequest); - request.setPayload(payload); - assertNotEquals(request, copiedRequest); - copiedRequest.setPayload(payload); - assertEquals(request, copiedRequest); + setter.accept(request2, value); + assertEquals(request1, request2); + + setter.accept(request1, null); + assertNotEquals(request1, request2); } } |