Merge branch 'master' into ambassador
This commit is contained in:
		
							
								
								
									
										39
									
								
								acyclic-visitor/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								acyclic-visitor/README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| --- | ||||
| layout: pattern | ||||
| title: Acyclic Visitor | ||||
| folder: acyclic-visitor | ||||
| permalink: /patterns/acyclic-visitor/ | ||||
| categories: Behavioral | ||||
| tags: | ||||
|  - Java | ||||
|  - Difficulty-Intermediate | ||||
| --- | ||||
|  | ||||
|  | ||||
|  | ||||
| ## Intent | ||||
| Allow new functions to be added to existing class hierarchies without affecting those hierarchies, and without creating the troublesome dependency cycles that are inherent to the GOF VISITOR Pattern. | ||||
|  | ||||
| ## Applicability | ||||
| This pattern can be used: | ||||
| * When you need to add a new function to an existing hierarchy without the need to alter or affect that hierarchy. | ||||
| * When there are functions that operate upon a hierarchy, but which do not belong in the hierarchy itself. e.g. the ConfigureForDOS / ConfigureForUnix / ConfigureForX issue. | ||||
| * When you need to perform very different operations on an object depending upon its type. | ||||
| * When the visited class hierarchy will be frequently extended with new derivatives of the Element class. | ||||
| * When the recompilation, relinking, retesting or redistribution of the derivatives of Element is very expensive. | ||||
|  | ||||
| ## Consequences | ||||
| The good: | ||||
| * No dependency cycles between class hierarchies. | ||||
| * No need to recompile all the visitors if a new one is added. | ||||
| * Does not cause compilation failure in existing visitors if class hierarchy has a new member. | ||||
|  | ||||
| The bad: | ||||
| * Violates the principle of least surprise or Liskov's Substitution principle by showing that it can accept all visitors but actually only being interested in particular visitors. | ||||
| * Parallel hierarchy of visitors has to be created for all members in visitable class hierarchy. | ||||
|  | ||||
| ## Related patterns | ||||
| * [Visitor Pattern](../visitor/README.md) | ||||
|  | ||||
| ## Credits | ||||
| * [Acyclic Visitor](http://condor.depaul.edu/dmumaugh/OOT/Design-Principles/acv.pdf) | ||||
							
								
								
									
										115
									
								
								acyclic-visitor/etc/Acyclic Visitor.ucls
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								acyclic-visitor/etc/Acyclic Visitor.ucls
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,115 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <class-diagram version="1.2.2" icons="true" always-add-relationships="false" generalizations="true" realizations="true"  | ||||
|   associations="true" dependencies="false" nesting-relationships="true" router="FAN">   | ||||
|   <interface id="1" language="java" name="com.iluwatar.acyclicvisitor.ModemVisitor" project="acyclic-visitor"  | ||||
|     file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ModemVisitor.java" binary="false"  | ||||
|     corner="BOTTOM_RIGHT">     | ||||
|     <position height="-1" width="-1" x="860" y="67"/>     | ||||
|     <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"  | ||||
|       sort-features="false" accessors="true" visibility="true">       | ||||
|       <attributes public="true" package="true" protected="true" private="true" static="true"/>       | ||||
|       <operations public="true" package="true" protected="true" private="true" static="true"/>     | ||||
|     </display>   | ||||
|   </interface>   | ||||
|   <class id="2" language="java" name="com.iluwatar.acyclicvisitor.Modem" project="acyclic-visitor"  | ||||
|     file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Modem.java" binary="false" corner="BOTTOM_RIGHT">     | ||||
|     <position height="-1" width="-1" x="327" y="77"/>     | ||||
|     <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"  | ||||
|       sort-features="false" accessors="true" visibility="true">       | ||||
|       <attributes public="true" package="true" protected="true" private="true" static="true"/>       | ||||
|       <operations public="true" package="true" protected="true" private="true" static="true"/>     | ||||
|     </display>   | ||||
|   </class>   | ||||
|   <class id="3" language="java" name="com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor" project="acyclic-visitor"  | ||||
|     file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java" binary="false"  | ||||
|     corner="BOTTOM_RIGHT">     | ||||
|     <position height="124" width="196" x="647" y="225"/>     | ||||
|     <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"  | ||||
|       sort-features="false" accessors="true" visibility="true">       | ||||
|       <attributes public="true" package="true" protected="true" private="true" static="true"/>       | ||||
|       <operations public="true" package="true" protected="true" private="true" static="true"/>     | ||||
|     </display>   | ||||
|   </class>   | ||||
|   <class id="4" language="java" name="com.iluwatar.acyclicvisitor.Zoom" project="acyclic-visitor"  | ||||
|     file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Zoom.java" binary="false" corner="BOTTOM_RIGHT">     | ||||
|     <position height="-1" width="-1" x="203" y="305"/>     | ||||
|     <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"  | ||||
|       sort-features="false" accessors="true" visibility="true">       | ||||
|       <attributes public="true" package="true" protected="true" private="true" static="true"/>       | ||||
|       <operations public="true" package="true" protected="true" private="true" static="true"/>     | ||||
|     </display>   | ||||
|   </class>   | ||||
|   <interface id="5" language="java" name="com.iluwatar.acyclicvisitor.HayesVisitor" project="acyclic-visitor"  | ||||
|     file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/HayesVisitor.java" binary="false"  | ||||
|     corner="BOTTOM_RIGHT">     | ||||
|     <position height="-1" width="-1" x="1019" y="468"/>     | ||||
|     <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"  | ||||
|       sort-features="false" accessors="true" visibility="true">       | ||||
|       <attributes public="true" package="true" protected="true" private="true" static="true"/>       | ||||
|       <operations public="true" package="true" protected="true" private="true" static="true"/>     | ||||
|     </display>   | ||||
|   </interface>   | ||||
|   <interface id="6" language="java" name="com.iluwatar.acyclicvisitor.ZoomVisitor" project="acyclic-visitor"  | ||||
|     file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ZoomVisitor.java" binary="false"  | ||||
|     corner="BOTTOM_RIGHT">     | ||||
|     <position height="-1" width="-1" x="758" y="467"/>     | ||||
|     <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"  | ||||
|       sort-features="false" accessors="true" visibility="true">       | ||||
|       <attributes public="true" package="true" protected="true" private="true" static="true"/>       | ||||
|       <operations public="true" package="true" protected="true" private="true" static="true"/>     | ||||
|     </display>   | ||||
|   </interface>   | ||||
|   <class id="7" language="java" name="com.iluwatar.acyclicvisitor.Hayes" project="acyclic-visitor"  | ||||
|     file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Hayes.java" binary="false" corner="BOTTOM_RIGHT">     | ||||
|     <position height="-1" width="-1" x="479" y="307"/>     | ||||
|     <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"  | ||||
|       sort-features="false" accessors="true" visibility="true">       | ||||
|       <attributes public="true" package="true" protected="true" private="true" static="true"/>       | ||||
|       <operations public="true" package="true" protected="true" private="true" static="true"/>     | ||||
|     </display>   | ||||
|   </class>   | ||||
|   <class id="8" language="java" name="com.iluwatar.acyclicvisitor.ConfigureForDosVisitor" project="acyclic-visitor"  | ||||
|     file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java" binary="false"  | ||||
|     corner="BOTTOM_RIGHT">     | ||||
|     <position height="142" width="192" x="883" y="225"/>     | ||||
|     <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"  | ||||
|       sort-features="false" accessors="true" visibility="true">       | ||||
|       <attributes public="true" package="true" protected="true" private="true" static="true"/>       | ||||
|       <operations public="true" package="true" protected="true" private="true" static="true"/>     | ||||
|     </display>   | ||||
|   </class>   | ||||
|   <generalization id="9">     | ||||
|     <end type="SOURCE" refId="7"/>     | ||||
|     <end type="TARGET" refId="2"/>   | ||||
|   </generalization>   | ||||
|   <realization id="10">     | ||||
|     <end type="SOURCE" refId="8"/>     | ||||
|     <end type="TARGET" refId="6"/>   | ||||
|   </realization>   | ||||
|   <realization id="11">     | ||||
|     <end type="SOURCE" refId="8"/>     | ||||
|     <end type="TARGET" refId="5"/>   | ||||
|   </realization>   | ||||
|   <realization id="12">     | ||||
|     <end type="SOURCE" refId="3"/>     | ||||
|     <end type="TARGET" refId="6"/>   | ||||
|   </realization>   | ||||
|   <realization id="13">     | ||||
|     <end type="SOURCE" refId="3"/>     | ||||
|     <end type="TARGET" refId="1"/>   | ||||
|   </realization>   | ||||
|   <realization id="14">     | ||||
|     <end type="SOURCE" refId="8"/>     | ||||
|     <end type="TARGET" refId="1"/>   | ||||
|   </realization>   | ||||
|   <generalization id="15">     | ||||
|     <end type="SOURCE" refId="4"/>     | ||||
|     <end type="TARGET" refId="2"/>   | ||||
|   </generalization>   | ||||
|   <classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"  | ||||
|     sort-features="false" accessors="true" visibility="true">     | ||||
|     <attributes public="true" package="true" protected="true" private="true" static="true"/>     | ||||
|     <operations public="true" package="true" protected="true" private="true" static="true"/>   | ||||
|   </classifier-display>   | ||||
|   <association-display labels="true" multiplicity="true"/> | ||||
| </class-diagram> | ||||
							
								
								
									
										
											BIN
										
									
								
								acyclic-visitor/etc/acyclic-visitor.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								acyclic-visitor/etc/acyclic-visitor.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 26 KiB | 
							
								
								
									
										76
									
								
								acyclic-visitor/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								acyclic-visitor/pom.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,76 @@ | ||||
| <!-- | ||||
|  | ||||
|     The MIT License | ||||
|     Copyright (c) 2014 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. | ||||
|  | ||||
| --> | ||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||
| 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
| 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
| 	<modelVersion>4.0.0</modelVersion> | ||||
| 	 | ||||
| 	<parent> | ||||
| 		<groupId>com.iluwatar</groupId> | ||||
| 		<artifactId>java-design-patterns</artifactId> | ||||
| 		<version>1.20.0-SNAPSHOT</version> | ||||
| 	</parent> | ||||
| 	 | ||||
| 	<artifactId>acyclic-visitor</artifactId> | ||||
|  | ||||
| 	<properties> | ||||
| 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||||
| 		<maven.compiler.source>1.8</maven.compiler.source> | ||||
| 		<maven.compiler.target>1.8</maven.compiler.target> | ||||
| 	</properties> | ||||
|  | ||||
| 	<dependencies> | ||||
| 		<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core --> | ||||
| 		<dependency> | ||||
| 			<groupId>org.assertj</groupId> | ||||
| 			<artifactId>assertj-core</artifactId> | ||||
| 			<version>3.9.1</version> | ||||
| 			<scope>test</scope> | ||||
| 		</dependency> | ||||
| 		<!-- https://mvnrepository.com/artifact/uk.org.lidalia/slf4j-test --> | ||||
| 		<dependency> | ||||
| 			<groupId>uk.org.lidalia</groupId> | ||||
| 			<artifactId>slf4j-test</artifactId> | ||||
| 			<version>1.0.0</version> | ||||
| 			<scope>test</scope> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
|       		<groupId>org.junit.jupiter</groupId> | ||||
|       		<artifactId>junit-jupiter-api</artifactId> | ||||
|       		<scope>test</scope> | ||||
|     	</dependency> | ||||
|     	<dependency> | ||||
|       		<groupId>org.junit.jupiter</groupId> | ||||
|       		<artifactId>junit-jupiter-engine</artifactId> | ||||
|       		<scope>test</scope> | ||||
|     	</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.mockito</groupId> | ||||
| 			<artifactId>mockito-all</artifactId> | ||||
| 			<version>1.9.5</version> | ||||
| 			<scope>test</scope> | ||||
| 		</dependency> | ||||
| 	</dependencies> | ||||
| </project> | ||||
| @@ -0,0 +1,30 @@ | ||||
| /** | ||||
|  * 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; | ||||
|  | ||||
| /** | ||||
|  * All ModemVisitor interface extends all visitor interfaces | ||||
|  */ | ||||
| public interface AllModemVisitor extends ModemVisitor, ZoomVisitor, HayesVisitor{ | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,55 @@ | ||||
| /** | ||||
|  * 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; | ||||
|  | ||||
| /** | ||||
|  * The Acyclic Visitor pattern allows new functions to be added to existing class  | ||||
|  * hierarchies without affecting those hierarchies, and without creating the dependency  | ||||
|  * cycles that are inherent to the GoF Visitor pattern, by making the Visitor base class  | ||||
|  * degenerate | ||||
|  * <p> | ||||
|  * In this example the visitor base class is {@link ModemVisitor}. The base class of the  | ||||
|  * visited hierarchy is {@link Modem} and has two children {@link Hayes} and {@link Zoom}  | ||||
|  * each one having its own visitor interface {@link HayesVisitor} and {@link ZoomVisitor}  | ||||
|  * respectively. {@link ConfigureForUnixVisitor} and {@link ConfigureForDosVisitor}  | ||||
|  * implement each derivative's visit method only if it is required  | ||||
|  */ | ||||
| public class App { | ||||
|    | ||||
|   /** | ||||
|    * Program's entry point | ||||
|    */ | ||||
|    | ||||
|   public static void main(String[] args) {   | ||||
|     ConfigureForUnixVisitor conUnix = new ConfigureForUnixVisitor(); | ||||
|     ConfigureForDosVisitor conDos = new ConfigureForDosVisitor(); | ||||
|      | ||||
|     Zoom zoom = new Zoom(); | ||||
|     Hayes hayes = new Hayes(); | ||||
|      | ||||
|     hayes.accept(conDos); // Hayes modem with Unix configurator | ||||
|     zoom.accept(conDos); // Zoom modem with Dos configurator | ||||
|     hayes.accept(conUnix); // Hayes modem with Unix configurator | ||||
|     zoom.accept(conUnix); // Zoom modem with Unix configurator    | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,43 @@ | ||||
| /** | ||||
|  * 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; | ||||
|  | ||||
| /** | ||||
|  * ConfigureForDosVisitor class implements both zoom's and  hayes' visit method  | ||||
|  * for Dos manufacturer | ||||
|  */ | ||||
| public class ConfigureForDosVisitor implements AllModemVisitor { | ||||
|  | ||||
|   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."); | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,39 @@ | ||||
| /** | ||||
|  * 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; | ||||
|  | ||||
| /** | ||||
|  * ConfigureForUnixVisitor class implements 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."); | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,56 @@ | ||||
| /** | ||||
|  * 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; | ||||
|  | ||||
| /** | ||||
|  * Hayes class implements its accept method | ||||
|  */ | ||||
| public class Hayes extends Modem { | ||||
|    | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class); | ||||
|  | ||||
|   /** | ||||
|    * Accepts all visitors but honors only HayesVisitor | ||||
|    */ | ||||
|   @Override | ||||
|   public void accept(ModemVisitor modemVisitor) { | ||||
|     try { | ||||
|       ((HayesVisitor) modemVisitor).visit(this); | ||||
|     } catch (ClassCastException e) { | ||||
|       LOGGER.error("Unable to cast to HayesVisitor"); | ||||
|     } | ||||
|  | ||||
|   } | ||||
|    | ||||
|   /** | ||||
|    * Hayes' modem's toString | ||||
|    * method | ||||
|    */ | ||||
|   @Override | ||||
|   public String toString() { | ||||
|     return "Hayes modem"; | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,30 @@ | ||||
| /** | ||||
|  * 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; | ||||
|  | ||||
| /** | ||||
|  * HayesVisitor interface | ||||
|  */ | ||||
| public interface HayesVisitor extends ModemVisitor { | ||||
|   void visit(Hayes hayes); | ||||
| } | ||||
| @@ -0,0 +1,30 @@ | ||||
| /** | ||||
|  * 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; | ||||
|  | ||||
| /** | ||||
|  * Modem abstract class | ||||
|  */ | ||||
| public abstract class Modem { | ||||
|   public abstract void accept(ModemVisitor modemVisitor); | ||||
| } | ||||
| @@ -0,0 +1,32 @@ | ||||
| /** | ||||
|  * 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; | ||||
|  | ||||
| /** | ||||
|  * ModemVisitor interface does not contain any visit methods so that it does not | ||||
|  * depend on the visited hierarchy. Each derivative's visit method is declared in  | ||||
|  * its own visitor interface | ||||
|  */ | ||||
| public interface ModemVisitor { | ||||
|   // Visitor is a degenerate base class for all visitors. | ||||
| } | ||||
| @@ -0,0 +1,55 @@ | ||||
| /** | ||||
|  * 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; | ||||
|  | ||||
| /** | ||||
|  * Zoom class implements its accept method | ||||
|  */ | ||||
| public class Zoom extends Modem { | ||||
|    | ||||
|   private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class); | ||||
|  | ||||
|   /** | ||||
|    * Accepts all visitors but honors only ZoomVisitor | ||||
|    */ | ||||
|   @Override | ||||
|   public void accept(ModemVisitor modemVisitor) { | ||||
|     try { | ||||
|       ((ZoomVisitor) modemVisitor).visit(this); | ||||
|     } catch (ClassCastException e) { | ||||
|       LOGGER.error("Unable to cast to ZoomVisitor"); | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   /** | ||||
|    * Zoom modem's toString | ||||
|    * method | ||||
|    */ | ||||
|   @Override | ||||
|   public String toString() { | ||||
|     return "Zoom modem"; | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,30 @@ | ||||
| /** | ||||
|  * 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; | ||||
|  | ||||
| /** | ||||
|  * ZoomVisitor interface | ||||
|  */ | ||||
| public interface ZoomVisitor extends ModemVisitor{ | ||||
|   void visit(Zoom zoom); | ||||
| } | ||||
| @@ -0,0 +1,39 @@ | ||||
| /** | ||||
|  * 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.junit.jupiter.api.Test; | ||||
|  | ||||
| import com.iluwatar.acyclicvisitor.App; | ||||
|  | ||||
| /** | ||||
|  * Tests that the Acyclic Visitor example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|    | ||||
|   @Test | ||||
|   public void test() { | ||||
|     String[] args = {}; | ||||
|     App.main(args);   | ||||
|   } | ||||
| } | ||||
| @@ -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 = new Zoom(); | ||||
|      | ||||
|     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 = new Hayes(); | ||||
|      | ||||
|     conDos.visit(hayes); | ||||
|      | ||||
|     assertThat(logger.getLoggingEvents()).extracting("level", "message").contains( | ||||
|         tuple(INFO, hayes + " used with Dos configurator.")); | ||||
|   } | ||||
|    | ||||
|   @AfterEach | ||||
|   public void clearLoggers() { | ||||
|     TestLoggerFactory.clear(); | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,65 @@ | ||||
| /** | ||||
|  * 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 = new Zoom(); | ||||
|      | ||||
|     conUnix.visit(zoom); | ||||
|      | ||||
|     assertThat(logger.getLoggingEvents()).extracting("level", "message").contains( | ||||
|         tuple(INFO, zoom + " used with Unix configurator.")); | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,60 @@ | ||||
| /** | ||||
|  * 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.mockito.Matchers.eq; | ||||
| import static org.mockito.Mockito.mock; | ||||
| import static org.mockito.Mockito.verify; | ||||
| import static org.mockito.Mockito.verifyZeroInteractions; | ||||
|  | ||||
| import org.junit.jupiter.api.Test; | ||||
|  | ||||
| import com.iluwatar.acyclicvisitor.ConfigureForDosVisitor; | ||||
| import com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor; | ||||
| import com.iluwatar.acyclicvisitor.Hayes; | ||||
| import com.iluwatar.acyclicvisitor.HayesVisitor; | ||||
|  | ||||
| /** | ||||
|  * Hayes test class | ||||
|  */ | ||||
| public class HayesTest { | ||||
|  | ||||
|   @Test | ||||
|   public void testAcceptForDos() {   | ||||
|     Hayes hayes = new Hayes(); | ||||
|     ConfigureForDosVisitor mockVisitor = mock(ConfigureForDosVisitor.class); | ||||
|      | ||||
|     hayes.accept(mockVisitor); | ||||
|     verify((HayesVisitor)mockVisitor).visit(eq(hayes)); | ||||
|   } | ||||
|    | ||||
|   @Test | ||||
|   public void testAcceptForUnix() {     | ||||
|     Hayes hayes = new Hayes(); | ||||
|     ConfigureForUnixVisitor mockVisitor = mock(ConfigureForUnixVisitor.class); | ||||
|      | ||||
|     hayes.accept(mockVisitor); | ||||
|      | ||||
|     verifyZeroInteractions(mockVisitor); | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,59 @@ | ||||
| /** | ||||
|  * 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.mockito.Matchers.eq; | ||||
| import static org.mockito.Mockito.verify; | ||||
| import static org.mockito.Mockito.mock; | ||||
|  | ||||
| import org.junit.jupiter.api.Test; | ||||
|  | ||||
| import com.iluwatar.acyclicvisitor.ConfigureForDosVisitor; | ||||
| import com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor; | ||||
| import com.iluwatar.acyclicvisitor.Zoom; | ||||
| import com.iluwatar.acyclicvisitor.ZoomVisitor; | ||||
|  | ||||
| /** | ||||
|  * Zoom test class | ||||
|  */ | ||||
| public class ZoomTest { | ||||
|    | ||||
|   @Test | ||||
|   public void testAcceptForDos() {   | ||||
|     Zoom zoom = new Zoom(); | ||||
|     ConfigureForDosVisitor mockVisitor = mock(ConfigureForDosVisitor.class); | ||||
|      | ||||
|     zoom.accept(mockVisitor); | ||||
|     verify((ZoomVisitor)mockVisitor).visit(eq(zoom)); | ||||
|   } | ||||
|    | ||||
|   @Test | ||||
|   public void testAcceptForUnix() { | ||||
|     Zoom zoom = new Zoom(); | ||||
|     ConfigureForUnixVisitor mockVisitor = mock(ConfigureForUnixVisitor.class); | ||||
|      | ||||
|     zoom.accept(mockVisitor); | ||||
|     verify((ZoomVisitor)mockVisitor).visit(eq(zoom)); | ||||
|   } | ||||
| } | ||||
| @@ -1,4 +1,28 @@ | ||||
| <?xml version="1.0"?> | ||||
| <!-- | ||||
|  | ||||
|     The MIT License | ||||
|     Copyright (c) 2014 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. | ||||
|  | ||||
| --> | ||||
| <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||||
|     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||||
|   <modelVersion>4.0.0</modelVersion> | ||||
|   | ||||
| @@ -1,3 +1,25 @@ | ||||
| /** | ||||
|  * The MIT License | ||||
|  * Copyright (c) 2014 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.dirtyflag; | ||||
|  | ||||
| import java.io.BufferedReader; | ||||
|   | ||||
| @@ -1,3 +1,25 @@ | ||||
| /** | ||||
|  * The MIT License | ||||
|  * Copyright (c) 2014 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.dirtyflag; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
|   | ||||
| @@ -1,3 +1,26 @@ | ||||
| ==== | ||||
|     The MIT License | ||||
|     Copyright (c) 2014 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. | ||||
| ==== | ||||
|  | ||||
| UNITED_KINGDOM | ||||
| MALAYSIA | ||||
| UNITED_STATES | ||||
							
								
								
									
										1
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -162,6 +162,7 @@ | ||||
|         <module>trampoline</module> | ||||
|         <module>serverless</module> | ||||
|         <module>ambassador</module> | ||||
| 		    <module>acyclic-visitor</module> | ||||
|     </modules> | ||||
|  | ||||
|     <repositories> | ||||
|   | ||||
| @@ -23,6 +23,7 @@ | ||||
| package com.iluwatar.throttling; | ||||
|  | ||||
| import com.iluwatar.throttling.timer.Throttler; | ||||
| import org.junit.jupiter.api.Disabled; | ||||
| import org.junit.jupiter.api.Test; | ||||
|  | ||||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||||
| @@ -32,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; | ||||
|  */ | ||||
| public class B2BServiceTest { | ||||
|  | ||||
|   @Disabled | ||||
|   @Test | ||||
|   public void dummyCustomerApiTest() { | ||||
|     Tenant tenant = new Tenant("testTenant", 2); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user