mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-25 01:36:48 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -26,9 +26,7 @@ package com.iluwatar.privateclassdata;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Immutable stew class, protected with Private Class Data pattern.
|
||||
*/
|
||||
/** Immutable stew class, protected with Private Class Data pattern. */
|
||||
@Slf4j
|
||||
public class ImmutableStew {
|
||||
|
||||
@@ -38,12 +36,13 @@ public class ImmutableStew {
|
||||
data = new StewData(numPotatoes, numCarrots, numMeat, numPeppers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mix the stew.
|
||||
*/
|
||||
/** Mix the stew. */
|
||||
public void mix() {
|
||||
LOGGER
|
||||
.info("Mixing the immutable stew we find: {} potatoes, {} carrots, {} meat and {} peppers",
|
||||
data.numPotatoes(), data.numCarrots(), data.numMeat(), data.numPeppers());
|
||||
LOGGER.info(
|
||||
"Mixing the immutable stew we find: {} potatoes, {} carrots, {} meat and {} peppers",
|
||||
data.numPotatoes(),
|
||||
data.numCarrots(),
|
||||
data.numMeat(),
|
||||
data.numPeppers());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +1,72 @@
|
||||
/*
|
||||
* 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.privateclassdata;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Mutable stew class.
|
||||
*/
|
||||
@Slf4j
|
||||
public class Stew {
|
||||
|
||||
private int numPotatoes;
|
||||
private int numCarrots;
|
||||
private int numMeat;
|
||||
private int numPeppers;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Stew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
|
||||
this.numPotatoes = numPotatoes;
|
||||
this.numCarrots = numCarrots;
|
||||
this.numMeat = numMeat;
|
||||
this.numPeppers = numPeppers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mix the stew.
|
||||
*/
|
||||
public void mix() {
|
||||
LOGGER.info("Mixing the stew we find: {} potatoes, {} carrots, {} meat and {} peppers",
|
||||
numPotatoes, numCarrots, numMeat, numPeppers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Taste the stew.
|
||||
*/
|
||||
public void taste() {
|
||||
LOGGER.info("Tasting the stew");
|
||||
if (numPotatoes > 0) {
|
||||
numPotatoes--;
|
||||
}
|
||||
if (numCarrots > 0) {
|
||||
numCarrots--;
|
||||
}
|
||||
if (numMeat > 0) {
|
||||
numMeat--;
|
||||
}
|
||||
if (numPeppers > 0) {
|
||||
numPeppers--;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.privateclassdata;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/** Mutable stew class. */
|
||||
@Slf4j
|
||||
public class Stew {
|
||||
|
||||
private int numPotatoes;
|
||||
private int numCarrots;
|
||||
private int numMeat;
|
||||
private int numPeppers;
|
||||
|
||||
/** Constructor. */
|
||||
public Stew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {
|
||||
this.numPotatoes = numPotatoes;
|
||||
this.numCarrots = numCarrots;
|
||||
this.numMeat = numMeat;
|
||||
this.numPeppers = numPeppers;
|
||||
}
|
||||
|
||||
/** Mix the stew. */
|
||||
public void mix() {
|
||||
LOGGER.info(
|
||||
"Mixing the stew we find: {} potatoes, {} carrots, {} meat and {} peppers",
|
||||
numPotatoes,
|
||||
numCarrots,
|
||||
numMeat,
|
||||
numPeppers);
|
||||
}
|
||||
|
||||
/** Taste the stew. */
|
||||
public void taste() {
|
||||
LOGGER.info("Tasting the stew");
|
||||
if (numPotatoes > 0) {
|
||||
numPotatoes--;
|
||||
}
|
||||
if (numCarrots > 0) {
|
||||
numCarrots--;
|
||||
}
|
||||
if (numMeat > 0) {
|
||||
numMeat--;
|
||||
}
|
||||
if (numPeppers > 0) {
|
||||
numPeppers--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,5 @@
|
||||
*/
|
||||
package com.iluwatar.privateclassdata;
|
||||
|
||||
/**
|
||||
* Stew ingredients.
|
||||
*/
|
||||
|
||||
/** Stew ingredients. */
|
||||
public record StewData(int numPotatoes, int numCarrots, int numMeat, int numPeppers) {}
|
||||
|
||||
@@ -24,17 +24,15 @@
|
||||
*/
|
||||
package com.iluwatar.privateclassdata;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
/**
|
||||
* Application test
|
||||
*/
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Application test */
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
|
||||
+9
-14
@@ -31,10 +31,7 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* ImmutableStewTest
|
||||
*
|
||||
*/
|
||||
/** ImmutableStewTest */
|
||||
class ImmutableStewTest {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
@@ -49,9 +46,7 @@ class ImmutableStewTest {
|
||||
appender.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if mixing the stew doesn't change the internal state
|
||||
*/
|
||||
/** Verify if mixing the stew doesn't change the internal state */
|
||||
@Test
|
||||
void testMix() {
|
||||
var stew = new Stew(1, 2, 3, 4);
|
||||
@@ -65,22 +60,22 @@ class ImmutableStewTest {
|
||||
assertEquals(20, appender.getLogSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if tasting the stew actually removes one of each ingredient
|
||||
*/
|
||||
/** Verify if tasting the stew actually removes one of each ingredient */
|
||||
@Test
|
||||
void testDrink() {
|
||||
final var stew = new Stew(1, 2, 3, 4);
|
||||
stew.mix();
|
||||
|
||||
assertEquals("Mixing the stew we find: 1 potatoes, 2 carrots, 3 meat and 4 peppers", appender
|
||||
.getLastMessage());
|
||||
assertEquals(
|
||||
"Mixing the stew we find: 1 potatoes, 2 carrots, 3 meat and 4 peppers",
|
||||
appender.getLastMessage());
|
||||
|
||||
stew.taste();
|
||||
assertEquals("Tasting the stew", appender.getLastMessage());
|
||||
|
||||
stew.mix();
|
||||
assertEquals("Mixing the stew we find: 0 potatoes, 1 carrots, 2 meat and 3 peppers", appender
|
||||
.getLastMessage());
|
||||
assertEquals(
|
||||
"Mixing the stew we find: 0 potatoes, 1 carrots, 2 meat and 3 peppers",
|
||||
appender.getLastMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,7 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* StewTest
|
||||
*
|
||||
*/
|
||||
/** StewTest */
|
||||
class StewTest {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
@@ -49,14 +46,12 @@ class StewTest {
|
||||
appender.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if mixing the stew doesn't change the internal state
|
||||
*/
|
||||
/** Verify if mixing the stew doesn't change the internal state */
|
||||
@Test
|
||||
void testMix() {
|
||||
final var stew = new ImmutableStew(1, 2, 3, 4);
|
||||
final var expectedMessage = "Mixing the immutable stew we find: 1 potatoes, "
|
||||
+ "2 carrots, 3 meat and 4 peppers";
|
||||
final var expectedMessage =
|
||||
"Mixing the immutable stew we find: 1 potatoes, " + "2 carrots, 3 meat and 4 peppers";
|
||||
|
||||
for (var i = 0; i < 20; i++) {
|
||||
stew.mix();
|
||||
@@ -65,5 +60,4 @@ class StewTest {
|
||||
|
||||
assertEquals(20, appender.getLogSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-3
@@ -31,9 +31,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* InMemory Log Appender Util.
|
||||
*/
|
||||
/** InMemory Log Appender Util. */
|
||||
public class InMemoryAppender extends AppenderBase<ILoggingEvent> {
|
||||
private final List<ILoggingEvent> log = new LinkedList<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user