/*
 * Copyright 2011-2016 Frank W. Rahn and the project authors.
 *
 * 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 de.rahn.finances.commons.metrics;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;

import java.util.SortedMap;
import java.util.TreeMap;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.codahale.metrics.UniformReservoir;

/**
 * Test, des Exporters.
 * 
 * @author Frank W. Rahn
 */
@RunWith(MockitoJUnitRunner.class)
public class MetricsExporterServiceTest {

	@Mock
	private MetricRegistry registry;

	@InjectMocks
	private MetricsExporterService exporter = new MetricsExporterService();

	private <V> SortedMap<String, V> singletonMap(String name, V value) {
		TreeMap<String, V> map = new TreeMap<>();
		map.put(name, value);

		return map;
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		when(registry.remove(anyString())).thenReturn(true);
		when(registry.getGauges()).thenReturn(singletonMap("gauges", () -> 4711));
		when(registry.getCounters()).thenReturn(singletonMap("counter", new Counter()));
		when(registry.getHistograms()).thenReturn(singletonMap("histogram", new Histogram(new UniformReservoir())));
		when(registry.getMeters()).thenReturn(singletonMap("meter", new Meter()));
		when(registry.getTimers()).thenReturn(singletonMap("timer", new Timer()));

		exporter.initialize();
	}

	/**
	 * Test method for {@link MetricsExporterService#exportMetrics()}.
	 */
	@Test
	public void testExportMetrics() {
		exporter.exportMetrics();

		assertThat(registry.getMetrics(), notNullValue());
		assertThat(registry.getMetrics().keySet(), empty());
	}

}
@@ -681,113 +681,35 @@
 org.
-hamcrest.Matchers.empty;%0Aimport static org.hamcrest.Matchers.notNullValue;%0Aimport static org.junit
+assertj.core.api
 .Assert
+ions
 .ass
@@ -955,39 +955,162 @@
 org.
-mockito.InjectMocks;%0Aimport org
+springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.boot.test.context.SpringBootTest;%0Aimport org.springframework.boot.test.mock
 .moc
@@ -1118,16 +1118,20 @@
 ito.Mock
+Bean
 ;%0Aimport
@@ -1139,36 +1139,50 @@
 org.
-mockito.runners.MockitoJUnit
+springframework.test.context.junit4.Spring
 Runn
@@ -1423,16 +1423,78 @@
 rvoir;%0A%0A
+import de.rahn.finances.commons.config.CommonsConfiguration;%0A%0A
 /**%0A * T
@@ -1515,17 +1515,16 @@
 ters.%0A *
- 
 %0A * @aut
@@ -1558,20 +1558,14 @@
 ith(
-MockitoJUnit
+Spring
 Runn
@@ -1574,16 +1574,70 @@
 .class)%0A
+@SpringBootTest(classes = CommonsConfiguration.class)%0A
 public c
@@ -1677,16 +1677,20 @@
 %0A%0A%09@Mock
+Bean
 %0A%09privat
@@ -1723,19 +1723,17 @@
 %0A%0A%09@
-InjectMocks
+Autowired
 %0A%09pr
@@ -2535,34 +2535,8 @@
 )));
-%0A%0A%09%09exporter.initialize();
 %0A%09%7D%0A
@@ -2723,24 +2723,20 @@
 cs()
-, n
+).isN
 otNull
-Value()
+(
 );%0A%09
@@ -2781,18 +2781,19 @@
 et()
-, e
+).isE
 mpty()
-)
 ;%0A%09%7D

Test angepasst