From 9341d6f75146f46415b54f025a49b54679a02cbc Mon Sep 17 00:00:00 2001 From: "dhrubajyoti.bhattacharjee" Date: Fri, 10 Nov 2017 00:18:16 +0530 Subject: [PATCH 01/16] BAEL-1160 Introduction to Apache Lucene --- lucene/pom.xml | 37 +++++++++ .../baeldung/lucene/InMemoryLuceneIndex.java | 78 +++++++++++++++++++ .../lucene/LuceneInMemorySearchTest.java | 23 ++++++ pom.xml | 1 + 4 files changed, 139 insertions(+) create mode 100644 lucene/pom.xml create mode 100644 lucene/src/main/java/com/baeldung/lucene/InMemoryLuceneIndex.java create mode 100644 lucene/src/test/java/com/baeldung/lucene/LuceneInMemorySearchTest.java diff --git a/lucene/pom.xml b/lucene/pom.xml new file mode 100644 index 0000000000..42b81a7d4a --- /dev/null +++ b/lucene/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + lucene + 0.0.1-SNAPSHOT + lucene + An Apache Lucene demo application + + + + + org.apache.lucene + lucene-core + 7.1.0 + + + + org.apache.lucene + lucene-queryparser + 7.1.0 + + + + junit + junit + 4.12 + test + + + + + \ No newline at end of file diff --git a/lucene/src/main/java/com/baeldung/lucene/InMemoryLuceneIndex.java b/lucene/src/main/java/com/baeldung/lucene/InMemoryLuceneIndex.java new file mode 100644 index 0000000000..40a35fad86 --- /dev/null +++ b/lucene/src/main/java/com/baeldung/lucene/InMemoryLuceneIndex.java @@ -0,0 +1,78 @@ +package com.baeldung.lucene; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.TextField; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.queryparser.classic.ParseException; +import org.apache.lucene.queryparser.classic.QueryParser; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.ScoreDoc; +import org.apache.lucene.search.TopDocs; +import org.apache.lucene.store.Directory; + +public class InMemoryLuceneIndex { + + private Directory memoryIndex; + private StandardAnalyzer analyzer; + + public InMemoryLuceneIndex(Directory memoryIndex, StandardAnalyzer analyzer) { + super(); + this.memoryIndex = memoryIndex; + this.analyzer = analyzer; + } + + /** + * + * @param title + * @param body + */ + public void indexDocument(String title, String body) { + + IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer); + try { + IndexWriter writter = new IndexWriter(memoryIndex, indexWriterConfig); + Document document = new Document(); + + document.add(new TextField("title", title, Field.Store.YES)); + document.add(new TextField("body", body, Field.Store.YES)); + + writter.addDocument(document); + writter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public List searchIndex(String inField, String queryString) { + try { + Query query = new QueryParser(inField, analyzer).parse(queryString); + + IndexReader indexReader = DirectoryReader.open(memoryIndex); + IndexSearcher searcher = new IndexSearcher(indexReader); + TopDocs topDocs = searcher.search(query, 10); + List documents = new ArrayList<>(); + for (ScoreDoc scoreDoc : topDocs.scoreDocs) { + documents.add(searcher.doc(scoreDoc.doc)); + } + + return documents; + } catch (IOException | ParseException e) { + e.printStackTrace(); + } + return null; + + } + +} + + diff --git a/lucene/src/test/java/com/baeldung/lucene/LuceneInMemorySearchTest.java b/lucene/src/test/java/com/baeldung/lucene/LuceneInMemorySearchTest.java new file mode 100644 index 0000000000..c3a498a4b8 --- /dev/null +++ b/lucene/src/test/java/com/baeldung/lucene/LuceneInMemorySearchTest.java @@ -0,0 +1,23 @@ +package com.baeldung.lucene; + +import java.util.List; + +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.store.RAMDirectory; +import org.junit.Assert; +import org.junit.Test; + +public class LuceneInMemorySearchTest { + + @Test + public void givenSearchQueryWhenFetchedDocumentThenCorrect() { + InMemoryLuceneIndex inMemoryLuceneIndex = new InMemoryLuceneIndex(new RAMDirectory(), new StandardAnalyzer()); + inMemoryLuceneIndex.indexDocument("Hello world", "Some hello world "); + + List documents = inMemoryLuceneIndex.searchIndex("body", "world"); + + Assert.assertEquals("Hello world", documents.get(0).get("title")); + } + +} diff --git a/pom.xml b/pom.xml index bc8e35ba94..403cd47aa6 100644 --- a/pom.xml +++ b/pom.xml @@ -260,6 +260,7 @@ saas deeplearning4j spring-boot-admin + lucene From c0f9c00a3b40648d72af62ee6ec878d3cae28346 Mon Sep 17 00:00:00 2001 From: Alejandro Gervasio Date: Tue, 14 Nov 2017 04:39:46 -0300 Subject: [PATCH 02/16] Implementing the Template Method Pattern with Java - BAEL-1289 (#3038) * Initial Commit * Update HighEndComputerBuilder.java * Update HighEndComputerBuilder.java * Update StandardComputerBuilder.java * Update TemplateMethodPatternTest.java * Update ComputerBuilder.java * Delete HighEndComputer.java * Delete StandardComputer.java --- .../templatemethodpattern/model/Computer.java | 28 +++---------------- .../model/ComputerBuilder.java | 6 ++-- .../model/HighEndComputer.java | 26 ----------------- .../model/HighEndComputerBuilder.java | 8 +++--- .../model/StandardComputer.java | 25 ----------------- .../model/StandardComputerBuilder.java | 6 ++-- .../TemplateMethodPatternTest.java | 5 ++-- 7 files changed, 16 insertions(+), 88 deletions(-) delete mode 100644 patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java delete mode 100644 patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java index d422204b82..939071d843 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java @@ -2,36 +2,16 @@ package com.baeldung.templatemethodpattern.model; import java.util.HashMap; import java.util.Map; -import java.util.ArrayList; -import java.util.List; -public abstract class ComputerBuilder { +public class Computer { - protected Map computerParts = new HashMap<>(); - protected List moterboardSetupStatus = new ArrayList<>(); + private Map computerParts = new HashMap<>(); - public final Computer buildComputer() { - addMotherboard(); - setupMotherboard(); - addProcessor(); - return getComputer(); + public Computer(Map computerParts) { + this.computerParts = computerParts; } - public abstract void addMotherboard(); - - public abstract void setupMotherboard(); - - public abstract void addProcessor(); - - public List getMotherboardSetupStatus() { - return moterboardSetupStatus; - } - public Map getComputerParts() { return computerParts; } - - private Computer getComputer() { - return new Computer(computerParts); - } } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java index f264d33215..7526af4e52 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java @@ -8,7 +8,7 @@ import java.util.Map; public abstract class ComputerBuilder { protected Map computerParts = new HashMap<>(); - protected List moterboardSetupStatus = new ArrayList<>(); + protected List motherboardSetupStatus = new ArrayList<>(); public final Computer buildComputer() { addMotherboard(); @@ -24,9 +24,9 @@ public abstract class ComputerBuilder { public abstract void addProcessor(); public List getMotherboardSetupStatus() { - return moterboardSetupStatus; + return motherboardSetupStatus; } - + public Map getComputerParts() { return computerParts; } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java deleted file mode 100644 index 8d80e1e108..0000000000 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.templatemethodpattern.model; - -public class HighEndComputer extends Computer { - - @Override - public void addMotherboard() { - computerParts.put("Motherboard", "High-end Motherboard"); - } - - @Override - public void setupMotherboard() { - moterboardSetupStatus.add("Screwing the high-end motherboard to the case."); - moterboardSetupStatus.add("Pluging in the power supply connectors."); - moterboardSetupStatus.forEach(step -> System.out.println(step)); - } - - @Override - public void addProcessor() { - computerParts.put("Processor", "High-end Processor"); - } - - @Override - public void addMotherboard() { - computerParts.put("Motherboard", "High End Motherboard"); - } -} diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java index cf53a2ae6c..baa800ca8f 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java @@ -9,13 +9,13 @@ public class HighEndComputerBuilder extends ComputerBuilder { @Override public void setupMotherboard() { - moterboardSetupStatus.add("Screwing the high-end motherboard to the case."); - moterboardSetupStatus.add("Pluging in the power supply connectors."); - moterboardSetupStatus.forEach(step -> System.out.println(step)); + motherboardSetupStatus.add("Screwing the high-end motherboard to the case."); + motherboardSetupStatus.add("Pluging in the power supply connectors."); + motherboardSetupStatus.forEach(step -> System.out.println(step)); } @Override public void addProcessor() { - computerParts.put("Processor", "High-end Processor"); + computerParts.put("Processor", "High-end Processor"); } } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java deleted file mode 100644 index 8410ad88ee..0000000000 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.templatemethodpattern.model; - -public class StandardComputer extends Computer { - - public void addMotherboard() { - computerParts.put("Motherboard", "Standard Motherboard"); - } - - @Override - public void setupMotherboard() { - moterboardSetupStatus.add("Screwing the standard motherboard to the case."); - moterboardSetupStatus.add("Pluging in the power supply connectors."); - moterboardSetupStatus.forEach(step -> System.out.println(step)); - } - - @Override - public void addProcessor() { - computerParts.put("Processor", "Standard Processor"); - } - - @Override - public void addMotherboard() { - computerParts.put("Motherboard", "Standard Motherboard"); - } -} diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java index 1d9bd0e00f..78547dc38b 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java @@ -9,9 +9,9 @@ public class StandardComputerBuilder extends ComputerBuilder { @Override public void setupMotherboard() { - moterboardSetupStatus.add("Screwing the standard motherboard to the case."); - moterboardSetupStatus.add("Pluging in the power supply connectors."); - moterboardSetupStatus.forEach(step -> System.out.println(step)); + motherboardSetupStatus.add("Screwing the standard motherboard to the case."); + motherboardSetupStatus.add("Pluging in the power supply connectors."); + motherboardSetupStatus.forEach(step -> System.out.println(step)); } @Override diff --git a/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java b/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java index df5751fb03..6dc62facc6 100644 --- a/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java +++ b/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java @@ -29,8 +29,8 @@ public class TemplateMethodPatternTest { @Test public void givenStandardMotherBoard_whenAddingMotherBoard_thenEqualAssertion() { - standardComputer.addMotherboard(); - assertEquals("Standard Motherboard", standardComputer.getComputerParts().get("Motherboard")); + standardComputerBuilder.addMotherboard(); + assertEquals("Standard Motherboard", standardComputerBuilder.getComputerParts().get("Motherboard")); } @Test @@ -81,7 +81,6 @@ public class TemplateMethodPatternTest { highEndComputerBuilder.buildComputer(); assertEquals(2, highEndComputerBuilder.getComputerParts().size()); } - @Test public void givenAllHighEndParts_whenComputerisBuilt_thenComputerInstance() { assertThat(standardComputerBuilder.buildComputer(), instanceOf(Computer.class)); From ebc5b52b3a59d55712cc79c47a2ee9f3b5df7daf Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Tue, 14 Nov 2017 08:52:11 +0100 Subject: [PATCH 03/16] Update README.MD (#3040) --- drools/README.MD | 1 - 1 file changed, 1 deletion(-) diff --git a/drools/README.MD b/drools/README.MD index e3f00f5047..b2259e2878 100644 --- a/drools/README.MD +++ b/drools/README.MD @@ -1,4 +1,3 @@ ### Relevant Articles: - [Introduction to Drools](http://www.baeldung.com/drools) - [Drools Using Rules from Excel Files](http://www.baeldung.com/drools-excel) -- [Drools Using Rules from Excel Files](http://www.baeldung.com/drools-excel) From 35d44cb6d72e1119ee168405d7d708605685f733 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 14 Nov 2017 11:37:36 +0200 Subject: [PATCH 04/16] Update README.md --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index b4b8d9062e..dcf77ff536 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -114,4 +114,5 @@ - [StringBuilder and StringBuffer in Java](http://www.baeldung.com/java-string-builder-string-buffer) - [Number of Digits in an Integer in Java](http://www.baeldung.com/java-number-of-digits-in-int) - [Proxy, Decorator, Adapter and Bridge Patterns](http://www.baeldung.com/java-structural-design-patterns) +- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin) From d6096fc58bde01cce6d008aa36af035abde23558 Mon Sep 17 00:00:00 2001 From: bahti Date: Tue, 14 Nov 2017 14:17:57 +0200 Subject: [PATCH 05/16] BAEL 1185 Lazy Verification with Mockito 2 mini-article accompanying code (#2985) * BAEL-1185 Add Mockito2 lazy verification test * Test multiple exceptions with lazy verification * move mockito2 lazyVerificationTest to testing-modules * update test method name in lazyverificationtest --- .../mockito/java8/LazyVerificationTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/LazyVerificationTest.java diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/LazyVerificationTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/LazyVerificationTest.java new file mode 100644 index 0000000000..43b39d6859 --- /dev/null +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/LazyVerificationTest.java @@ -0,0 +1,34 @@ +package com.baeldung.mockito.java8; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.util.List; + +import org.junit.Test; +import org.mockito.exceptions.base.MockitoAssertionError; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.VerificationCollector; + +public class LazyVerificationTest { + + @Test + public void whenLazilyVerified_thenReportsMultipleFailures() { + VerificationCollector collector = MockitoJUnit.collector() + .assertLazily(); + + List mockList = mock(List.class); + verify(mockList).add("one"); + verify(mockList).clear(); + + try { + collector.collectAndReport(); + } catch (MockitoAssertionError error) { + assertTrue(error.getMessage() + .contains("1. Wanted but not invoked:")); + assertTrue(error.getMessage() + .contains("2. Wanted but not invoked:")); + } + } +} From 62e5e2f75d0a3085b32cf5910d9177a8e37114d6 Mon Sep 17 00:00:00 2001 From: Doha2012 Date: Tue, 14 Nov 2017 14:47:48 +0200 Subject: [PATCH 06/16] add readme to grouping modules (#3039) * move security content from spring-security-rest-full * swagger update * move query language to new module * rename spring-security-rest-full to spring-rest-full * group persistence modules * group testing modules * try fix conflict * cleanup * group and cleanup * add readme to grouping modules --- guava-modules/README.md | 3 +++ logging-modules/README.md | 3 +++ persistence-modules/README.md | 3 +++ testing-modules/README.md | 3 +++ 4 files changed, 12 insertions(+) create mode 100644 guava-modules/README.md create mode 100644 logging-modules/README.md create mode 100644 persistence-modules/README.md create mode 100644 testing-modules/README.md diff --git a/guava-modules/README.md b/guava-modules/README.md new file mode 100644 index 0000000000..79e45a89e7 --- /dev/null +++ b/guava-modules/README.md @@ -0,0 +1,3 @@ + +## Guava Modules + diff --git a/logging-modules/README.md b/logging-modules/README.md new file mode 100644 index 0000000000..23458cf30b --- /dev/null +++ b/logging-modules/README.md @@ -0,0 +1,3 @@ + +## Logging Modules + diff --git a/persistence-modules/README.md b/persistence-modules/README.md new file mode 100644 index 0000000000..6c2b1d2ca9 --- /dev/null +++ b/persistence-modules/README.md @@ -0,0 +1,3 @@ + +## Persistence Modules + diff --git a/testing-modules/README.md b/testing-modules/README.md new file mode 100644 index 0000000000..3fbeea6188 --- /dev/null +++ b/testing-modules/README.md @@ -0,0 +1,3 @@ + +## Testing Modules + From d64b61548e57ae0a73f8d96aab02139f9aff865a Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Tue, 14 Nov 2017 13:58:56 +0100 Subject: [PATCH 07/16] Update pom.xml (#3041) --- drools/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drools/pom.xml b/drools/pom.xml index 971bd5f4b8..17b1e1129d 100644 --- a/drools/pom.xml +++ b/drools/pom.xml @@ -13,7 +13,7 @@ 4.4.6 - 7.1.0.Beta2 + 7.4.1.Final 3.13 @@ -65,4 +65,4 @@ - \ No newline at end of file + From 1c543f8f866ec64ab6f32d85b12f260d250f3756 Mon Sep 17 00:00:00 2001 From: Marcos Lopez Gonzalez Date: Tue, 14 Nov 2017 18:14:01 +0100 Subject: [PATCH 08/16] BAEL-1233 - Enabled Annotation in Spring 5 Testing (#3031) * tests with enabled annotations * rollback pom * formatting --- .../com/baeldung/jupiter/EnabledOnJava8.java | 18 +++++++ .../jupiter/Spring5EnabledAnnotationTest.java | 50 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 spring-5/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java create mode 100644 spring-5/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java diff --git a/spring-5/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java b/spring-5/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java new file mode 100644 index 0000000000..c6d3b7ff10 --- /dev/null +++ b/spring-5/src/test/java/com/baeldung/jupiter/EnabledOnJava8.java @@ -0,0 +1,18 @@ +package com.baeldung.jupiter; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.test.context.junit.jupiter.EnabledIf; + +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@EnabledIf( + expression = "#{systemProperties['java.version'].startsWith('1.8')}", + reason = "Enabled on Java 8" +) +public @interface EnabledOnJava8 { + +} diff --git a/spring-5/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java b/spring-5/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java new file mode 100644 index 0000000000..ae058bc8ba --- /dev/null +++ b/spring-5/src/test/java/com/baeldung/jupiter/Spring5EnabledAnnotationTest.java @@ -0,0 +1,50 @@ +package com.baeldung.jupiter; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.DisabledIf; +import org.springframework.test.context.junit.jupiter.EnabledIf; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +@SpringJUnitConfig(Spring5EnabledAnnotationTest.Config.class) +@TestPropertySource(properties = { "tests.enabled=true" }) +public class Spring5EnabledAnnotationTest { + + @Configuration + static class Config { + } + + @EnabledIf("true") + @Test + void givenEnabledIfLiteral_WhenTrue_ThenTestExecuted() { + assertTrue(true); + } + + @EnabledIf(expression = "${tests.enabled}", loadContext = true) + @Test + void givenEnabledIfExpression_WhenTrue_ThenTestExecuted() { + assertTrue(true); + } + + @EnabledIf("#{systemProperties['java.version'].startsWith('1.8')}") + @Test + void givenEnabledIfSpel_WhenTrue_ThenTestExecuted() { + assertTrue(true); + } + + @EnabledOnJava8 + @Test + void givenEnabledOnJava8_WhenTrue_ThenTestExecuted() { + assertTrue(true); + } + + @DisabledIf("#{systemProperties['java.version'].startsWith('1.7')}") + @Test + void givenDisabledIf_WhenTrue_ThenTestNotExecuted() { + assertTrue(true); + } + +} From 95868bf28ec649f88ae0b69bfa63a6badb49af68 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 15 Nov 2017 07:24:54 +0100 Subject: [PATCH 09/16] Update README.md (#3015) --- testing-modules/mocks/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/testing-modules/mocks/README.md b/testing-modules/mocks/README.md index 15370b812b..d7b817c518 100644 --- a/testing-modules/mocks/README.md +++ b/testing-modules/mocks/README.md @@ -1,6 +1,5 @@ ## Relevant articles: -- [Introduction to MockServer](http://www.baeldung.com/mockserver) - [JMockit Advanced Usage](http://www.baeldung.com/jmockit-advanced-usage) - [A Guide to JMockit Expectations](http://www.baeldung.com/jmockit-expectations) - [JMockit 101](http://www.baeldung.com/jmockit-101) From 499f57cad423581c977b3eee27cf2c5841a15123 Mon Sep 17 00:00:00 2001 From: Dassi orleando Date: Wed, 15 Nov 2017 07:31:59 +0100 Subject: [PATCH 10/16] BAEL-1190: JUnit 5 upgrade (#3048) * Different types of bean injection in Spring * Difference between two dates in java * Update README.md * Simple clean of difference between dates * Clean my test article * Improve dates diff: for dates and datetimes * Move difference between dates from core-java to libraries * BAEL-890 - Kotlin-Allopen with Spring example * BAEL-1107 - Introduction to Apache Cayenne Orm * BAEL-1107: update formating and version of libs * BAEL-1107: update properties of Author * BAEL-1157: Apache Cayenne - Advanced Querying * BAEL-1157: Fix imports * BAEL-1157: code indentation * BAEL-1157: Update list of author names * BAEL-132: Configure Jenkins to Run and Show Jmeter Tests * Removed submodule spring-jmeter-jenkins * Commit again spring-jmeter-jenkins * BAEL-1190: JUnit 5 upgrade --- testing-modules/junit-5/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index 229703ccf5..2be8937d04 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -20,7 +20,7 @@ UTF-8 1.8 - 5.0.1 + 5.0.2 1.0.1 4.12.1 2.8.2 @@ -127,4 +127,4 @@ - \ No newline at end of file + From af50b1e59cbb15e0bcedf15375879b42132aced3 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 15 Nov 2017 09:26:24 +0200 Subject: [PATCH 11/16] Updated a link to the article (#3047) * code snippets for the `Java 9 Stream API improvements` article * code snippets for the `Java 9 Stream API improvements` article [2 attempt] * removed the first attempt * the Spring 5 WebClient * delted stream features test * HttpMediaTypeNotAcceptableExceptionExampleController [0] * reactive web client service was removed * new WebClient * new WebClient [2] * spring-rest-shell init * pom added * readme added * updated a link to the article --- spring-rest-shell/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-rest-shell/README.md b/spring-rest-shell/README.md index 06e18450c6..901d9a51ee 100644 --- a/spring-rest-shell/README.md +++ b/spring-rest-shell/README.md @@ -2,4 +2,4 @@ ### Relevant Articles -- [Spring REST Shell](http://www.baeldung.com/) \ No newline at end of file +- [Spring REST Shell](http://www.baeldung.com/spring-rest-shell) \ No newline at end of file From 9685875496aaab220d3d7316ca5da176cd8c3876 Mon Sep 17 00:00:00 2001 From: adamd1985 Date: Wed, 15 Nov 2017 17:28:49 +0100 Subject: [PATCH 12/16] Revert "Implementing the Template Method Pattern with Java - BAEL-1289 (#3038)" (#3042) This reverts commit c0f9c00a3b40648d72af62ee6ec878d3cae28346. --- .../templatemethodpattern/model/Computer.java | 28 ++++++++++++++++--- .../model/ComputerBuilder.java | 6 ++-- .../model/HighEndComputer.java | 26 +++++++++++++++++ .../model/HighEndComputerBuilder.java | 8 +++--- .../model/StandardComputer.java | 25 +++++++++++++++++ .../model/StandardComputerBuilder.java | 6 ++-- .../TemplateMethodPatternTest.java | 5 ++-- 7 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java create mode 100644 patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java index 939071d843..d422204b82 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java @@ -2,16 +2,36 @@ package com.baeldung.templatemethodpattern.model; import java.util.HashMap; import java.util.Map; +import java.util.ArrayList; +import java.util.List; -public class Computer { +public abstract class ComputerBuilder { - private Map computerParts = new HashMap<>(); + protected Map computerParts = new HashMap<>(); + protected List moterboardSetupStatus = new ArrayList<>(); - public Computer(Map computerParts) { - this.computerParts = computerParts; + public final Computer buildComputer() { + addMotherboard(); + setupMotherboard(); + addProcessor(); + return getComputer(); } + public abstract void addMotherboard(); + + public abstract void setupMotherboard(); + + public abstract void addProcessor(); + + public List getMotherboardSetupStatus() { + return moterboardSetupStatus; + } + public Map getComputerParts() { return computerParts; } + + private Computer getComputer() { + return new Computer(computerParts); + } } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java index 7526af4e52..f264d33215 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java @@ -8,7 +8,7 @@ import java.util.Map; public abstract class ComputerBuilder { protected Map computerParts = new HashMap<>(); - protected List motherboardSetupStatus = new ArrayList<>(); + protected List moterboardSetupStatus = new ArrayList<>(); public final Computer buildComputer() { addMotherboard(); @@ -24,9 +24,9 @@ public abstract class ComputerBuilder { public abstract void addProcessor(); public List getMotherboardSetupStatus() { - return motherboardSetupStatus; + return moterboardSetupStatus; } - + public Map getComputerParts() { return computerParts; } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java new file mode 100644 index 0000000000..8d80e1e108 --- /dev/null +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java @@ -0,0 +1,26 @@ +package com.baeldung.templatemethodpattern.model; + +public class HighEndComputer extends Computer { + + @Override + public void addMotherboard() { + computerParts.put("Motherboard", "High-end Motherboard"); + } + + @Override + public void setupMotherboard() { + moterboardSetupStatus.add("Screwing the high-end motherboard to the case."); + moterboardSetupStatus.add("Pluging in the power supply connectors."); + moterboardSetupStatus.forEach(step -> System.out.println(step)); + } + + @Override + public void addProcessor() { + computerParts.put("Processor", "High-end Processor"); + } + + @Override + public void addMotherboard() { + computerParts.put("Motherboard", "High End Motherboard"); + } +} diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java index baa800ca8f..cf53a2ae6c 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java @@ -9,13 +9,13 @@ public class HighEndComputerBuilder extends ComputerBuilder { @Override public void setupMotherboard() { - motherboardSetupStatus.add("Screwing the high-end motherboard to the case."); - motherboardSetupStatus.add("Pluging in the power supply connectors."); - motherboardSetupStatus.forEach(step -> System.out.println(step)); + moterboardSetupStatus.add("Screwing the high-end motherboard to the case."); + moterboardSetupStatus.add("Pluging in the power supply connectors."); + moterboardSetupStatus.forEach(step -> System.out.println(step)); } @Override public void addProcessor() { - computerParts.put("Processor", "High-end Processor"); + computerParts.put("Processor", "High-end Processor"); } } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java new file mode 100644 index 0000000000..8410ad88ee --- /dev/null +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java @@ -0,0 +1,25 @@ +package com.baeldung.templatemethodpattern.model; + +public class StandardComputer extends Computer { + + public void addMotherboard() { + computerParts.put("Motherboard", "Standard Motherboard"); + } + + @Override + public void setupMotherboard() { + moterboardSetupStatus.add("Screwing the standard motherboard to the case."); + moterboardSetupStatus.add("Pluging in the power supply connectors."); + moterboardSetupStatus.forEach(step -> System.out.println(step)); + } + + @Override + public void addProcessor() { + computerParts.put("Processor", "Standard Processor"); + } + + @Override + public void addMotherboard() { + computerParts.put("Motherboard", "Standard Motherboard"); + } +} diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java index 78547dc38b..1d9bd0e00f 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java @@ -9,9 +9,9 @@ public class StandardComputerBuilder extends ComputerBuilder { @Override public void setupMotherboard() { - motherboardSetupStatus.add("Screwing the standard motherboard to the case."); - motherboardSetupStatus.add("Pluging in the power supply connectors."); - motherboardSetupStatus.forEach(step -> System.out.println(step)); + moterboardSetupStatus.add("Screwing the standard motherboard to the case."); + moterboardSetupStatus.add("Pluging in the power supply connectors."); + moterboardSetupStatus.forEach(step -> System.out.println(step)); } @Override diff --git a/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java b/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java index 6dc62facc6..df5751fb03 100644 --- a/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java +++ b/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java @@ -29,8 +29,8 @@ public class TemplateMethodPatternTest { @Test public void givenStandardMotherBoard_whenAddingMotherBoard_thenEqualAssertion() { - standardComputerBuilder.addMotherboard(); - assertEquals("Standard Motherboard", standardComputerBuilder.getComputerParts().get("Motherboard")); + standardComputer.addMotherboard(); + assertEquals("Standard Motherboard", standardComputer.getComputerParts().get("Motherboard")); } @Test @@ -81,6 +81,7 @@ public class TemplateMethodPatternTest { highEndComputerBuilder.buildComputer(); assertEquals(2, highEndComputerBuilder.getComputerParts().size()); } + @Test public void givenAllHighEndParts_whenComputerisBuilt_thenComputerInstance() { assertThat(standardComputerBuilder.buildComputer(), instanceOf(Computer.class)); From 8957b9414c59f7d9f5451cac3a4e8b665f666e50 Mon Sep 17 00:00:00 2001 From: Alejandro Gervasio Date: Wed, 15 Nov 2017 13:43:57 -0300 Subject: [PATCH 13/16] Initial Commit (#3045) --- .../baeldung/templatemethodpattern/model/ComputerBuilder.java | 4 ++-- .../templatemethodpatterntest/TemplateMethodPatternTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java index f264d33215..9d8eae7f80 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java @@ -20,9 +20,9 @@ public abstract class ComputerBuilder { public abstract void addMotherboard(); public abstract void setupMotherboard(); - + public abstract void addProcessor(); - + public List getMotherboardSetupStatus() { return moterboardSetupStatus; } diff --git a/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java b/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java index df5751fb03..39888d5ad5 100644 --- a/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java +++ b/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java @@ -77,7 +77,7 @@ public class TemplateMethodPatternTest { } @Test - public void givenAllHighEnddParts_whenBuildingComputer_thenTwoParts() { + public void givenAllHighEndParts_whenBuildingComputer_thenTwoParts() { highEndComputerBuilder.buildComputer(); assertEquals(2, highEndComputerBuilder.getComputerParts().size()); } From d54917c7e9f0f74c40982571af8ac9f61782b7cb Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 15 Nov 2017 17:57:10 +0100 Subject: [PATCH 14/16] Spring cloud samples (#3010) * Matchers is now deprecated in Mockito 2, it's now replaced by ArgumentMatchers * BAEL-1069: Guide to diamond operator in Java * Changes after review * BAEL-719: Intro to Spring Cloud Stream * Pull request changes done * Renamed unit tests * Add spring-cloud-stream * Add module * Exclude integration tests from spring-cloud --- drools/pom.xml | 125 ++++++++++-------- spring-cloud/pom.xml | 10 +- spring-cloud/spring-cloud-stream/pom.xml | 71 ++++++++++ .../spring-cloud-stream-rabbit/pom.xml | 32 +++++ .../MultipleOutputsServiceApplication.java | 38 ++++++ ...tputsWithConditionsServiceApplication.java | 39 ++++++ .../rabbit/MyLoggerServiceApplication.java | 32 +++++ .../messages/TextPlainMessageConverter.java | 26 ++++ .../cloud/stream/rabbit/model/LogMessage.java | 32 +++++ .../stream/rabbit/processor/MyProcessor.java | 19 +++ .../src/main/resources/application.yml | 28 ++++ ...putsServiceApplicationIntegrationTest.java | 52 ++++++++ ...sWithConditionsServiceIntegrationTest.java | 52 ++++++++ .../MyLoggerApplicationIntegrationTest.java | 40 ++++++ 14 files changed, 539 insertions(+), 57 deletions(-) create mode 100644 spring-cloud/spring-cloud-stream/pom.xml create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/pom.xml create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsServiceApplication.java create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsWithConditionsServiceApplication.java create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MyLoggerServiceApplication.java create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/messages/TextPlainMessageConverter.java create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/model/LogMessage.java create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/processor/MyProcessor.java create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/resources/application.yml create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsServiceApplicationIntegrationTest.java create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsWithConditionsServiceIntegrationTest.java create mode 100644 spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MyLoggerApplicationIntegrationTest.java diff --git a/drools/pom.xml b/drools/pom.xml index 17b1e1129d..5f228802fa 100644 --- a/drools/pom.xml +++ b/drools/pom.xml @@ -1,68 +1,87 @@ - 4.0.0 - - drools - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + drools + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + 4.4.6 7.4.1.Final 3.13 - - - org.apache.httpcomponents - httpcore - ${http-component-version} - - - - org.kie - kie-ci - ${drools-version} - - - org.drools - drools-decisiontables - ${drools-version} - + + + org.apache.httpcomponents + httpcore + ${http-component-version} + + + + org.kie + kie-ci + ${drools-version} + + + org.drools + drools-decisiontables + ${drools-version} + - - org.drools - drools-core - ${drools-version} - - - org.drools - drools-compiler - ${drools-version} - - - org.apache.poi - poi - ${apache-poi-version} - + + org.drools + drools-core + ${drools-version} + + + org.drools + drools-compiler + ${drools-version} + + + org.apache.poi + poi + ${apache-poi-version} + - - org.apache.poi - poi-ooxml - ${apache-poi-version} - + + org.apache.poi + poi-ooxml + ${apache-poi-version} + - - org.springframework - spring-core - 4.3.6.RELEASE - + + org.springframework + spring-core + 4.3.6.RELEASE + - + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + 3 + true + + **/*IntegrationTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/JdbcTest.java + **/*LiveTest.java + + + + + diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index 93bf6ea74b..fd023a5ea5 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -1,7 +1,7 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung.spring.cloud @@ -15,8 +15,9 @@ spring-cloud-ribbon-client spring-cloud-rest spring-cloud-zookeeper - spring-cloud-gateway - spring-cloud-connectors-heroku + spring-cloud-gateway + spring-cloud-stream + spring-cloud-connectors-heroku pom @@ -38,6 +39,7 @@ 1.2.3.RELEASE 1.2.3.RELEASE 1.2.3.RELEASE + 1.3.0.RELEASE 1.4.2.RELEASE 3.6.0 1.4.2.RELEASE diff --git a/spring-cloud/spring-cloud-stream/pom.xml b/spring-cloud/spring-cloud-stream/pom.xml new file mode 100644 index 0000000000..5ec24268d9 --- /dev/null +++ b/spring-cloud/spring-cloud-stream/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + org.baeldung + spring-cloud-stream + pom + + spring-cloud-stream + + + com.baeldung.spring.cloud + spring-cloud + 1.0.0-SNAPSHOT + + + + spring-cloud-stream-rabbit + + + + UTF-8 + 3.6.0 + + + + + + org.springframework.cloud + spring-cloud-starter-stream-rabbit + ${spring-cloud-stream.version} + + + + org.springframework.cloud + spring-cloud-stream + ${spring-cloud-stream.version} + + + + org.springframework.cloud + spring-cloud-stream-test-support + ${spring-cloud-stream.version} + test + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-maven-plugin.version} + + + + + diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/pom.xml b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/pom.xml new file mode 100644 index 0000000000..a954a7035e --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + spring-cloud-stream-rabbit + jar + + spring-cloud-stream-rabbit + Simple Spring Cloud Stream + + + org.baeldung + spring-cloud-stream + 1.0.0-SNAPSHOT + .. + + + + + org.springframework.cloud + spring-cloud-starter-stream-rabbit + + + + org.springframework.cloud + spring-cloud-stream-test-support + test + + + + diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsServiceApplication.java b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsServiceApplication.java new file mode 100644 index 0000000000..375494dfac --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsServiceApplication.java @@ -0,0 +1,38 @@ +package com.baeldung.spring.cloud.stream.rabbit; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.annotation.StreamListener; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.MessageBuilder; + +import com.baeldung.spring.cloud.stream.rabbit.processor.MyProcessor; + +@SpringBootApplication +@EnableBinding(MyProcessor.class) +public class MultipleOutputsServiceApplication { + public static void main(String[] args) { + SpringApplication.run(MultipleOutputsServiceApplication.class, args); + } + + @Autowired + private MyProcessor processor; + + @StreamListener(MyProcessor.INPUT) + public void routeValues(Integer val) { + if (val < 10) { + processor.anOutput() + .send(message(val)); + } else { + processor.anotherOutput() + .send(message(val)); + } + } + + private static final Message message(T val) { + return MessageBuilder.withPayload(val) + .build(); + } +} diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsWithConditionsServiceApplication.java b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsWithConditionsServiceApplication.java new file mode 100644 index 0000000000..4729e418b6 --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsWithConditionsServiceApplication.java @@ -0,0 +1,39 @@ +package com.baeldung.spring.cloud.stream.rabbit; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.annotation.StreamListener; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.MessageBuilder; + +import com.baeldung.spring.cloud.stream.rabbit.processor.MyProcessor; + +@SpringBootApplication +@EnableBinding(MyProcessor.class) +public class MultipleOutputsWithConditionsServiceApplication { + public static void main(String[] args) { + SpringApplication.run(MultipleOutputsWithConditionsServiceApplication.class, args); + } + + @Autowired + private MyProcessor processor; + + @StreamListener(target = MyProcessor.INPUT, condition = "payload < 10") + public void routeValuesToAnOutput(Integer val) { + processor.anOutput() + .send(message(val)); + } + + @StreamListener(target = MyProcessor.INPUT, condition = "payload >= 10") + public void routeValuesToAnotherOutput(Integer val) { + processor.anotherOutput() + .send(message(val)); + } + + private static final Message message(T val) { + return MessageBuilder.withPayload(val) + .build(); + } +} diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MyLoggerServiceApplication.java b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MyLoggerServiceApplication.java new file mode 100644 index 0000000000..aac551e544 --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/MyLoggerServiceApplication.java @@ -0,0 +1,32 @@ +package com.baeldung.spring.cloud.stream.rabbit; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.stream.annotation.EnableBinding; +import org.springframework.cloud.stream.annotation.StreamListener; +import org.springframework.cloud.stream.messaging.Processor; +import org.springframework.context.annotation.Bean; +import org.springframework.messaging.converter.MessageConverter; +import org.springframework.messaging.handler.annotation.SendTo; + +import com.baeldung.spring.cloud.stream.rabbit.messages.TextPlainMessageConverter; +import com.baeldung.spring.cloud.stream.rabbit.model.LogMessage; + +@SpringBootApplication +@EnableBinding(Processor.class) +public class MyLoggerServiceApplication { + public static void main(String[] args) { + SpringApplication.run(MyLoggerServiceApplication.class, args); + } + + @Bean + public MessageConverter providesTextPlainMessageConverter() { + return new TextPlainMessageConverter(); + } + + @StreamListener(Processor.INPUT) + @SendTo(Processor.OUTPUT) + public LogMessage enrichLogMessage(LogMessage log) { + return new LogMessage(String.format("[1]: %s", log.getMessage())); + } +} diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/messages/TextPlainMessageConverter.java b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/messages/TextPlainMessageConverter.java new file mode 100644 index 0000000000..d690ee38a9 --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/messages/TextPlainMessageConverter.java @@ -0,0 +1,26 @@ +package com.baeldung.spring.cloud.stream.rabbit.messages; + +import org.springframework.messaging.Message; +import org.springframework.messaging.converter.AbstractMessageConverter; +import org.springframework.util.MimeType; + +import com.baeldung.spring.cloud.stream.rabbit.model.LogMessage; + +public class TextPlainMessageConverter extends AbstractMessageConverter { + + public TextPlainMessageConverter() { + super(new MimeType("text", "plain")); + } + + @Override + protected boolean supports(Class clazz) { + return (LogMessage.class == clazz); + } + + @Override + protected Object convertFromInternal(Message message, Class targetClass, Object conversionHint) { + Object payload = message.getPayload(); + String text = payload instanceof String ? (String) payload : new String((byte[]) payload); + return new LogMessage(text); + } +} diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/model/LogMessage.java b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/model/LogMessage.java new file mode 100644 index 0000000000..44a6ca4d4e --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/model/LogMessage.java @@ -0,0 +1,32 @@ +package com.baeldung.spring.cloud.stream.rabbit.model; + +import java.io.Serializable; + +public class LogMessage implements Serializable { + + private static final long serialVersionUID = -5857383701708275796L; + + private String message; + + public LogMessage() { + + } + + public LogMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return message; + } + +} diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/processor/MyProcessor.java b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/processor/MyProcessor.java new file mode 100644 index 0000000000..563ce06b6f --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/baeldung/spring/cloud/stream/rabbit/processor/MyProcessor.java @@ -0,0 +1,19 @@ +package com.baeldung.spring.cloud.stream.rabbit.processor; + +import org.springframework.cloud.stream.annotation.Input; +import org.springframework.cloud.stream.annotation.Output; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.SubscribableChannel; + +public interface MyProcessor { + String INPUT = "myInput"; + + @Input + SubscribableChannel myInput(); + + @Output("myOutput") + MessageChannel anOutput(); + + @Output + MessageChannel anotherOutput(); +} diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/resources/application.yml b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/resources/application.yml new file mode 100644 index 0000000000..3d9d97a736 --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/main/resources/application.yml @@ -0,0 +1,28 @@ +spring: + cloud: + stream: + bindings: + input: + destination: queue.log.messages + binder: local_rabbit + group: logMessageConsumers + output: + destination: queue.pretty.log.messages + binder: local_rabbit + binders: + local_rabbit: + type: rabbit + environment: + spring: + rabbitmq: + host: localhost + port: 5672 + username: guest + password: guest + virtual-host: / +server: + port: 0 +management: + health: + binders: + enabled: true \ No newline at end of file diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsServiceApplicationIntegrationTest.java b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsServiceApplicationIntegrationTest.java new file mode 100644 index 0000000000..898d06897f --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsServiceApplicationIntegrationTest.java @@ -0,0 +1,52 @@ +package com.baeldung.spring.cloud.stream.rabbit; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.stream.test.binder.MessageCollector; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.spring.cloud.stream.rabbit.processor.MyProcessor; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = MultipleOutputsServiceApplication.class) +@DirtiesContext +public class MultipleOutputsServiceApplicationIntegrationTest { + + @Autowired + private MyProcessor pipe; + + @Autowired + private MessageCollector messageCollector; + + @Test + public void whenSendMessage_thenResponseIsInAOutput() { + whenSendMessage(1); + thenPayloadInChannelIs(pipe.anOutput(), 1); + } + + @Test + public void whenSendMessage_thenResponseIsInAnotherOutput() { + whenSendMessage(11); + thenPayloadInChannelIs(pipe.anotherOutput(), 11); + } + + private void whenSendMessage(Integer val) { + pipe.myInput() + .send(MessageBuilder.withPayload(val) + .build()); + } + + private void thenPayloadInChannelIs(MessageChannel channel, Integer expectedValue) { + Object payload = messageCollector.forChannel(channel) + .poll() + .getPayload(); + assertEquals(expectedValue, payload); + } +} diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsWithConditionsServiceIntegrationTest.java b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsWithConditionsServiceIntegrationTest.java new file mode 100644 index 0000000000..c3bf5a1205 --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MultipleOutputsWithConditionsServiceIntegrationTest.java @@ -0,0 +1,52 @@ +package com.baeldung.spring.cloud.stream.rabbit; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.stream.test.binder.MessageCollector; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.spring.cloud.stream.rabbit.processor.MyProcessor; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = MultipleOutputsWithConditionsServiceApplication.class) +@DirtiesContext +public class MultipleOutputsWithConditionsServiceIntegrationTest { + + @Autowired + private MyProcessor pipe; + + @Autowired + private MessageCollector messageCollector; + + @Test + public void whenSendMessage_thenResponseIsInAOutput() { + whenSendMessage(1); + thenPayloadInChannelIs(pipe.anOutput(), 1); + } + + @Test + public void whenSendMessage_thenResponseIsInAnotherOutput() { + whenSendMessage(11); + thenPayloadInChannelIs(pipe.anotherOutput(), 11); + } + + private void whenSendMessage(Integer val) { + pipe.myInput() + .send(MessageBuilder.withPayload(val) + .build()); + } + + private void thenPayloadInChannelIs(MessageChannel channel, Integer expectedValue) { + Object payload = messageCollector.forChannel(channel) + .poll() + .getPayload(); + assertEquals(expectedValue, payload); + } +} diff --git a/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MyLoggerApplicationIntegrationTest.java b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MyLoggerApplicationIntegrationTest.java new file mode 100644 index 0000000000..21d84e79e0 --- /dev/null +++ b/spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/baeldung/spring/cloud/stream/rabbit/MyLoggerApplicationIntegrationTest.java @@ -0,0 +1,40 @@ +package com.baeldung.spring.cloud.stream.rabbit; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.stream.messaging.Processor; +import org.springframework.cloud.stream.test.binder.MessageCollector; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.spring.cloud.stream.rabbit.model.LogMessage; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = MyLoggerServiceApplication.class) +@DirtiesContext +public class MyLoggerApplicationIntegrationTest { + + @Autowired + private Processor pipe; + + @Autowired + private MessageCollector messageCollector; + + @Test + public void whenSendMessage_thenResponseShouldUpdateText() { + pipe.input() + .send(MessageBuilder.withPayload(new LogMessage("This is my message")) + .build()); + + Object payload = messageCollector.forChannel(pipe.output()) + .poll() + .getPayload(); + + assertEquals("[1]: This is my message", payload.toString()); + } +} From 656e89f0893a150d1ff9e88d856f4a511b404976 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Thu, 16 Nov 2017 06:02:47 -0600 Subject: [PATCH 15/16] 1098 README update (#3058) * BAEL-973: updated README * BAEL-1069: Updated README * BAEL-817: add README file * BAEL-1084: README update * BAEL-960: Update README * BAEL-1155: updated README * BAEL-1041: updated README * BAEL-973: Updated README * BAEL-1187: updated README * BAEL-1183: Update README * BAEL-1133: Updated README * BAEL-1098: README update --- testing-modules/rest-testing/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/rest-testing/README.md b/testing-modules/rest-testing/README.md index 37a53dd815..c6185de05f 100644 --- a/testing-modules/rest-testing/README.md +++ b/testing-modules/rest-testing/README.md @@ -10,3 +10,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock) - [REST API Testing with Cucumber](http://www.baeldung.com/cucumber-rest-api-testing) - [Testing a REST API with JBehave](http://www.baeldung.com/jbehave-rest-testing) +- [REST API Testing with Karate](http://www.baeldung.com/karate-rest-api-testing) From bdbee879af049ea73b38c70e66bbb64b662fea9b Mon Sep 17 00:00:00 2001 From: Alejandro Gervasio Date: Thu, 16 Nov 2017 17:28:55 -0300 Subject: [PATCH 16/16] Implementing the Template Method Pattern with Java - BAEL-1289 (#3065) * Initial Commit * Added Domain Classes * Update HighEndComputer.java * Update StandardComputer.java * Update TemplateMethodPatternTest.java --- .../application/Application.java | 4 +-- .../templatemethodpattern/model/Computer.java | 26 +++--------------- .../model/ComputerBuilder.java | 10 +++---- .../model/HighEndComputer.java | 26 ++++-------------- .../model/HighEndComputerBuilder.java | 8 +++--- .../model/StandardComputer.java | 27 +++++-------------- .../model/StandardComputerBuilder.java | 6 ++--- .../TemplateMethodPatternTest.java | 8 +++--- 8 files changed, 33 insertions(+), 82 deletions(-) diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/application/Application.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/application/Application.java index 5570c2e1dd..bd383b4568 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/application/Application.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/application/Application.java @@ -1,11 +1,11 @@ package com.baeldung.templatemethodpattern.application; import com.baeldung.templatemethodpattern.model.Computer; +import com.baeldung.templatemethodpattern.model.StandardComputer; +import com.baeldung.templatemethodpattern.model.HighEndComputer; import com.baeldung.templatemethodpattern.model.ComputerBuilder; import com.baeldung.templatemethodpattern.model.HighEndComputerBuilder; import com.baeldung.templatemethodpattern.model.StandardComputerBuilder; -import com.baeldung.templatemethodpattern.model.HighEndComputer; -import com.baeldung.templatemethodpattern.model.StandardComputer; public class Application { diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java index d422204b82..128eec59ad 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/Computer.java @@ -5,33 +5,15 @@ import java.util.Map; import java.util.ArrayList; import java.util.List; -public abstract class ComputerBuilder { +public class Computer { - protected Map computerParts = new HashMap<>(); - protected List moterboardSetupStatus = new ArrayList<>(); + private Map computerParts = new HashMap<>(); - public final Computer buildComputer() { - addMotherboard(); - setupMotherboard(); - addProcessor(); - return getComputer(); + public Computer(Map computerParts) { + this.computerParts = computerParts; } - public abstract void addMotherboard(); - - public abstract void setupMotherboard(); - - public abstract void addProcessor(); - - public List getMotherboardSetupStatus() { - return moterboardSetupStatus; - } - public Map getComputerParts() { return computerParts; } - - private Computer getComputer() { - return new Computer(computerParts); - } } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java index 9d8eae7f80..39052f4776 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/ComputerBuilder.java @@ -8,7 +8,7 @@ import java.util.Map; public abstract class ComputerBuilder { protected Map computerParts = new HashMap<>(); - protected List moterboardSetupStatus = new ArrayList<>(); + protected List motherboardSetupStatus = new ArrayList<>(); public final Computer buildComputer() { addMotherboard(); @@ -22,11 +22,11 @@ public abstract class ComputerBuilder { public abstract void setupMotherboard(); public abstract void addProcessor(); - - public List getMotherboardSetupStatus() { - return moterboardSetupStatus; - } + public List getMotherboardSetupStatus() { + return motherboardSetupStatus; + } + public Map getComputerParts() { return computerParts; } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java index 8d80e1e108..16d89f1ad6 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputer.java @@ -1,26 +1,10 @@ package com.baeldung.templatemethodpattern.model; -public class HighEndComputer extends Computer { +import java.util.Map; - @Override - public void addMotherboard() { - computerParts.put("Motherboard", "High-end Motherboard"); - } +public class HighEndComputer extends Computer { - @Override - public void setupMotherboard() { - moterboardSetupStatus.add("Screwing the high-end motherboard to the case."); - moterboardSetupStatus.add("Pluging in the power supply connectors."); - moterboardSetupStatus.forEach(step -> System.out.println(step)); - } - - @Override - public void addProcessor() { - computerParts.put("Processor", "High-end Processor"); - } - - @Override - public void addMotherboard() { - computerParts.put("Motherboard", "High End Motherboard"); - } + public HighEndComputer(Map computerParts) { + super(computerParts); + } } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java index cf53a2ae6c..baa800ca8f 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/HighEndComputerBuilder.java @@ -9,13 +9,13 @@ public class HighEndComputerBuilder extends ComputerBuilder { @Override public void setupMotherboard() { - moterboardSetupStatus.add("Screwing the high-end motherboard to the case."); - moterboardSetupStatus.add("Pluging in the power supply connectors."); - moterboardSetupStatus.forEach(step -> System.out.println(step)); + motherboardSetupStatus.add("Screwing the high-end motherboard to the case."); + motherboardSetupStatus.add("Pluging in the power supply connectors."); + motherboardSetupStatus.forEach(step -> System.out.println(step)); } @Override public void addProcessor() { - computerParts.put("Processor", "High-end Processor"); + computerParts.put("Processor", "High-end Processor"); } } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java index 8410ad88ee..14d32d7b64 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputer.java @@ -1,25 +1,10 @@ package com.baeldung.templatemethodpattern.model; - + +import java.util.Map; + public class StandardComputer extends Computer { - public void addMotherboard() { - computerParts.put("Motherboard", "Standard Motherboard"); - } - - @Override - public void setupMotherboard() { - moterboardSetupStatus.add("Screwing the standard motherboard to the case."); - moterboardSetupStatus.add("Pluging in the power supply connectors."); - moterboardSetupStatus.forEach(step -> System.out.println(step)); - } - - @Override - public void addProcessor() { - computerParts.put("Processor", "Standard Processor"); - } - - @Override - public void addMotherboard() { - computerParts.put("Motherboard", "Standard Motherboard"); - } + public StandardComputer(Map computerParts) { + super(computerParts); + } } diff --git a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java index 1d9bd0e00f..78547dc38b 100644 --- a/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java +++ b/patterns/template-method/src/main/java/com/baeldung/templatemethodpattern/model/StandardComputerBuilder.java @@ -9,9 +9,9 @@ public class StandardComputerBuilder extends ComputerBuilder { @Override public void setupMotherboard() { - moterboardSetupStatus.add("Screwing the standard motherboard to the case."); - moterboardSetupStatus.add("Pluging in the power supply connectors."); - moterboardSetupStatus.forEach(step -> System.out.println(step)); + motherboardSetupStatus.add("Screwing the standard motherboard to the case."); + motherboardSetupStatus.add("Pluging in the power supply connectors."); + motherboardSetupStatus.forEach(step -> System.out.println(step)); } @Override diff --git a/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java b/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java index 39888d5ad5..1d608ff2c2 100644 --- a/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java +++ b/patterns/template-method/src/test/java/com/baeldung/templatemethodpatterntest/TemplateMethodPatternTest.java @@ -29,12 +29,12 @@ public class TemplateMethodPatternTest { @Test public void givenStandardMotherBoard_whenAddingMotherBoard_thenEqualAssertion() { - standardComputer.addMotherboard(); - assertEquals("Standard Motherboard", standardComputer.getComputerParts().get("Motherboard")); + standardComputerBuilder.addMotherboard(); + assertEquals("Standard Motherboard", standardComputerBuilder.getComputerParts().get("Motherboard")); } @Test - public void givenStandardMotheroboard_whenSetup_thenTwoEqualAssertions() { + public void givenStandardMotherboard_whenSetup_thenTwoEqualAssertions() { standardComputerBuilder.setupMotherboard(); assertEquals("Screwing the standard motherboard to the case.", standardComputerBuilder.getMotherboardSetupStatus().get(0)); assertEquals("Pluging in the power supply connectors.", standardComputerBuilder.getMotherboardSetupStatus().get(1)); @@ -77,7 +77,7 @@ public class TemplateMethodPatternTest { } @Test - public void givenAllHighEndParts_whenBuildingComputer_thenTwoParts() { + public void givenAllHighEnddParts_whenBuildingComputer_thenTwoParts() { highEndComputerBuilder.buildComputer(); assertEquals(2, highEndComputerBuilder.getComputerParts().size()); }