From 874a2371993b86f1f0abdfc10b7a6e53ac015da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Sepp=C3=A4l=C3=A4?= Date: Sun, 1 Jan 2023 12:43:34 +0200 Subject: [PATCH 1/4] add missing sonar goal --- .github/workflows/maven-pr-builder.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven-pr-builder.yml b/.github/workflows/maven-pr-builder.yml index 0edf916aed8c..e7c2e1413029 100644 --- a/.github/workflows/maven-pr-builder.yml +++ b/.github/workflows/maven-pr-builder.yml @@ -61,7 +61,7 @@ jobs: run: sudo apt-get install -y xvfb - name: Build with Maven and run SonarQube analysis - run: xvfb-run ./mvnw clean verify -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=iluwatar -Dsonar.projectKey=iluwatar_java-design-patterns -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }} -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} + run: xvfb-run ./mvnw clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=iluwatar -Dsonar.projectKey=iluwatar_java-design-patterns -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.base=${{ github.base_ref }} -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} env: # These two env variables are needed for sonar analysis GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From a9cf54b32009e34b834b7e6ed7fcce77b9e043df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Sepp=C3=A4l=C3=A4?= Date: Sun, 1 Jan 2023 12:49:17 +0200 Subject: [PATCH 2/4] fix ServiceContextTest --- .../java/com/iluwatar/context/object/App.java | 24 +++++++++++++++ .../com/iluwatar/context/object/LayerA.java | 24 +++++++++++++++ .../com/iluwatar/context/object/LayerB.java | 24 +++++++++++++++ .../com/iluwatar/context/object/LayerC.java | 24 +++++++++++++++ .../context/object/ServiceContext.java | 24 +++++++++++++++ .../context/object/ServiceContextFactory.java | 24 +++++++++++++++ .../com/iluwatar/contect/object/AppTest.java | 24 +++++++++++++++ .../contect/object/ServiceContextTest.java | 30 +++++++++++++++++-- 8 files changed, 195 insertions(+), 3 deletions(-) diff --git a/context-object/src/main/java/com/iluwatar/context/object/App.java b/context-object/src/main/java/com/iluwatar/context/object/App.java index 4041a52736de..4147357d29aa 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/App.java +++ b/context-object/src/main/java/com/iluwatar/context/object/App.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 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.context.object; import lombok.extern.slf4j.Slf4j; diff --git a/context-object/src/main/java/com/iluwatar/context/object/LayerA.java b/context-object/src/main/java/com/iluwatar/context/object/LayerA.java index 3b471e8a6903..5d1ae45139e4 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/LayerA.java +++ b/context-object/src/main/java/com/iluwatar/context/object/LayerA.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 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.context.object; import lombok.Getter; diff --git a/context-object/src/main/java/com/iluwatar/context/object/LayerB.java b/context-object/src/main/java/com/iluwatar/context/object/LayerB.java index 4c7daab1c7c4..73229d4feeb5 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/LayerB.java +++ b/context-object/src/main/java/com/iluwatar/context/object/LayerB.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 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.context.object; import lombok.Getter; diff --git a/context-object/src/main/java/com/iluwatar/context/object/LayerC.java b/context-object/src/main/java/com/iluwatar/context/object/LayerC.java index f1a2ba03571f..1d1604beb7c7 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/LayerC.java +++ b/context-object/src/main/java/com/iluwatar/context/object/LayerC.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 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.context.object; import lombok.Getter; diff --git a/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java b/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java index d8e78dd25ddf..54f2cecbdcf8 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java +++ b/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 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.context.object; import lombok.Getter; diff --git a/context-object/src/main/java/com/iluwatar/context/object/ServiceContextFactory.java b/context-object/src/main/java/com/iluwatar/context/object/ServiceContextFactory.java index f315ea247080..d7094a0c080b 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/ServiceContextFactory.java +++ b/context-object/src/main/java/com/iluwatar/context/object/ServiceContextFactory.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 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.context.object; /** diff --git a/context-object/src/test/java/com/iluwatar/contect/object/AppTest.java b/context-object/src/test/java/com/iluwatar/contect/object/AppTest.java index 44adacaff262..9c5d72fde8ba 100644 --- a/context-object/src/test/java/com/iluwatar/contect/object/AppTest.java +++ b/context-object/src/test/java/com/iluwatar/contect/object/AppTest.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 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.contect.object; import com.iluwatar.context.object.App; diff --git a/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java b/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java index 3086c45b9495..839a8937246d 100644 --- a/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java +++ b/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java @@ -1,3 +1,27 @@ +/* + * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). + * + * The MIT License + * Copyright © 2014-2022 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.contect.object; import com.iluwatar.context.object.LayerA; @@ -56,14 +80,14 @@ void testScopedDataPassedBetweenLayers() { @Test void testToString() { assertEquals(layerA.getContext().toString(), - "ServiceContext(AccountService=null, SessionService=null, SearchService=null)"); + "ServiceContext(accountService=null, sessionService=null, searchService=null)"); layerA.addAccountInfo(SERVICE); assertEquals(layerA.getContext().toString(), - "ServiceContext(AccountService=SERVICE, SessionService=null, SearchService=null)"); + "ServiceContext(accountService=SERVICE, sessionService=null, searchService=null)"); var layerB = new LayerB(layerA); layerB.addSessionInfo(SERVICE); var layerC = new LayerC(layerB); assertEquals(layerC.getContext().toString(), - "ServiceContext(AccountService=SERVICE, SessionService=SERVICE, SearchService=null)"); + "ServiceContext(accountService=SERVICE, sessionService=SERVICE, searchService=null)"); } } From 05c9672ff2e0f66406924baf4768af7d7171def1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Sepp=C3=A4l=C3=A4?= Date: Sun, 1 Jan 2023 13:27:34 +0200 Subject: [PATCH 3/4] update test --- .../com/iluwatar/contect/object/ServiceContextTest.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java b/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java index 839a8937246d..bab963c7399e 100644 --- a/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java +++ b/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java @@ -79,15 +79,12 @@ void testScopedDataPassedBetweenLayers() { @Test void testToString() { - assertEquals(layerA.getContext().toString(), - "ServiceContext(accountService=null, sessionService=null, searchService=null)"); + assertEquals("ServiceContext(accountService=null, sessionService=null, searchService=null)", layerA.getContext().toString()); layerA.addAccountInfo(SERVICE); - assertEquals(layerA.getContext().toString(), - "ServiceContext(accountService=SERVICE, sessionService=null, searchService=null)"); + assertEquals("ServiceContext(accountService=SERVICE, sessionService=null, searchService=null)", layerA.getContext().toString()); var layerB = new LayerB(layerA); layerB.addSessionInfo(SERVICE); var layerC = new LayerC(layerB); - assertEquals(layerC.getContext().toString(), - "ServiceContext(accountService=SERVICE, sessionService=SERVICE, searchService=null)"); + assertEquals("ServiceContext(accountService=SERVICE, sessionService=SERVICE, searchService=null)", layerC.getContext().toString()); } } From 4b733f28860f4ebe1ada47b43c9e9d0f28641cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Sepp=C3=A4l=C3=A4?= Date: Sun, 1 Jan 2023 14:13:39 +0200 Subject: [PATCH 4/4] refactor test --- .../context/object/ServiceContext.java | 1 - .../contect/object/ServiceContextTest.java | 27 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java b/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java index 54f2cecbdcf8..dcd4e1450602 100644 --- a/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java +++ b/context-object/src/main/java/com/iluwatar/context/object/ServiceContext.java @@ -31,7 +31,6 @@ /** * Where context objects are defined. */ -@ToString @Getter @Setter public class ServiceContext { diff --git a/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java b/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java index bab963c7399e..7fdbb68b4dc5 100644 --- a/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java +++ b/context-object/src/test/java/com/iluwatar/contect/object/ServiceContextTest.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -78,13 +79,31 @@ void testScopedDataPassedBetweenLayers() { } @Test - void testToString() { - assertEquals("ServiceContext(accountService=null, sessionService=null, searchService=null)", layerA.getContext().toString()); + void testLayerContexts() { + assertAll( + () -> assertNull(layerA.getContext().getAccountService()), + () -> assertNull(layerA.getContext().getSearchService()), + () -> assertNull(layerA.getContext().getSessionService()) + ); layerA.addAccountInfo(SERVICE); - assertEquals("ServiceContext(accountService=SERVICE, sessionService=null, searchService=null)", layerA.getContext().toString()); + assertAll( + () -> assertEquals(SERVICE, layerA.getContext().getAccountService()), + () -> assertNull(layerA.getContext().getSearchService()), + () -> assertNull(layerA.getContext().getSessionService()) + ); var layerB = new LayerB(layerA); layerB.addSessionInfo(SERVICE); + assertAll( + () -> assertEquals(SERVICE, layerB.getContext().getAccountService()), + () -> assertEquals(SERVICE, layerB.getContext().getSessionService()), + () -> assertNull(layerB.getContext().getSearchService()) + ); var layerC = new LayerC(layerB); - assertEquals("ServiceContext(accountService=SERVICE, sessionService=SERVICE, searchService=null)", layerC.getContext().toString()); + layerC.addSearchInfo(SERVICE); + assertAll( + () -> assertEquals(SERVICE, layerC.getContext().getAccountService()), + () -> assertEquals(SERVICE, layerC.getContext().getSearchService()), + () -> assertEquals(SERVICE, layerC.getContext().getSessionService()) + ); } }