From 445f3207c1e1877850ae7c73336bd57b4ba1e86f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Weing=C3=A4rtner?= Date: Thu, 11 Aug 2016 14:24:06 -0300 Subject: [PATCH] Fix bugs reported by sonar --- ...oudStackClientRequestRuntimeException.java | 6 +- ...acheCloudStackApiCommandParameterTest.java | 59 +++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/test/java/br/com/autonomiccs/apacheCloudStack/client/ApacheCloudStackApiCommandParameterTest.java diff --git a/src/main/java/br/com/autonomiccs/apacheCloudStack/ApacheCloudStackClientRequestRuntimeException.java b/src/main/java/br/com/autonomiccs/apacheCloudStack/ApacheCloudStackClientRequestRuntimeException.java index 4915d7d..a162dc0 100644 --- a/src/main/java/br/com/autonomiccs/apacheCloudStack/ApacheCloudStackClientRequestRuntimeException.java +++ b/src/main/java/br/com/autonomiccs/apacheCloudStack/ApacheCloudStackClientRequestRuntimeException.java @@ -33,16 +33,16 @@ public class ApacheCloudStackClientRequestRuntimeException extends RuntimeExcept /** * Status of the HTTP request that generated this exception */ - private int statusCode; + private final int statusCode; /** * Response of the HTTP request that generated this exception */ - private String response; + private final String response; /** * Command request that generated the error */ - private String commandRequest; + private final String commandRequest; public ApacheCloudStackClientRequestRuntimeException(int statusCode, String responseAsString, String commandRequest) { this.statusCode = statusCode; diff --git a/src/test/java/br/com/autonomiccs/apacheCloudStack/client/ApacheCloudStackApiCommandParameterTest.java b/src/test/java/br/com/autonomiccs/apacheCloudStack/client/ApacheCloudStackApiCommandParameterTest.java new file mode 100644 index 0000000..998ad01 --- /dev/null +++ b/src/test/java/br/com/autonomiccs/apacheCloudStack/client/ApacheCloudStackApiCommandParameterTest.java @@ -0,0 +1,59 @@ +/* + * Apache CloudStack Java Client + * Copyright (C) 2016 Autonomiccs, Inc. + * + * Licensed to the Autonomiccs, Inc. under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The Autonomiccs, Inc. 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 br.com.autonomiccs.apacheCloudStack.client; + +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class ApacheCloudStackApiCommandParameterTest { + + + @Test + public void equalsTest() { + ApacheCloudStackApiCommandParameter apacheCloudStackApiCommandParameter1 = new ApacheCloudStackApiCommandParameter("param1", null); + ApacheCloudStackApiCommandParameter apacheCloudStackApiCommandParameter2 = new ApacheCloudStackApiCommandParameter("param1", "value"); + + Assert.assertEquals(apacheCloudStackApiCommandParameter1, apacheCloudStackApiCommandParameter2); + } + + @Test + public void hashCodeTest() { + ApacheCloudStackApiCommandParameter apacheCloudStackApiCommandParameter = new ApacheCloudStackApiCommandParameter("param1", "value"); + HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(); + hashCodeBuilder.append("param1"); + + Assert.assertEquals(hashCodeBuilder.toHashCode(), apacheCloudStackApiCommandParameter.hashCode()); + + } + + @Test + public void compareToTest() { + ApacheCloudStackApiCommandParameter apacheCloudStackApiCommandParameter = new ApacheCloudStackApiCommandParameter("param1", "value"); + ApacheCloudStackApiCommandParameter apacheCloudStackApiCommandParameterOther = new ApacheCloudStackApiCommandParameter("param2", "value"); + + Assert.assertEquals(-1, apacheCloudStackApiCommandParameter.compareTo(apacheCloudStackApiCommandParameterOther)); + } +}