mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-20 12:24:09 +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:
@@ -94,7 +94,8 @@ public class App {
|
||||
// Demonstrates the TieredFeatureToggleVersion setup with
|
||||
// two users: one on the free tier and the other on the paid tier. When the
|
||||
// Service#getWelcomeMessage(User) method is called with the paid user, the welcome
|
||||
// message includes their username. In contrast, calling the same service with the free tier user results
|
||||
// message includes their username. In contrast, calling the same service with the free tier
|
||||
// user results
|
||||
// in a more generic welcome message without the username.
|
||||
|
||||
var service2 = new TieredFeatureToggleVersion();
|
||||
|
||||
@@ -28,8 +28,8 @@ import com.iluwatar.featuretoggle.user.User;
|
||||
|
||||
/**
|
||||
* Simple interfaces to allow the calling of the method to generate the welcome message for a given
|
||||
* user. While there is a helper method to gather the status of the feature toggle. In some
|
||||
* cases there is no need for the {@link Service#isEnhanced()} in {@link
|
||||
* user. While there is a helper method to gather the status of the feature toggle. In some cases
|
||||
* there is no need for the {@link Service#isEnhanced()} in {@link
|
||||
* com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion} where the toggle is
|
||||
* determined by the actual {@link User}.
|
||||
*
|
||||
@@ -53,5 +53,4 @@ public interface Service {
|
||||
* @return Boolean {@code true} if enhanced.
|
||||
*/
|
||||
boolean isEnhanced();
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -46,8 +46,8 @@ import lombok.Getter;
|
||||
public class PropertiesFeatureToggleVersion implements Service {
|
||||
|
||||
/**
|
||||
* True if the welcome message to be returned is the enhanced venison or not. For
|
||||
* this service it will see the value of the boolean that was set in the constructor {@link
|
||||
* True if the welcome message to be returned is the enhanced venison or not. For this service it
|
||||
* will see the value of the boolean that was set in the constructor {@link
|
||||
* PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)}
|
||||
*/
|
||||
private final boolean enhanced;
|
||||
@@ -80,9 +80,9 @@ public class PropertiesFeatureToggleVersion implements Service {
|
||||
* passed {@link User}. However, if disabled then a generic version fo the message is returned.
|
||||
*
|
||||
* @param user the {@link User} to be displayed in the message if the enhanced version is enabled
|
||||
* see {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is
|
||||
* enabled, then the message will be personalised with the name of the passed {@link
|
||||
* User}. However, if disabled then a generic version fo the message is returned.
|
||||
* see {@link PropertiesFeatureToggleVersion#isEnhanced()}. If the enhanced version is
|
||||
* enabled, then the message will be personalised with the name of the passed {@link User}.
|
||||
* However, if disabled then a generic version fo the message is returned.
|
||||
* @return Resulting welcome message.
|
||||
* @see User
|
||||
*/
|
||||
|
||||
+5
-6
@@ -30,9 +30,9 @@ import com.iluwatar.featuretoggle.user.UserGroup;
|
||||
|
||||
/**
|
||||
* This example of the Feature Toggle pattern shows how it could be implemented based on a {@link
|
||||
* User}. Therefore, showing its use within a tiered application where the paying users get access to
|
||||
* different content or better versions of features. So in this instance a {@link User} is passed in
|
||||
* and if they are found to be on the {@link UserGroup#isPaid(User)} they are welcomed with a
|
||||
* User}. Therefore, showing its use within a tiered application where the paying users get access
|
||||
* to different content or better versions of features. So in this instance a {@link User} is passed
|
||||
* in and if they are found to be on the {@link UserGroup#isPaid(User)} they are welcomed with a
|
||||
* personalised message. While the other is more generic. However, this pattern is limited to simple
|
||||
* examples such as the one below.
|
||||
*
|
||||
@@ -49,8 +49,8 @@ public class TieredFeatureToggleVersion implements Service {
|
||||
* the enhanced version of the welcome message will be returned where the username is displayed.
|
||||
*
|
||||
* @param user the {@link User} to generate the welcome message for, different messages are
|
||||
* displayed if the user is in the {@link UserGroup#isPaid(User)} or {@link
|
||||
* UserGroup#freeGroup}
|
||||
* displayed if the user is in the {@link UserGroup#isPaid(User)} or {@link
|
||||
* UserGroup#freeGroup}
|
||||
* @return Resulting welcome message.
|
||||
* @see User
|
||||
* @see UserGroup
|
||||
@@ -75,5 +75,4 @@ public class TieredFeatureToggleVersion implements Service {
|
||||
public boolean isEnhanced() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-9
@@ -33,9 +33,7 @@ import com.iluwatar.featuretoggle.user.User;
|
||||
import java.util.Properties;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test Properties Toggle
|
||||
*/
|
||||
/** Test Properties Toggle */
|
||||
class PropertiesFeatureToggleVersionTest {
|
||||
|
||||
@Test
|
||||
@@ -45,11 +43,13 @@ class PropertiesFeatureToggleVersionTest {
|
||||
|
||||
@Test
|
||||
void testNonBooleanProperty() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
final var properties = new Properties();
|
||||
properties.setProperty("enhancedWelcome", "Something");
|
||||
new PropertiesFeatureToggleVersion(properties);
|
||||
});
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> {
|
||||
final var properties = new Properties();
|
||||
properties.setProperty("enhancedWelcome", "Something");
|
||||
new PropertiesFeatureToggleVersion(properties);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,7 +59,8 @@ class PropertiesFeatureToggleVersionTest {
|
||||
var service = new PropertiesFeatureToggleVersion(properties);
|
||||
assertTrue(service.isEnhanced());
|
||||
final var welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
|
||||
assertEquals("Welcome Jamie No Code. You're using the enhanced welcome message.", welcomeMessage);
|
||||
assertEquals(
|
||||
"Welcome Jamie No Code. You're using the enhanced welcome message.", welcomeMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-3
@@ -33,9 +33,7 @@ import com.iluwatar.featuretoggle.user.UserGroup;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test Tiered Feature Toggle
|
||||
*/
|
||||
/** Test Tiered Feature Toggle */
|
||||
class TieredFeatureToggleVersionTest {
|
||||
|
||||
final User paidUser = new User("Jamie Coder");
|
||||
|
||||
@@ -30,9 +30,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test User Group specific feature
|
||||
*/
|
||||
/** Test User Group specific feature */
|
||||
class UserGroupTest {
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user