Polish "Use Assert.state() with Supplier where possible"

Closes gh-10658
This commit is contained in:
Stephane Nicoll
2017-10-17 15:36:51 +02:00
parent 3b71393e0a
commit 2eba1c5f62
4 changed files with 8 additions and 7 deletions

View File

@@ -93,8 +93,8 @@ public final class CommandLineInvoker {
} }
File bin = new File(unpacked.listFiles()[0], "bin"); File bin = new File(unpacked.listFiles()[0], "bin");
File launchScript = new File(bin, isWindows() ? "spring.bat" : "spring"); File launchScript = new File(bin, isWindows() ? "spring.bat" : "spring");
Assert.state(launchScript.exists() && launchScript.isFile(), Assert.state(launchScript.exists() && launchScript.isFile(), () ->
() -> "Could not find CLI launch script " + launchScript.getAbsolutePath()); "Could not find CLI launch script " + launchScript.getAbsolutePath());
return launchScript; return launchScript;
} }

View File

@@ -109,8 +109,8 @@ class DefinitionsParser {
private void addDefinition(AnnotatedElement element, Definition definition, private void addDefinition(AnnotatedElement element, Definition definition,
String type) { String type) {
boolean isNewDefinition = this.definitions.add(definition); boolean isNewDefinition = this.definitions.add(definition);
Assert.state(isNewDefinition, Assert.state(isNewDefinition, () ->
() -> "Duplicate " + type + " definition " + definition); "Duplicate " + type + " definition " + definition);
if (element instanceof Field) { if (element instanceof Field) {
Field field = (Field) element; Field field = (Field) element;
this.definitionFields.put(definition, field); this.definitionFields.put(definition, field);

View File

@@ -91,7 +91,8 @@ public class ApplicationTemp {
Assert.state(StringUtils.hasLength(property), "No 'java.io.tmpdir' property set"); Assert.state(StringUtils.hasLength(property), "No 'java.io.tmpdir' property set");
File file = new File(property); File file = new File(property);
Assert.state(file.exists(), () -> "Temp directory" + file + " does not exist"); Assert.state(file.exists(), () -> "Temp directory" + file + " does not exist");
Assert.state(file.isDirectory(), () -> "Temp location " + file + " is not a directory"); Assert.state(file.isDirectory(), () -> "Temp location " + file
+ " is not a directory");
return file; return file;
} }

View File

@@ -92,8 +92,8 @@ public class JettyWebServer implements WebServer {
@Override @Override
protected void doStart() throws Exception { protected void doStart() throws Exception {
for (Connector connector : JettyWebServer.this.connectors) { for (Connector connector : JettyWebServer.this.connectors) {
Assert.state(connector.isStopped(), () -> "Connector " + connector Assert.state(connector.isStopped(), () -> "Connector "
+ " has been started prematurely"); + connector + " has been started prematurely");
} }
JettyWebServer.this.server.setConnectors(null); JettyWebServer.this.server.setConnectors(null);
} }