Merge branch '1.1.x'

This commit is contained in:
Phillip Webb 2014-08-18 17:55:21 -07:00
commit fc7823bc42
3 changed files with 53 additions and 10 deletions

View File

@ -47,7 +47,7 @@ public class DefaultCounterService implements CounterService {
@Override
public void reset(String metricName) {
this.writer.increment(new Delta<Long>(wrap(metricName), 0L));
this.writer.reset(wrap(metricName));
}
private String wrap(String metricName) {

View File

@ -17,7 +17,10 @@
package org.springframework.boot.actuate.metrics.writer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
@ -26,6 +29,7 @@ import static org.mockito.Mockito.verify;
/**
* Tests for {@link DefaultCounterService}.
*/
@RunWith(MockitoJUnitRunner.class)
public class DefaultCounterServiceTests {
private final MetricWriter repository = mock(MetricWriter.class);
@ -33,22 +37,28 @@ public class DefaultCounterServiceTests {
private final DefaultCounterService service = new DefaultCounterService(
this.repository);
@Captor
private ArgumentCaptor<Delta<Number>> captor;
@Test
public void incrementPrependsCounter() {
this.service.increment("foo");
@SuppressWarnings("rawtypes")
ArgumentCaptor<Delta> captor = ArgumentCaptor.forClass(Delta.class);
verify(this.repository).increment(captor.capture());
assertEquals("counter.foo", captor.getValue().getName());
verify(this.repository).increment(this.captor.capture());
assertEquals("counter.foo", this.captor.getValue().getName());
assertEquals(1L, this.captor.getValue().getValue());
}
@Test
public void decrementPrependsCounter() {
this.service.decrement("foo");
@SuppressWarnings("rawtypes")
ArgumentCaptor<Delta> captor = ArgumentCaptor.forClass(Delta.class);
verify(this.repository).increment(captor.capture());
assertEquals("counter.foo", captor.getValue().getName());
assertEquals(-1L, captor.getValue().getValue());
verify(this.repository).increment(this.captor.capture());
assertEquals("counter.foo", this.captor.getValue().getName());
assertEquals(-1L, this.captor.getValue().getValue());
}
@Test
public void resetResetsCounter() throws Exception {
this.service.reset("foo");
verify(this.repository).reset("counter.foo");
}
}

View File

@ -63,6 +63,39 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>clean-samples</id>
<phase>clean</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete includeemptydirs="true">
<fileset dir="${main.basedir}/spring-boot-samples" includes="**/target/" />
</delete>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>clean-samples</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>