aboutsummaryrefslogtreecommitdiffstats
path: root/vespalog
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2020-03-26 16:36:34 +0100
committergjoranv <gv@verizonmedia.com>2020-03-26 16:36:34 +0100
commit7a85c82246abcbe010a5422951a1164d87a0ad66 (patch)
tree37a380f686b74ba4cae1c9d806cb9f664cc71315 /vespalog
parent231eb9b109b18e80962fecc20915d970373dee47 (diff)
Remove some code inspection warnings.
Diffstat (limited to 'vespalog')
-rw-r--r--vespalog/src/test/java/com/yahoo/log/VespaLogHandlerTestCase.java65
1 files changed, 26 insertions, 39 deletions
diff --git a/vespalog/src/test/java/com/yahoo/log/VespaLogHandlerTestCase.java b/vespalog/src/test/java/com/yahoo/log/VespaLogHandlerTestCase.java
index c0dd856b634..220e5e9271e 100644
--- a/vespalog/src/test/java/com/yahoo/log/VespaLogHandlerTestCase.java
+++ b/vespalog/src/test/java/com/yahoo/log/VespaLogHandlerTestCase.java
@@ -13,6 +13,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.BrokenBarrierException;
@@ -32,20 +33,20 @@ import static org.junit.Assert.fail;
* @author Bjorn Borud
*/
public class VespaLogHandlerTestCase {
- protected static String hostname;
- protected static String pid;
+ private static String hostname;
+ private static String pid;
- protected static LogRecord record1;
- protected static String record1String;
+ static LogRecord record1;
+ static String record1String;
- protected static LogRecord record2;
- protected static String record2String;
+ static LogRecord record2;
+ private static String record2String;
- protected static LogRecord record3;
- protected static String record3String;
+ private static LogRecord record3;
+ private static String record3String;
- protected static LogRecord record4;
- protected static String record4String;
+ private static LogRecord record4;
+ private static String record4String;
static {
hostname = Util.getHostName();
@@ -139,7 +140,7 @@ public class VespaLogHandlerTestCase {
}
@Test
- public void testFallback() throws FileNotFoundException {
+ public void testFallback() {
File file = new File("mydir2");
file.delete();
assertTrue(file.mkdir());
@@ -157,7 +158,7 @@ public class VespaLogHandlerTestCase {
* Perform simple test
*/
@Test
- public void testLogCtl () throws InterruptedException, FileNotFoundException {
+ public void testLogCtl () {
MockLevelController ctl = new MockLevelController();
MockLevelControllerRepo ctlRepo = new MockLevelControllerRepo(ctl);
MockLogTarget target = new MockLogTarget();
@@ -203,7 +204,7 @@ public class VespaLogHandlerTestCase {
@Test
public void testRotate () throws IOException {
// Doesn't work in Windows. TODO: Fix the logging stuff
- if (System.getProperty("os.name").toLowerCase().indexOf("win")>=0)
+ if (System.getProperty("os.name").toLowerCase().contains("win"))
return;
try {
VespaLogHandler h
@@ -269,10 +270,8 @@ public class VespaLogHandlerTestCase {
);
class LogRacer implements Runnable {
- private int n;
- public LogRacer (int n) {
- this.n = n;
+ private LogRacer() {
}
public void run () {
@@ -285,7 +284,7 @@ public class VespaLogHandlerTestCase {
}
}
- public void logLikeCrazy () {
+ void logLikeCrazy() {
for (int j = 0; j < numLogEntries; j++) {
try {
h.publish(record1);
@@ -299,7 +298,7 @@ public class VespaLogHandlerTestCase {
}
for (int i = 0; i < numThreads; i++) {
- t[i] = new Thread(new LogRacer(i));
+ t[i] = new Thread(new LogRacer());
t[i].start();
}
@@ -361,35 +360,23 @@ public class VespaLogHandlerTestCase {
*
*/
protected static String[] readFile (String fileName) {
- BufferedReader br = null;
- List<String> lines = new LinkedList<String>();
- try {
- br = new BufferedReader(
- new InputStreamReader(new FileInputStream(new File(fileName)), "UTF-8"));
+ List<String> lines = new LinkedList<>();
+ try (BufferedReader br = new BufferedReader(
+ new InputStreamReader(new FileInputStream(new File(fileName)), StandardCharsets.UTF_8))) {
for (String line = br.readLine();
line != null;
- line = br.readLine())
- {
+ line = br.readLine()) {
lines.add(line);
}
- return lines.toArray(new String[lines.size()]);
- }
- catch (Throwable e) {
+ return lines.toArray(new String[0]);
+ } catch (Throwable e) {
return new String[0];
}
- finally {
- if (br != null) {
- try {
- br.close();
- }
- catch (IOException e) {}
- }
- }
}
private static class MockLevelControllerRepo implements LevelControllerRepo {
private LevelController levelController;
- public MockLevelControllerRepo(LevelController controller) {
+ MockLevelControllerRepo(LevelController controller) {
this.levelController = controller;
}
@@ -411,7 +398,7 @@ public class VespaLogHandlerTestCase {
return (level.equals(logLevel));
}
- public void setShouldLog(Level level) {
+ void setShouldLog(Level level) {
this.logLevel = level;
}
@@ -431,7 +418,7 @@ public class VespaLogHandlerTestCase {
private static class MockLogTarget implements LogTarget {
private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- public String[] getLines() {
+ String[] getLines() {
return baos.toString().split("\n");
}
@Override