From 5e1da6361fd91d923dac256b209b7ba14ce9c662 Mon Sep 17 00:00:00 2001 From: Argyro-Sioziou Date: Sun, 27 May 2018 16:58:38 +0300 Subject: [PATCH] Adding ConfigureForDosVisitor and ConfigureForUnixVisitor --- .../ConfigureForDosVisitor.java | 46 ++++++++++++ .../ConfigureForUnixVisitor.java | 40 ++++++++++ .../ConfigureForDosVisitorTest.java | 75 +++++++++++++++++++ .../ConfigureForUnixVisitorTest.java | 75 +++++++++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java create mode 100644 acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java create mode 100644 acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitorTest.java create mode 100644 acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitorTest.java diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java new file mode 100644 index 000000000..aee1dfa38 --- /dev/null +++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java @@ -0,0 +1,46 @@ +/** + * The MIT License + * Copyright (c) 2014-2016 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.iluwatar.acyclicvisitor; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CongigureForDosVisitor class + * implements both zoom's and + * hayes' visit method for Dos + * manufacturer + */ + +public class ConfigureForDosVisitor implements ModemVisitor, HayesVisitor, ZoomVisitor { + + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class); + + public void visit(Hayes hayes) { + LOGGER.info(hayes + " used with Dos configurator."); + } + + public void visit(Zoom zoom) { + LOGGER.info(zoom + " used with Dos configurator."); + } +} diff --git a/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java new file mode 100644 index 000000000..c2402d2bc --- /dev/null +++ b/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java @@ -0,0 +1,40 @@ +/** + * The MIT License + * Copyright (c) 2014-2016 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.iluwatar.acyclicvisitor; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CongigureForDosVisitor class + * implements both zoom's visit + * method for Unix manufacturer + */ +public class ConfigureForUnixVisitor implements ModemVisitor, ZoomVisitor { + + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForUnixVisitor.class); + + public void visit(Zoom zoom) { + LOGGER.info(zoom + " used with Unix configurator."); + } +} \ No newline at end of file diff --git a/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitorTest.java b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitorTest.java new file mode 100644 index 000000000..78d442caa --- /dev/null +++ b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitorTest.java @@ -0,0 +1,75 @@ +/** + * The MIT License + * Copyright (c) 2014-2016 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.iluwatar.acyclicvisitor; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.groups.Tuple.tuple; +import static org.mockito.Mockito.mock; +import static uk.org.lidalia.slf4jext.Level.INFO; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import com.iluwatar.acyclicvisitor.ConfigureForDosVisitor; +import com.iluwatar.acyclicvisitor.Hayes; +import com.iluwatar.acyclicvisitor.HayesVisitor; +import com.iluwatar.acyclicvisitor.Zoom; +import com.iluwatar.acyclicvisitor.ZoomVisitor; + +import uk.org.lidalia.slf4jtest.TestLogger; +import uk.org.lidalia.slf4jtest.TestLoggerFactory; + +/** + * ConfigureForDosVisitor test class + */ +public class ConfigureForDosVisitorTest { + + TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForDosVisitor.class); + + @Test + public void testVisitForZoom() { + ConfigureForDosVisitor conDos = new ConfigureForDosVisitor(); + Zoom zoom = mock(Zoom.class); + + ((ZoomVisitor)conDos).visit(zoom); + + assertThat(logger.getLoggingEvents()).extracting("level", "message").contains( + tuple(INFO, zoom + " used with Dos configurator.")); + } + + @Test + public void testVisitForHayes() { + ConfigureForDosVisitor conDos = new ConfigureForDosVisitor(); + Hayes hayes = mock(Hayes.class); + + ((HayesVisitor)conDos).visit(hayes); + + assertThat(logger.getLoggingEvents()).extracting("level", "message").contains( + tuple(INFO, hayes + " used with Dos configurator.")); + } + + @AfterEach + public void clearLoggers() { + TestLoggerFactory.clear(); + } +} diff --git a/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitorTest.java b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitorTest.java new file mode 100644 index 000000000..4346ffd30 --- /dev/null +++ b/acyclic-visitor/src/test/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitorTest.java @@ -0,0 +1,75 @@ +/** + * The MIT License + * Copyright (c) 2014-2016 Ilkka Seppälä + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.iluwatar.acyclicvisitor; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.groups.Tuple.tuple; +import static uk.org.lidalia.slf4jext.Level.INFO; +import static org.mockito.Mockito.mock; + +import uk.org.lidalia.slf4jtest.TestLogger; +import uk.org.lidalia.slf4jtest.TestLoggerFactory; +import org.junit.jupiter.api.Test; + +import com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor; +import com.iluwatar.acyclicvisitor.Hayes; +import com.iluwatar.acyclicvisitor.HayesVisitor; +import com.iluwatar.acyclicvisitor.Zoom; +import com.iluwatar.acyclicvisitor.ZoomVisitor; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; + +/** + * ConfigureForUnixVisitor test class + */ +public class ConfigureForUnixVisitorTest { + + TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForUnixVisitor.class); + + @AfterEach + public void clearLoggers() { + TestLoggerFactory.clear(); + } + + @Test + public void testVisitForZoom() { + ConfigureForUnixVisitor conUnix = new ConfigureForUnixVisitor(); + Zoom zoom = mock(Zoom.class); + + ((ZoomVisitor)conUnix).visit(zoom); + + assertThat(logger.getLoggingEvents()).extracting("level", "message").contains( + tuple(INFO, zoom + " used with Unix configurator.")); + } + + @Test + public void testVisitForHayes() { + ConfigureForUnixVisitor conUnix = new ConfigureForUnixVisitor(); + Hayes hayes = mock(Hayes.class); + + Assertions.assertThrows(ClassCastException.class, () -> { + ((HayesVisitor)conUnix).visit(hayes); + }); + } +}