Add tests that run the examples
This commit is contained in:
		| @@ -0,0 +1,100 @@ | ||||
| /** | ||||
|  * 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.abstractfactory; | ||||
|  | ||||
| import static org.junit.Assert.assertEquals; | ||||
| import static org.junit.Assert.assertTrue; | ||||
|  | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
|  | ||||
| public class AbstractFactoryTest { | ||||
|  | ||||
|   private App app = new App(); | ||||
|   private KingdomFactory elfFactory; | ||||
|   private KingdomFactory orcFactory; | ||||
|  | ||||
|   @Before | ||||
|   public void setUp() { | ||||
|     elfFactory = app.getElfKingdomFactory(); | ||||
|     orcFactory = app.getOrcKingdomFactory(); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void king() { | ||||
|     final King elfKing = app.getKing(elfFactory); | ||||
|     assertTrue(elfKing instanceof ElfKing); | ||||
|     assertEquals(ElfKing.DESCRIPTION, elfKing.getDescription()); | ||||
|     final King orcKing = app.getKing(orcFactory); | ||||
|     assertTrue(orcKing instanceof OrcKing); | ||||
|     assertEquals(OrcKing.DESCRIPTION, orcKing.getDescription()); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void castle() { | ||||
|     final Castle elfCastle = app.getCastle(elfFactory); | ||||
|     assertTrue(elfCastle instanceof ElfCastle); | ||||
|     assertEquals(ElfCastle.DESCRIPTION, elfCastle.getDescription()); | ||||
|     final Castle orcCastle = app.getCastle(orcFactory); | ||||
|     assertTrue(orcCastle instanceof OrcCastle); | ||||
|     assertEquals(OrcCastle.DESCRIPTION, orcCastle.getDescription()); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void army() { | ||||
|     final Army elfArmy = app.getArmy(elfFactory); | ||||
|     assertTrue(elfArmy instanceof ElfArmy); | ||||
|     assertEquals(ElfArmy.DESCRIPTION, elfArmy.getDescription()); | ||||
|     final Army orcArmy = app.getArmy(orcFactory); | ||||
|     assertTrue(orcArmy instanceof OrcArmy); | ||||
|     assertEquals(OrcArmy.DESCRIPTION, orcArmy.getDescription()); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void createElfKingdom() { | ||||
|     app.createKingdom(elfFactory); | ||||
|     final King king = app.getKing(); | ||||
|     final Castle castle = app.getCastle(); | ||||
|     final Army army = app.getArmy(); | ||||
|     assertTrue(king instanceof ElfKing); | ||||
|     assertEquals(ElfKing.DESCRIPTION, king.getDescription()); | ||||
|     assertTrue(castle instanceof ElfCastle); | ||||
|     assertEquals(ElfCastle.DESCRIPTION, castle.getDescription()); | ||||
|     assertTrue(army instanceof ElfArmy); | ||||
|     assertEquals(ElfArmy.DESCRIPTION, army.getDescription()); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void createOrcKingdom() { | ||||
|     app.createKingdom(orcFactory); | ||||
|     final King king = app.getKing(); | ||||
|     final Castle castle = app.getCastle(); | ||||
|     final Army army = app.getArmy(); | ||||
|     assertTrue(king instanceof OrcKing); | ||||
|     assertEquals(OrcKing.DESCRIPTION, king.getDescription()); | ||||
|     assertTrue(castle instanceof OrcCastle); | ||||
|     assertEquals(OrcCastle.DESCRIPTION, castle.getDescription()); | ||||
|     assertTrue(army instanceof OrcArmy); | ||||
|     assertEquals(OrcArmy.DESCRIPTION, army.getDescription()); | ||||
|   } | ||||
| } | ||||
| @@ -22,79 +22,17 @@ | ||||
|  */ | ||||
| package com.iluwatar.abstractfactory; | ||||
|  | ||||
| import static org.junit.Assert.assertEquals; | ||||
| import static org.junit.Assert.assertTrue; | ||||
|  | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * Tests that Abstract Factory example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|  | ||||
|   private App app = new App(); | ||||
|   private KingdomFactory elfFactory; | ||||
|   private KingdomFactory orcFactory; | ||||
|  | ||||
|   @Before | ||||
|   public void setUp() { | ||||
|     elfFactory = app.getElfKingdomFactory(); | ||||
|     orcFactory = app.getOrcKingdomFactory(); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void king() { | ||||
|     final King elfKing = app.getKing(elfFactory); | ||||
|     assertTrue(elfKing instanceof ElfKing); | ||||
|     assertEquals(ElfKing.DESCRIPTION, elfKing.getDescription()); | ||||
|     final King orcKing = app.getKing(orcFactory); | ||||
|     assertTrue(orcKing instanceof OrcKing); | ||||
|     assertEquals(OrcKing.DESCRIPTION, orcKing.getDescription()); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void castle() { | ||||
|     final Castle elfCastle = app.getCastle(elfFactory); | ||||
|     assertTrue(elfCastle instanceof ElfCastle); | ||||
|     assertEquals(ElfCastle.DESCRIPTION, elfCastle.getDescription()); | ||||
|     final Castle orcCastle = app.getCastle(orcFactory); | ||||
|     assertTrue(orcCastle instanceof OrcCastle); | ||||
|     assertEquals(OrcCastle.DESCRIPTION, orcCastle.getDescription()); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void army() { | ||||
|     final Army elfArmy = app.getArmy(elfFactory); | ||||
|     assertTrue(elfArmy instanceof ElfArmy); | ||||
|     assertEquals(ElfArmy.DESCRIPTION, elfArmy.getDescription()); | ||||
|     final Army orcArmy = app.getArmy(orcFactory); | ||||
|     assertTrue(orcArmy instanceof OrcArmy); | ||||
|     assertEquals(OrcArmy.DESCRIPTION, orcArmy.getDescription()); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void createElfKingdom() { | ||||
|     app.createKingdom(elfFactory); | ||||
|     final King king = app.getKing(); | ||||
|     final Castle castle = app.getCastle(); | ||||
|     final Army army = app.getArmy(); | ||||
|     assertTrue(king instanceof ElfKing); | ||||
|     assertEquals(ElfKing.DESCRIPTION, king.getDescription()); | ||||
|     assertTrue(castle instanceof ElfCastle); | ||||
|     assertEquals(ElfCastle.DESCRIPTION, castle.getDescription()); | ||||
|     assertTrue(army instanceof ElfArmy); | ||||
|     assertEquals(ElfArmy.DESCRIPTION, army.getDescription()); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void createOrcKingdom() { | ||||
|     app.createKingdom(orcFactory); | ||||
|     final King king = app.getKing(); | ||||
|     final Castle castle = app.getCastle(); | ||||
|     final Army army = app.getArmy(); | ||||
|     assertTrue(king instanceof OrcKing); | ||||
|     assertEquals(OrcKing.DESCRIPTION, king.getDescription()); | ||||
|     assertTrue(castle instanceof OrcCastle); | ||||
|     assertEquals(OrcCastle.DESCRIPTION, castle.getDescription()); | ||||
|     assertTrue(army instanceof OrcArmy); | ||||
|     assertEquals(OrcArmy.DESCRIPTION, army.getDescription()); | ||||
|   public void test() throws IOException { | ||||
|     String[] args = {}; | ||||
|     App.main(args); | ||||
|   } | ||||
| } | ||||
|   | ||||
							
								
								
									
										38
									
								
								adapter/src/test/java/com/iluwatar/adapter/AppTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								adapter/src/test/java/com/iluwatar/adapter/AppTest.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| /** | ||||
|  * 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.adapter; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * Tests that Adapter example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|   @Test | ||||
|   public void test() throws IOException { | ||||
|     String[] args = {}; | ||||
|     App.main(args); | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,38 @@ | ||||
| /** | ||||
|  * 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.business.delegate; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * Tests that Business Delegate example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|   @Test | ||||
|   public void test() throws IOException { | ||||
|     String[] args = {}; | ||||
|     App.main(args); | ||||
|   } | ||||
| } | ||||
| @@ -22,42 +22,17 @@ | ||||
|  */ | ||||
| package com.iluwatar.caching; | ||||
|  | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * Application test | ||||
|  * | ||||
|  * Tests that Caching example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|   App app; | ||||
|  | ||||
|   /** | ||||
|    * Setup of application test includes: initializing DB connection and cache size/capacity. | ||||
|    */ | ||||
|   @Before | ||||
|   public void setUp() { | ||||
|     AppManager.initDb(false); // VirtualDB (instead of MongoDB) was used in running the JUnit tests | ||||
|                               // to avoid Maven compilation errors. Set flag to true to run the | ||||
|                               // tests with MongoDB (provided that MongoDB is installed and socket | ||||
|                               // connection is open). | ||||
|     AppManager.initCacheCapacity(3); | ||||
|     app = new App(); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testReadAndWriteThroughStrategy() { | ||||
|     app.useReadAndWriteThroughStrategy(); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testReadThroughAndWriteAroundStrategy() { | ||||
|     app.useReadThroughAndWriteAroundStrategy(); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testReadThroughAndWriteBehindStrategy() { | ||||
|     app.useReadThroughAndWriteBehindStrategy(); | ||||
|   public void test() throws IOException { | ||||
|     String[] args = {}; | ||||
|     App.main(args); | ||||
|   } | ||||
| } | ||||
|   | ||||
							
								
								
									
										63
									
								
								caching/src/test/java/com/iluwatar/caching/CachingTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								caching/src/test/java/com/iluwatar/caching/CachingTest.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,63 @@ | ||||
| /** | ||||
|  * 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.caching; | ||||
|  | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * Application test | ||||
|  * | ||||
|  */ | ||||
| public class CachingTest { | ||||
|   App app; | ||||
|  | ||||
|   /** | ||||
|    * Setup of application test includes: initializing DB connection and cache size/capacity. | ||||
|    */ | ||||
|   @Before | ||||
|   public void setUp() { | ||||
|     AppManager.initDb(false); // VirtualDB (instead of MongoDB) was used in running the JUnit tests | ||||
|                               // to avoid Maven compilation errors. Set flag to true to run the | ||||
|                               // tests with MongoDB (provided that MongoDB is installed and socket | ||||
|                               // connection is open). | ||||
|     AppManager.initCacheCapacity(3); | ||||
|     app = new App(); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testReadAndWriteThroughStrategy() { | ||||
|     app.useReadAndWriteThroughStrategy(); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testReadThroughAndWriteAroundStrategy() { | ||||
|     app.useReadThroughAndWriteAroundStrategy(); | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testReadThroughAndWriteBehindStrategy() { | ||||
|     app.useReadThroughAndWriteBehindStrategy(); | ||||
|   } | ||||
| } | ||||
| @@ -24,56 +24,15 @@ package com.iluwatar.callback; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import static org.junit.Assert.assertEquals; | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * Add a field as a counter. Every time the callback method is called increment this field. Unit | ||||
|  * test checks that the field is being incremented. | ||||
|  * | ||||
|  * Could be done with mock objects as well where the call method call is verified. | ||||
|  * Tests that Callback example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|  | ||||
|   private Integer callingCount = 0; | ||||
|  | ||||
|   @Test | ||||
|   public void test() { | ||||
|     Callback callback = new Callback() { | ||||
|       @Override | ||||
|       public void call() { | ||||
|         callingCount++; | ||||
|       } | ||||
|     }; | ||||
|  | ||||
|     Task task = new SimpleTask(); | ||||
|  | ||||
|     assertEquals("Initial calling count of 0", new Integer(0), callingCount); | ||||
|  | ||||
|     task.executeWith(callback); | ||||
|  | ||||
|     assertEquals("Callback called once", new Integer(1), callingCount); | ||||
|  | ||||
|     task.executeWith(callback); | ||||
|  | ||||
|     assertEquals("Callback called twice", new Integer(2), callingCount); | ||||
|  | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testWithLambdasExample() { | ||||
|     Callback callback = () -> callingCount++; | ||||
|  | ||||
|     Task task = new SimpleTask(); | ||||
|  | ||||
|     assertEquals("Initial calling count of 0", new Integer(0), callingCount); | ||||
|  | ||||
|     task.executeWith(callback); | ||||
|  | ||||
|     assertEquals("Callback called once", new Integer(1), callingCount); | ||||
|  | ||||
|     task.executeWith(callback); | ||||
|  | ||||
|     assertEquals("Callback called twice", new Integer(2), callingCount); | ||||
|  | ||||
|   public void test() throws IOException { | ||||
|     String[] args = {}; | ||||
|     App.main(args); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -0,0 +1,79 @@ | ||||
| /** | ||||
|  * 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.callback; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import static org.junit.Assert.assertEquals; | ||||
|  | ||||
| /** | ||||
|  * Add a field as a counter. Every time the callback method is called increment this field. Unit | ||||
|  * test checks that the field is being incremented. | ||||
|  * | ||||
|  * Could be done with mock objects as well where the call method call is verified. | ||||
|  */ | ||||
| public class CallbackTest { | ||||
|  | ||||
|   private Integer callingCount = 0; | ||||
|  | ||||
|   @Test | ||||
|   public void test() { | ||||
|     Callback callback = new Callback() { | ||||
|       @Override | ||||
|       public void call() { | ||||
|         callingCount++; | ||||
|       } | ||||
|     }; | ||||
|  | ||||
|     Task task = new SimpleTask(); | ||||
|  | ||||
|     assertEquals("Initial calling count of 0", new Integer(0), callingCount); | ||||
|  | ||||
|     task.executeWith(callback); | ||||
|  | ||||
|     assertEquals("Callback called once", new Integer(1), callingCount); | ||||
|  | ||||
|     task.executeWith(callback); | ||||
|  | ||||
|     assertEquals("Callback called twice", new Integer(2), callingCount); | ||||
|  | ||||
|   } | ||||
|  | ||||
|   @Test | ||||
|   public void testWithLambdasExample() { | ||||
|     Callback callback = () -> callingCount++; | ||||
|  | ||||
|     Task task = new SimpleTask(); | ||||
|  | ||||
|     assertEquals("Initial calling count of 0", new Integer(0), callingCount); | ||||
|  | ||||
|     task.executeWith(callback); | ||||
|  | ||||
|     assertEquals("Callback called once", new Integer(1), callingCount); | ||||
|  | ||||
|     task.executeWith(callback); | ||||
|  | ||||
|     assertEquals("Callback called twice", new Integer(2), callingCount); | ||||
|  | ||||
|   } | ||||
| } | ||||
							
								
								
									
										38
									
								
								command/src/test/java/com/iluwatar/command/AppTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								command/src/test/java/com/iluwatar/command/AppTest.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| /** | ||||
|  * 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.command; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * Tests that Command example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|   @Test | ||||
|   public void test() throws IOException { | ||||
|     String[] args = {}; | ||||
|     App.main(args); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										38
									
								
								dao/src/test/java/com/iluwatar/dao/AppTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								dao/src/test/java/com/iluwatar/dao/AppTest.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| /** | ||||
|  * 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.dao; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * Tests that DAO example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|   @Test | ||||
|   public void test() throws IOException { | ||||
|     String[] args = {}; | ||||
|     App.main(args); | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,38 @@ | ||||
| /** | ||||
|  * 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.eda; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * Tests that Event Driven Architecture example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|   @Test | ||||
|   public void test() throws IOException { | ||||
|     String[] args = {}; | ||||
|     App.main(args); | ||||
|   } | ||||
| } | ||||
| @@ -0,0 +1,38 @@ | ||||
| /** | ||||
|  * 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.factory.method; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * Tests that Factory Method example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|   @Test | ||||
|   public void test() throws IOException { | ||||
|     String[] args = {}; | ||||
|     App.main(args); | ||||
|   } | ||||
| } | ||||
| @@ -34,7 +34,7 @@ import com.iluwatar.reactor.framework.ThreadPoolDispatcher; | ||||
|  * This class tests the Distributed Logging service by starting a Reactor and then sending it | ||||
|  * concurrent logging requests using multiple clients. | ||||
|  */ | ||||
| public class AppTest { | ||||
| public class ReactorTest { | ||||
| 
 | ||||
|   /** | ||||
|    * Test the application using pooled thread dispatcher. | ||||
| @@ -0,0 +1,38 @@ | ||||
| /** | ||||
|  * 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.repository; | ||||
|  | ||||
| import org.junit.Test; | ||||
|  | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * Tests that Repository example runs without errors. | ||||
|  */ | ||||
| public class AppTest { | ||||
|   @Test | ||||
|   public void test() throws IOException { | ||||
|     String[] args = {}; | ||||
|     App.main(args); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user