Polish
This commit is contained in:
@@ -275,6 +275,7 @@ public class HealthIndicatorAutoConfiguration {
|
||||
public DiskSpaceHealthIndicatorProperties diskSpaceHealthIndicatorProperties() {
|
||||
return new DiskSpaceHealthIndicatorProperties();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,19 +37,12 @@ public class DiskSpaceHealthIndicatorProperties {
|
||||
}
|
||||
|
||||
public void setPath(File path) {
|
||||
if (!path.exists()) {
|
||||
throw new IllegalArgumentException(String.format("Path '%s' does not exist",
|
||||
path));
|
||||
}
|
||||
if (!path.canRead()) {
|
||||
throw new IllegalStateException(String.format("Path '%s' cannot be read",
|
||||
path));
|
||||
}
|
||||
Assert.isTrue(path.exists(), "Path '" + path + "' does not exist");
|
||||
Assert.isTrue(path.canRead(), "Path '" + path + "' cannot be read");
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public long getThreshold() {
|
||||
|
||||
return this.threshold;
|
||||
}
|
||||
|
||||
@@ -57,4 +50,5 @@ public class DiskSpaceHealthIndicatorProperties {
|
||||
Assert.isTrue(threshold >= 0, "threshold must be greater than 0");
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
* Tests for {@link DiskSpaceHealthIndicator}.
|
||||
@@ -43,22 +43,21 @@ public class DiskSpaceHealthIndicatorTests {
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Mock
|
||||
File fileMock;
|
||||
private File fileMock;
|
||||
|
||||
HealthIndicator healthIndicator;
|
||||
private HealthIndicator healthIndicator;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(this.fileMock.exists()).thenReturn(true);
|
||||
when(this.fileMock.canRead()).thenReturn(true);
|
||||
given(this.fileMock.exists()).willReturn(true);
|
||||
given(this.fileMock.canRead()).willReturn(true);
|
||||
this.healthIndicator = new DiskSpaceHealthIndicator(createProperties(
|
||||
this.fileMock, THRESHOLD_BYTES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void diskSpaceIsUp() throws Exception {
|
||||
when(this.fileMock.getFreeSpace()).thenReturn(THRESHOLD_BYTES + 10);
|
||||
|
||||
given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES + 10);
|
||||
Health health = this.healthIndicator.health();
|
||||
assertEquals(Status.UP, health.getStatus());
|
||||
assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold"));
|
||||
@@ -67,8 +66,7 @@ public class DiskSpaceHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void diskSpaceIsDown() throws Exception {
|
||||
when(this.fileMock.getFreeSpace()).thenReturn(THRESHOLD_BYTES - 10);
|
||||
|
||||
given(this.fileMock.getFreeSpace()).willReturn(THRESHOLD_BYTES - 10);
|
||||
Health health = this.healthIndicator.health();
|
||||
assertEquals(Status.DOWN, health.getStatus());
|
||||
assertEquals(THRESHOLD_BYTES, health.getDetails().get("threshold"));
|
||||
@@ -81,4 +79,5 @@ public class DiskSpaceHealthIndicatorTests {
|
||||
properties.setThreshold(threshold);
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user