/**
 * Copyright 2017 Pivotal Software, Inc.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micrometer.statsd;

import io.micrometer.core.instrument.Meter;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Subscriber;

import java.util.Collections;
import java.util.concurrent.atomic.AtomicInteger;

import static org.mockito.Mockito.*;

class StatsdGaugeTest {


    private AtomicInteger value = new AtomicInteger(1);

    private StatsdLineBuilder lineBuilder = mock(StatsdLineBuilder.class);
    private Subscriber<String> publisher = mock(Subscriber.class);

    @Test
    void shouldAlwaysPublishValue() {
        StatsdGauge<?> alwaysPublishingGauge = gauge(true);

        alwaysPublishingGauge.poll();
        alwaysPublishingGauge.poll();

        verify(publisher, times(2)).onNext(any());
    }

    @Test
    void shoulOnlyPublishValue_WhenValueChanges() {
        StatsdGauge<?> guagePublishingOnChange = gauge(false);

        guagePublishingOnChange.poll();
        guagePublishingOnChange.poll();

        verify(publisher, times(1)).onNext(any());

        //update value and expect the publisher to be called again
        value.incrementAndGet();
        guagePublishingOnChange.poll();


        verify(publisher, times(2)).onNext(any());
    }


    private StatsdGauge<?> gauge(boolean alwaysPublish) {
        Meter.Id meterId = new Meter.Id("test", Collections.emptyList(), null, null, Meter.Type.GAUGE);
        return new StatsdGauge<>(meterId, lineBuilder, publisher, value, AtomicInteger::get, alwaysPublish);
    }

}
@@ -1371,16 +1371,17 @@
 id shoul
+d
 OnlyPubl
@@ -1434,18 +1434,18 @@
 uge%3C?%3E g
-u
 a
+u
 gePublis
@@ -1475,34 +1475,34 @@
 lse);%0A%0A        g
-u
 a
+u
 gePublishingOnCh
@@ -1515,34 +1515,34 @@
 oll();%0A        g
-u
 a
+u
 gePublishingOnCh
@@ -1716,18 +1716,18 @@
        g
-u
 a
+u
 gePublis
@@ -2087,8 +2087,9 @@
     %7D%0A%0A%7D
+%0A

Fix typos