From ed6ea96d7e1561be0cebe458574705640a72e640 Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Mon, 16 Feb 2015 15:25:02 +0100 Subject: [PATCH] Added further JUnit tests --- .../stages/LegacyTraceReconstructorTest.java | 16 +++++ .../diagnosis/common/util/MapperTest.java | 72 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/test/java/kieker/diagnosis/common/util/MapperTest.java diff --git a/src/test/java/kieker/diagnosis/common/model/importer/stages/LegacyTraceReconstructorTest.java b/src/test/java/kieker/diagnosis/common/model/importer/stages/LegacyTraceReconstructorTest.java index 016f18b6..ddbf557f 100644 --- a/src/test/java/kieker/diagnosis/common/model/importer/stages/LegacyTraceReconstructorTest.java +++ b/src/test/java/kieker/diagnosis/common/model/importer/stages/LegacyTraceReconstructorTest.java @@ -1,3 +1,19 @@ +/*************************************************************************** + * Copyright 2014 Kieker Project (http://kieker-monitoring.net) + * + * 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 kieker.diagnosis.common.model.importer.stages; import static org.hamcrest.Matchers.is; diff --git a/src/test/java/kieker/diagnosis/common/util/MapperTest.java b/src/test/java/kieker/diagnosis/common/util/MapperTest.java new file mode 100644 index 00000000..4b031217 --- /dev/null +++ b/src/test/java/kieker/diagnosis/common/util/MapperTest.java @@ -0,0 +1,72 @@ +/*************************************************************************** + * Copyright 2014 Kieker Project (http://kieker-monitoring.net) + * + * 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 kieker.diagnosis.common.util; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.core.IsNull.nullValue; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +public class MapperTest { + + @Test + public void mappingWithoutEntriesShouldNotLeadToException() { + final Mapper<Integer, String> mapper = new Mapper<>(); + + assertThat(mapper.resolve(1), is(nullValue())); + } + + @Test + public void mappingWithSingleEntryShouldWork() { + final Mapper<Integer, String> mapper = new Mapper<>(); + + mapper.map(1).to("One"); + + assertThat(mapper.resolve(1), is("One")); + } + + @Test + public void mappingWithMultipleEntriesShouldWork() { + final Mapper<Integer, String> mapper = new Mapper<>(); + + mapper.map(1).to("One"); + mapper.map(2).to("Two"); + + assertThat(mapper.resolve(1), is("One")); + } + + @Test + public void sameKeyShouldOverwriteMapping() { + final Mapper<Integer, String> mapper = new Mapper<>(); + + mapper.map(1).to("One"); + mapper.map(1).to("1"); + + assertThat(mapper.resolve(1), is("1")); + } + + @Test + public void reverseMappingShouldWork() { + final Mapper<Integer, String> mapper = new Mapper<>(); + + mapper.map(1).to("One"); + + assertThat(mapper.invertedResolve("One"), is(1)); + } + +} -- GitLab