/*
 * Copyright 2017, Google Inc.
 * 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
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 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.opencensus.stats;

import io.opencensus.stats.Measure.MeasureDouble;
import io.opencensus.tags.Tag;
import io.opencensus.tags.Tag.TagString;
import io.opencensus.tags.TagContext;
import io.opencensus.tags.TagKey.TagKeyString;
import io.opencensus.tags.TagValueString;
import java.util.Collections;
import java.util.Iterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Tests for {@link StatsRecorder#getNoopStatsRecorder}. */
@RunWith(JUnit4.class)
public final class NoopStatsRecorderTest {
  private static final TagString TAG =
      TagString.create(TagKeyString.create("key"), TagValueString.create("value"));
  private static final MeasureDouble MEASURE =
      Measure.MeasureDouble.create("my measure", "description", "s");

  private final TagContext tagContext =
      new TagContext() {

        @Override
        public Iterator<Tag> unsafeGetIterator() {
          return Collections.<Tag>singleton(TAG).iterator();
        }
      };

  @Rule public final ExpectedException thrown = ExpectedException.none();

  @Test
  public void defaultRecord() {
    StatsRecorder.getNoopStatsRecorder()
        .record(tagContext, MeasureMap.builder().set(MEASURE, 5).build());
  }

  @Test
  public void defaultRecord_DisallowNullTagContext() {
    MeasureMap measures = MeasureMap.builder().set(MEASURE, 6).build();
    thrown.expect(NullPointerException.class);
    StatsRecorder.getNoopStatsRecorder().record(null, measures);
  }

  @Test
  public void defaultRecord_DisallowNullMeasureMap() {
    thrown.expect(NullPointerException.class);
    StatsRecorder.getNoopStatsRecorder().record(tagContext, null);
  }
}

@@ -1749,32 +1749,25 @@
 public void 
-defaultR
+r
 ecord() %7B%0A  
@@ -1903,32 +1903,176 @@
 public void 
-defaultR
+recordWithCurrentContext() %7B%0A    StatsRecorder.getNoopStatsRecorder().record(MeasureMap.builder().set(MEASURE, 6).build());%0A  %7D%0A%0A  @Test%0A  public void r
 ecord_Disall
@@ -2144,33 +2144,33 @@
 ().set(MEASURE, 
-6
+7
 ).build();%0A    t
@@ -2307,16 +2307,9 @@
 oid 
-defaultR
+r
 ecor
@@ -2454,11 +2454,192 @@
 ll);%0A  %7D
+%0A%0A  @Test%0A  public void recordWithCurrentContext_DisallowNullMeasureMap() %7B%0A    thrown.expect(NullPointerException.class);%0A    StatsRecorder.getNoopStatsRecorder().record(null);%0A  %7D
 %0A%7D%0A

Add more tests for NoopStatsRecorder.