### Question:
Stats { public static AtomicLong exportLong(String name) { final AtomicLong longVar = new AtomicLong(0L); export(new StatImpl<Long>(name) { @Override public Long read() { return longVar.get(); } }); return longVar; }  static String normalizeName(String name); static Stat<T> export(Stat<T> var); static AtomicInteger exportInt(final String name); static AtomicLong exportLong(String name); static Iterable<Stat<?>> getVariables(); @VisibleForTesting static void flush(); @VisibleForTesting static Stat<T> getVariable(String name); static final StatsProvider STATS_PROVIDER; static final StatRegistry STAT_REGISTRY; }### Answer:
@Test public void testSimpleExport() { AtomicLong var = Stats.exportLong("test_long"); assertCounter("test_long", 0); var.incrementAndGet(); assertCounter("test_long", 1); var.addAndGet(100); assertCounter("test_long", 101); }
@Test public void testSupportedSpecialChars() { AtomicLong hyphen = Stats.exportLong("c-d"); AtomicLong slash = Stats.exportLong("d/f"); AtomicLong dot = Stats.exportLong("f.g"); hyphen.incrementAndGet(); slash.incrementAndGet(); dot.incrementAndGet(); assertCounter("c-d", 1); assertCounter("d/f", 1); assertCounter("f.g", 1); }
@Test public void testNotSame() { AtomicLong firstExport = Stats.exportLong("somevar"); firstExport.incrementAndGet(); firstExport.incrementAndGet(); assertCounter("somevar", 2L); AtomicLong secondExport = Stats.exportLong("somevar"); assertNotSame(firstExport, secondExport); secondExport.incrementAndGet(); assertCounter("somevar", 2L); }
@Test public void testNormalizesSpace() { AtomicLong leading = Stats.exportLong(" leading space"); AtomicLong trailing = Stats.exportLong("trailing space "); AtomicLong surround = Stats.exportLong(" surround space "); leading.incrementAndGet(); trailing.incrementAndGet(); surround.incrementAndGet(); assertCounter("__leading_space", 1); assertCounter("trailing_space___", 1); assertCounter("___surround_space___", 1); }
@Test public void testNormalizesIllegalChars() { AtomicLong colon = Stats.exportLong("a:b"); AtomicLong plus = Stats.exportLong("b+c"); colon.incrementAndGet(); plus.incrementAndGet(); assertCounter("a_b", 1); assertCounter("b_c", 1); }