HookTestCase: use assertions instead of if-condition and fail
Instead of testing for an error condition with an if-statements and then explicitly calling `fail()`, use the Truth library's `assert_()` method. Also remove a couple of unnecessary `final` modifiers. Change-Id: I523768cc48254b1bac0d5b70478309075dd897e7
This commit is contained in:
@@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.tools.hooks;
|
package com.google.gerrit.server.tools.hooks;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static com.google.common.truth.Truth.assert_;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
@@ -99,24 +99,29 @@ public abstract class HookTestCase extends LocalDiskRepositoryTestCase {
|
|||||||
return hook;
|
return hook;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String scproot = "com/google/gerrit/server/tools/root";
|
String scproot = "com/google/gerrit/server/tools/root";
|
||||||
final String path = scproot + "/hooks/" + name;
|
String path = scproot + "/hooks/" + name;
|
||||||
|
String errorMessage = "Cannot locate " + path + " in CLASSPATH";
|
||||||
URL url = cl().getResource(path);
|
URL url = cl().getResource(path);
|
||||||
if (url == null) {
|
assert_()
|
||||||
fail("Cannot locate " + path + " in CLASSPATH");
|
.withFailureMessage(errorMessage)
|
||||||
}
|
.that(url).isNotNull();
|
||||||
|
|
||||||
if ("file".equals(url.getProtocol())) {
|
String protocol = url.getProtocol();
|
||||||
|
assert_()
|
||||||
|
.withFailureMessage("Cannot invoke " + url)
|
||||||
|
.that(protocol).isAnyOf("file", "jar");
|
||||||
|
|
||||||
|
if ("file".equals(protocol)) {
|
||||||
hook = new File(url.getPath());
|
hook = new File(url.getPath());
|
||||||
if (!hook.isFile()) {
|
assert_()
|
||||||
fail("Cannot locate " + path + " in CLASSPATH");
|
.withFailureMessage(errorMessage)
|
||||||
}
|
.that(hook.isFile()).isTrue();
|
||||||
long time = hook.lastModified();
|
long time = hook.lastModified();
|
||||||
hook.setExecutable(true);
|
hook.setExecutable(true);
|
||||||
hook.setLastModified(time);
|
hook.setLastModified(time);
|
||||||
hooks.put(name, hook);
|
hooks.put(name, hook);
|
||||||
return hook;
|
} else if ("jar".equals(protocol)) {
|
||||||
} else if ("jar".equals(url.getProtocol())) {
|
|
||||||
InputStream in = url.openStream();
|
InputStream in = url.openStream();
|
||||||
try {
|
try {
|
||||||
hook = File.createTempFile("hook_", ".sh");
|
hook = File.createTempFile("hook_", ".sh");
|
||||||
@@ -132,11 +137,8 @@ public abstract class HookTestCase extends LocalDiskRepositoryTestCase {
|
|||||||
}
|
}
|
||||||
hook.setExecutable(true);
|
hook.setExecutable(true);
|
||||||
hooks.put(name, hook);
|
hooks.put(name, hook);
|
||||||
return hook;
|
|
||||||
} else {
|
|
||||||
fail("Cannot invoke " + url);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return hook;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClassLoader cl() {
|
private ClassLoader cl() {
|
||||||
|
|||||||
Reference in New Issue
Block a user