Skip to content

Commit 6dd5f91

Browse files
authored
Merge pull request #179 from oracle/resolve-sonar-issues
Resolve simple Sonar code issues
2 parents 172aea1 + 9845c19 commit 6dd5f91

32 files changed

+337
-317
lines changed

build-helper-mojo/src/test/java/com/oracle/wls/buildhelper/BuildHelperMojoTest.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.buildhelper;
@@ -26,7 +26,7 @@
2626
import static org.hamcrest.Matchers.notNullValue;
2727
import static org.hamcrest.Matchers.nullValue;
2828

29-
public class BuildHelperMojoTest {
29+
class BuildHelperMojoTest {
3030

3131
private final BuildHelperMojo mojo = new BuildHelperMojo();
3232
private final List<Memento> mementos = new ArrayList<>();
@@ -46,55 +46,55 @@ public void tearDown() {
4646
}
4747

4848
@Test
49-
public void helperImplementsMojo() {
49+
void helperImplementsMojo() {
5050
assertThat(mojo, Matchers.instanceOf(AbstractMojo.class));
5151
}
5252

5353
@Test
54-
public void mojoHasGoalAnnotation() {
54+
void mojoHasGoalAnnotation() {
5555
assertThat(mojoTestSupport.getClassAnnotation(), notNullValue());
5656
}
5757

5858
@Test
59-
public void mojoAnnotatedWithName() {
59+
void mojoAnnotatedWithName() {
6060
assertThat(mojoTestSupport.getClassAnnotation().get("name"), equalTo("copy"));
6161
}
6262

6363
@Test
64-
public void mojoAnnotatedWithDefaultPhase() {
64+
void mojoAnnotatedWithDefaultPhase() {
6565
assertThat(mojoTestSupport.getClassAnnotation().get("defaultPhase"), equalTo(PROCESS_RESOURCES));
6666
}
6767

6868
@Test
69-
public void hasRequiredSourceFileParameter() throws NoSuchFieldException {
69+
void hasRequiredSourceFileParameter() throws NoSuchFieldException {
7070
assertThat(mojoTestSupport.getParameterField("sourceFile").getType(), equalTo(String.class));
7171
assertThat(mojoTestSupport.getParameterAnnotation("sourceFile").get("required"), is(true));
7272
}
7373

7474
@Test
75-
public void hasAnnotatedTargetFileField_withNoDefault() throws NoSuchFieldException {
75+
void hasAnnotatedTargetFileField_withNoDefault() throws NoSuchFieldException {
7676
assertThat(mojoTestSupport.getParameterField("targetFile").getType(), equalTo(File.class));
7777
assertThat(mojoTestSupport.getParameterAnnotation("targetFile").get("defaultValue"), nullValue());
7878
}
7979

8080
@Test
81-
public void targetFileField_isRequired() throws NoSuchFieldException {
81+
void targetFileField_isRequired() throws NoSuchFieldException {
8282
assertThat(mojoTestSupport.getParameterAnnotation("targetFile").get("required"), is(true));
8383
}
8484

8585
@Test
86-
public void hasAnnotatedUserDirFileField_withNullDefault() throws NoSuchFieldException {
86+
void hasAnnotatedUserDirFileField_withNullDefault() throws NoSuchFieldException {
8787
assertThat(mojoTestSupport.getParameterField("userDir").getType(), equalTo(File.class));
8888
assertThat(mojoTestSupport.getParameterAnnotation("userDir").get("defaultValue"), nullValue());
8989
}
9090

9191
@Test
92-
public void userDirField_isNotRequired() throws NoSuchFieldException {
92+
void userDirField_isNotRequired() throws NoSuchFieldException {
9393
assertThat(mojoTestSupport.getParameterAnnotation("userDir").get("required"), nullValue());
9494
}
9595

9696
@Test
97-
public void whenSourceAndTargetAbsolute_useAbsolutePaths() throws Exception {
97+
void whenSourceAndTargetAbsolute_useAbsolutePaths() throws Exception {
9898
setMojoParameter("sourceFile", "/root/source");
9999
setMojoParameter("targetFile", new File("/root/target"));
100100

@@ -105,7 +105,7 @@ public void whenSourceAndTargetAbsolute_useAbsolutePaths() throws Exception {
105105
}
106106

107107
@Test
108-
public void whenSourcePathIsRelative_computeAbsoluteRelativeToUserDir() throws Exception {
108+
void whenSourcePathIsRelative_computeAbsoluteRelativeToUserDir() throws Exception {
109109
setMojoParameter("sourceFile", "source");
110110
setMojoParameter("targetFile", new File("/root/target"));
111111
setMojoParameter("userDir", new File("/root/nested"));
@@ -117,7 +117,7 @@ public void whenSourcePathIsRelative_computeAbsoluteRelativeToUserDir() throws E
117117
}
118118

119119
@Test
120-
public void whenSourcePathIsRelativeAndNoUserDir_useSystemProperty() throws Exception {
120+
void whenSourcePathIsRelativeAndNoUserDir_useSystemProperty() throws Exception {
121121
System.setProperty("user.dir", "/user");
122122
setMojoParameter("sourceFile", "source");
123123
setMojoParameter("targetFile", new File("/root/target"));

wls-exporter-core/src/main/java/com/oracle/wls/exporter/ConfigurationDisplay.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2021, 2022, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.exporter;
@@ -8,6 +8,10 @@
88

99
public class ConfigurationDisplay {
1010

11+
private ConfigurationDisplay() {
12+
// no-op
13+
}
14+
1115
public static void displayConfiguration(OutputStream outputStream) {
1216
try (PrintStream ps = new PrintStream(outputStream)) {
1317
ps.println("<p>Current Configuration</p>");

wls-exporter-core/src/main/java/com/oracle/wls/exporter/DemoInputs.java

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
* @author Russell Gold
88
*/
99
class DemoInputs {
10+
11+
private DemoInputs() {
12+
// no-op
13+
}
14+
1015
@SuppressWarnings("unused")
1116
static final String YAML_STRING = "---\n" +
1217
"startDelaySeconds: 5\n" +

wls-exporter-core/src/main/java/com/oracle/wls/exporter/LiveConfiguration.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
*/
2525
public class LiveConfiguration {
2626

27+
private LiveConfiguration() {
28+
// no-op
29+
}
30+
2731
/** The address used to access WLS (cannot use the address found in the request due to potential server-side request forgery. */
2832
static final String WLS_HOST;
2933

@@ -190,7 +194,7 @@ public static void updateConfiguration() {
190194
installNewConfiguration(updater.getUpdate());
191195
}
192196

193-
private synchronized static void installNewConfiguration(ConfigurationUpdate update) {
197+
private static synchronized void installNewConfiguration(ConfigurationUpdate update) {
194198
if (update.getTimestamp() > timestamp) {
195199
getConfig().replace(toConfiguration(update.getConfiguration()));
196200
timestamp = update.getTimestamp();

wls-exporter-core/src/main/java/com/oracle/wls/exporter/domain/MapUtils.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017, 2020, Oracle and/or its affiliates.
1+
// Copyright (c) 2017, 2022, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.exporter.domain;
@@ -13,6 +13,9 @@
1313
*/
1414
public class MapUtils {
1515

16+
private MapUtils() {
17+
// no-op
18+
}
1619
private static final String ILLEGAL_VALUE_FORMAT = "Illegal value for %s: %s. Value must be %s";
1720

1821
/**
@@ -51,8 +54,8 @@ static Boolean getBooleanValue(Map<String, Object> map, String key) {
5154
throw createBadTypeException(key, value, "a boolean");
5255
}
5356

54-
private final static String[] TRUE_VALUES = {"true", "t", "yes", "on", "y"};
55-
private final static String[] FALSE_VALUES = {"false", "f", "no", "off", "n"};
57+
private static final String[] TRUE_VALUES = {"true", "t", "yes", "on", "y"};
58+
private static final String[] FALSE_VALUES = {"false", "f", "no", "off", "n"};
5659

5760
private static boolean inValues(Object candidate, String... matches) {
5861
for (String match : matches)

wls-exporter-core/src/main/java/com/oracle/wls/exporter/domain/SnakeCaseUtil.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017, 2020, Oracle and/or its affiliates.
1+
// Copyright (c) 2017, 2022, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.exporter.domain;
@@ -11,6 +11,11 @@
1111
* @author Russell Gold
1212
*/
1313
public class SnakeCaseUtil {
14+
15+
private SnakeCaseUtil() {
16+
// no-op
17+
}
18+
1419
private static final Pattern SNAKE_CASE_PATTERN = Pattern.compile("([a-z0-9])([A-Z])");
1520

1621
static String convert(String s) {

wls-exporter-core/src/main/java/com/oracle/wls/exporter/webapp/ServletUtils.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2021, 2022, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package com.oracle.wls.exporter.webapp;
@@ -12,6 +12,10 @@
1212

1313
public class ServletUtils {
1414

15+
private ServletUtils() {
16+
// no-op
17+
}
18+
1519
/** The path to the configuration file within the web application. */
1620
public static final String CONFIG_YML = "/config.yml";
1721

wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationFormCallTest.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static org.hamcrest.Matchers.startsWith;
2121
import static org.junit.jupiter.api.Assertions.assertThrows;
2222

23-
public class ConfigurationFormCallTest {
23+
class ConfigurationFormCallTest {
2424

2525
private static final String CONFIGURATION =
2626
"hostName: " + HOST_NAME + "\n" +
@@ -72,7 +72,7 @@ public void setUp() {
7272
}
7373

7474
@Test
75-
public void whenNoConfigurationSpecified_reportFailure() {
75+
void whenNoConfigurationSpecified_reportFailure() {
7676
assertThrows(RuntimeException.class, () -> handleConfigurationFormCall(context));
7777
}
7878

@@ -83,35 +83,35 @@ private void handleConfigurationFormCall(InvocationContextStub context) throws I
8383
}
8484

8585
@Test
86-
public void whenRequestUsesHttp_authenticateWithHttp() throws Exception {
86+
void whenRequestUsesHttp_authenticateWithHttp() throws Exception {
8787
handleConfigurationFormCall(context.withConfigurationForm("replace", CONFIGURATION));
8888

8989
assertThat(factory.getClientUrl(), startsWith("http:"));
9090
}
9191

9292
@Test
93-
public void whenRequestUsesHttps_authenticateWithHttps() throws Exception {
93+
void whenRequestUsesHttps_authenticateWithHttps() throws Exception {
9494
handleConfigurationFormCall(context.withHttps().withConfigurationForm("replace", CONFIGURATION));
9595

9696
assertThat(factory.getClientUrl(), startsWith("https:"));
9797
}
9898

9999
@Test
100-
public void afterUploadWithReplace_useNewConfiguration() throws Exception {
100+
void afterUploadWithReplace_useNewConfiguration() throws Exception {
101101
handleConfigurationFormCall(context.withConfigurationForm("replace", CONFIGURATION));
102102

103103
assertThat(LiveConfiguration.asString(), equalTo(CONFIGURATION));
104104
}
105105

106106
@Test
107-
public void afterUpload_redirectToMainPage() throws Exception {
107+
void afterUpload_redirectToMainPage() throws Exception {
108108
handleConfigurationFormCall(context.withConfigurationForm("replace", CONFIGURATION));
109109

110110
assertThat(context.getRedirectLocation(), equalTo(WebAppConstants.MAIN_PAGE));
111111
}
112112

113113
@Test
114-
public void whenRestPortInaccessible_switchToSpecifiedPort() throws Exception {
114+
void whenRestPortInaccessible_switchToSpecifiedPort() throws Exception {
115115
LiveConfiguration.loadFromString(CONFIGURATION_WITH_REST_PORT);
116116
factory.throwConnectionFailure("localhost", REST_PORT);
117117

@@ -121,14 +121,14 @@ public void whenRestPortInaccessible_switchToSpecifiedPort() throws Exception {
121121
}
122122

123123
@Test
124-
public void afterUploadWithAppend_useCombinedConfiguration() throws Exception {
124+
void afterUploadWithAppend_useCombinedConfiguration() throws Exception {
125125
handleConfigurationFormCall(context.withConfigurationForm("append", ADDED_CONFIGURATION));
126126

127127
assertThat(LiveConfiguration.asString(), equalTo(COMBINED_CONFIGURATION));
128128
}
129129

130130
@Test
131-
public void whenSelectedFileIsNotYaml_reportError() throws Exception {
131+
void whenSelectedFileIsNotYaml_reportError() throws Exception {
132132
handleConfigurationFormCall(context.withConfigurationForm("replace", NON_YAML));
133133

134134
assertThat(context.getResponse(), containsString(ConfigurationException.NOT_YAML_FORMAT));
@@ -138,7 +138,7 @@ public void whenSelectedFileIsNotYaml_reportError() throws Exception {
138138
"this is not yaml\n";
139139

140140
@Test
141-
public void whenSelectedFileHasPartialYaml_reportError() throws Exception {
141+
void whenSelectedFileHasPartialYaml_reportError() throws Exception {
142142
handleConfigurationFormCall(context.withConfigurationForm("replace", PARTIAL_YAML));
143143

144144
assertThat(context.getResponse(), containsString(ConfigurationException.BAD_YAML_FORMAT));
@@ -148,7 +148,7 @@ public void whenSelectedFileHasPartialYaml_reportError() throws Exception {
148148
"queries:\nkey name\n";
149149

150150
@Test
151-
public void whenSelectedFileHasBadBooleanValue_reportError() throws Exception {
151+
void whenSelectedFileHasBadBooleanValue_reportError() throws Exception {
152152
handleConfigurationFormCall(context.withConfigurationForm("append", ADDED_CONFIGURATION_WITH_BAD_BOOLEAN));
153153

154154
assertThat(context.getResponse(), containsString(BAD_BOOLEAN_STRING));
@@ -162,14 +162,14 @@ public void whenSelectedFileHasBadBooleanValue_reportError() throws Exception {
162162
" values: [age, sex]\n";
163163

164164
@Test
165-
public void afterSelectedFileHasBadBooleanValue_configurationIsUnchanged() throws Exception {
165+
void afterSelectedFileHasBadBooleanValue_configurationIsUnchanged() throws Exception {
166166
handleConfigurationFormCall(context.withConfigurationForm("append", ADDED_CONFIGURATION_WITH_BAD_BOOLEAN));
167167

168168
assertThat(LiveConfiguration.asString(), equalTo(CONFIGURATION));
169169
}
170170

171171
@Test
172-
public void whenServerSends403StatusOnGet_returnToClient() throws Exception {
172+
void whenServerSends403StatusOnGet_returnToClient() throws Exception {
173173
factory.reportNotAuthorized();
174174

175175
handleConfigurationFormCall(context.withConfigurationForm("replace", CONFIGURATION));
@@ -178,7 +178,7 @@ public void whenServerSends403StatusOnGet_returnToClient() throws Exception {
178178
}
179179

180180
@Test
181-
public void whenServerSends401StatusOnGet_returnToClient() throws Exception {
181+
void whenServerSends401StatusOnGet_returnToClient() throws Exception {
182182
factory.reportAuthenticationRequired("Test-Realm");
183183

184184
handleConfigurationFormCall(context.withConfigurationForm("replace", CONFIGURATION));

wls-exporter-core/src/test/java/com/oracle/wls/exporter/ConfigurationPutCallTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ private void handleConfigurationPutCall(InvocationContextStub context) throws IO
5959
}
6060

6161
@Test
62-
public void whenSpecifiedConfigurationHasBadBooleanValue_reportError() throws Exception {
62+
void whenSpecifiedConfigurationHasBadBooleanValue_reportError() throws Exception {
6363
handleConfigurationPutCall(context.withConfiguration("application/yaml", CONFIGURATION_WITH_BAD_BOOLEAN));
6464

6565
assertThat(context.getResponseStatus(), equalTo(HttpURLConnection.HTTP_BAD_REQUEST));
6666
}
6767

6868
@Test
69-
public void updateSpecifiedConfiguration() throws Exception {
69+
void updateSpecifiedConfiguration() throws Exception {
7070
handleConfigurationPutCall(context.withConfiguration("application/yaml", YAML_CONFIGURATION));
7171

7272
assertThat(LiveConfiguration.asString(), equalTo(YAML_CONFIGURATION));
7373
}
7474

7575
@Test
76-
public void updateConfigurationWithJson() throws Exception {
76+
void updateConfigurationWithJson() throws Exception {
7777
handleConfigurationPutCall(context.withConfiguration("application/json", JSON_CONFIGURATION));
7878

7979
assertThat(LiveConfiguration.asString(), equalTo(YAML_CONFIGURATION));

0 commit comments

Comments
 (0)