[BAEL-15974] - Fixed issue in Command Pattern article
This commit is contained in:
parent
50dd0ff282
commit
55d250318a
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.chainofresponsibility;
|
package com.baeldung.chainofresponsibility;
|
||||||
|
|
||||||
public abstract class AuthenticationProcessor {
|
public abstract class AuthenticationProcessor {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.chainofresponsibility;
|
package com.baeldung.chainofresponsibility;
|
||||||
|
|
||||||
public interface AuthenticationProvider {
|
public interface AuthenticationProvider {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.chainofresponsibility;
|
package com.baeldung.chainofresponsibility;
|
||||||
|
|
||||||
public class OAuthAuthenticationProcessor extends AuthenticationProcessor {
|
public class OAuthAuthenticationProcessor extends AuthenticationProcessor {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.chainofresponsibility;
|
package com.baeldung.chainofresponsibility;
|
||||||
|
|
||||||
public class OAuthTokenProvider implements AuthenticationProvider {
|
public class OAuthTokenProvider implements AuthenticationProvider {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.chainofresponsibility;
|
package com.baeldung.chainofresponsibility;
|
||||||
|
|
||||||
public class SamlAuthenticationProvider implements AuthenticationProvider {
|
public class SamlAuthenticationProvider implements AuthenticationProvider {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.chainofresponsibility;
|
package com.baeldung.chainofresponsibility;
|
||||||
|
|
||||||
public class UsernamePasswordAuthenticationProcessor extends AuthenticationProcessor {
|
public class UsernamePasswordAuthenticationProcessor extends AuthenticationProcessor {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.chainofresponsibility;
|
package com.baeldung.chainofresponsibility;
|
||||||
|
|
||||||
public class UsernamePasswordProvider implements AuthenticationProvider {
|
public class UsernamePasswordProvider implements AuthenticationProvider {
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.baeldung.pattern.command.client;
|
package com.baeldung.command.client;
|
||||||
|
|
||||||
import com.baeldung.pattern.command.command.OpenTextFileOperation;
|
import com.baeldung.command.command.OpenTextFileOperation;
|
||||||
import com.baeldung.pattern.command.command.SaveTextFileOperation;
|
import com.baeldung.command.command.SaveTextFileOperation;
|
||||||
import com.baeldung.pattern.command.command.TextFileOperation;
|
import com.baeldung.command.command.TextFileOperation;
|
||||||
import com.baeldung.pattern.command.invoker.TextFileOperationExecutor;
|
import com.baeldung.command.invoker.TextFileOperationExecutor;
|
||||||
import com.baeldung.pattern.command.receiver.TextFile;
|
import com.baeldung.command.receiver.TextFile;
|
||||||
|
|
||||||
public class TextFileApplication {
|
public class TextFileApplication {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.pattern.command.command;
|
package com.baeldung.command.command;
|
||||||
|
|
||||||
import com.baeldung.pattern.command.receiver.TextFile;
|
import com.baeldung.command.receiver.TextFile;
|
||||||
|
|
||||||
public class OpenTextFileOperation implements TextFileOperation {
|
public class OpenTextFileOperation implements TextFileOperation {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.pattern.command.command;
|
package com.baeldung.command.command;
|
||||||
|
|
||||||
import com.baeldung.pattern.command.receiver.TextFile;
|
import com.baeldung.command.receiver.TextFile;
|
||||||
|
|
||||||
public class SaveTextFileOperation implements TextFileOperation {
|
public class SaveTextFileOperation implements TextFileOperation {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.command.command;
|
package com.baeldung.command.command;
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface TextFileOperation {
|
public interface TextFileOperation {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.pattern.command.invoker;
|
package com.baeldung.command.invoker;
|
||||||
|
|
||||||
import com.baeldung.pattern.command.command.TextFileOperation;
|
import com.baeldung.command.command.TextFileOperation;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.command.receiver;
|
package com.baeldung.command.receiver;
|
||||||
|
|
||||||
public class TextFile {
|
public class TextFile {
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package com.baeldung.pattern.templatemethod.application;
|
package com.baeldung.templatemethod.application;
|
||||||
|
|
||||||
import com.baeldung.pattern.templatemethod.model.Computer;
|
import com.baeldung.templatemethod.model.Computer;
|
||||||
import com.baeldung.pattern.templatemethod.model.StandardComputer;
|
import com.baeldung.templatemethod.model.ComputerBuilder;
|
||||||
import com.baeldung.pattern.templatemethod.model.HighEndComputer;
|
import com.baeldung.templatemethod.model.HighEndComputerBuilder;
|
||||||
import com.baeldung.pattern.templatemethod.model.ComputerBuilder;
|
import com.baeldung.templatemethod.model.StandardComputerBuilder;
|
||||||
import com.baeldung.pattern.templatemethod.model.HighEndComputerBuilder;
|
|
||||||
import com.baeldung.pattern.templatemethod.model.StandardComputerBuilder;
|
|
||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.templatemethod.model;
|
package com.baeldung.templatemethod.model;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.baeldung.pattern.templatemethod.model;
|
package com.baeldung.templatemethod.model;
|
||||||
|
|
||||||
import com.baeldung.pattern.templatemethod.model.Computer;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.baeldung.pattern.templatemethod.model;
|
package com.baeldung.templatemethod.model;
|
||||||
|
|
||||||
import com.baeldung.pattern.templatemethod.model.Computer;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class HighEndComputer extends Computer {
|
public class HighEndComputer extends Computer {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.templatemethod.model;
|
package com.baeldung.templatemethod.model;
|
||||||
|
|
||||||
public class HighEndComputerBuilder extends ComputerBuilder {
|
public class HighEndComputerBuilder extends ComputerBuilder {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.baeldung.pattern.templatemethod.model;
|
package com.baeldung.templatemethod.model;
|
||||||
|
|
||||||
import com.baeldung.pattern.templatemethod.model.Computer;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class StandardComputer extends Computer {
|
public class StandardComputer extends Computer {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.pattern.templatemethod.model;
|
package com.baeldung.templatemethod.model;
|
||||||
|
|
||||||
public class StandardComputerBuilder extends ComputerBuilder {
|
public class StandardComputerBuilder extends ComputerBuilder {
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
package com.baeldung.chainofresponsibility;
|
package com.baeldung.chainofresponsibility;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import com.baeldung.pattern.chainofresponsibility.AuthenticationProcessor;
|
|
||||||
import com.baeldung.pattern.chainofresponsibility.OAuthAuthenticationProcessor;
|
|
||||||
import com.baeldung.pattern.chainofresponsibility.OAuthTokenProvider;
|
|
||||||
import com.baeldung.pattern.chainofresponsibility.UsernamePasswordProvider;
|
|
||||||
import com.baeldung.pattern.chainofresponsibility.SamlAuthenticationProvider;
|
|
||||||
import com.baeldung.pattern.chainofresponsibility.UsernamePasswordAuthenticationProcessor;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ChainOfResponsibilityIntegrationTest {
|
public class ChainOfResponsibilityIntegrationTest {
|
||||||
|
|
||||||
private static AuthenticationProcessor getChainOfAuthProcessor() {
|
private static AuthenticationProcessor getChainOfAuthProcessor() {
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.baeldung.pattern.command.test;
|
package com.baeldung.command.test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import com.baeldung.pattern.command.command.OpenTextFileOperation;
|
|
||||||
import com.baeldung.pattern.command.command.TextFileOperation;
|
|
||||||
import com.baeldung.pattern.command.receiver.TextFile;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.assertj.core.api.Assertions.*;
|
|
||||||
|
import com.baeldung.command.command.OpenTextFileOperation;
|
||||||
|
import com.baeldung.command.command.TextFileOperation;
|
||||||
|
import com.baeldung.command.receiver.TextFile;
|
||||||
|
|
||||||
public class OpenTextFileOperationUnitTest {
|
public class OpenTextFileOperationUnitTest {
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package com.baeldung.pattern.command.test;
|
package com.baeldung.command.test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import com.baeldung.pattern.command.command.SaveTextFileOperation;
|
|
||||||
import com.baeldung.pattern.command.command.TextFileOperation;
|
|
||||||
import com.baeldung.pattern.command.receiver.TextFile;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.assertj.core.api.Assertions.*;
|
|
||||||
|
import com.baeldung.command.command.SaveTextFileOperation;
|
||||||
|
import com.baeldung.command.command.TextFileOperation;
|
||||||
|
import com.baeldung.command.receiver.TextFile;
|
||||||
|
|
||||||
public class SaveTextFileOperationUnitTest {
|
public class SaveTextFileOperationUnitTest {
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
package com.baeldung.pattern.command.test;
|
package com.baeldung.command.test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import com.baeldung.pattern.command.command.OpenTextFileOperation;
|
|
||||||
import com.baeldung.pattern.command.command.SaveTextFileOperation;
|
|
||||||
import com.baeldung.pattern.command.command.TextFileOperation;
|
|
||||||
import com.baeldung.pattern.command.invoker.TextFileOperationExecutor;
|
|
||||||
import com.baeldung.pattern.command.receiver.TextFile;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import org.junit.Test;
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.baeldung.command.command.OpenTextFileOperation;
|
||||||
|
import com.baeldung.command.command.SaveTextFileOperation;
|
||||||
|
import com.baeldung.command.command.TextFileOperation;
|
||||||
|
import com.baeldung.command.invoker.TextFileOperationExecutor;
|
||||||
|
import com.baeldung.command.receiver.TextFile;
|
||||||
|
|
||||||
public class TextFileOperationExecutorUnitTest {
|
public class TextFileOperationExecutorUnitTest {
|
||||||
|
|
||||||
|
@ -65,4 +68,11 @@ public class TextFileOperationExecutorUnitTest {
|
||||||
Function<SaveTextFileOperation, String> executeMethodReference = SaveTextFileOperation::execute;
|
Function<SaveTextFileOperation, String> executeMethodReference = SaveTextFileOperation::execute;
|
||||||
assertThat(executeMethodReference.apply(new SaveTextFileOperation(new TextFile("file1.txt")))).isEqualTo("Saving file file1.txt");
|
assertThat(executeMethodReference.apply(new SaveTextFileOperation(new TextFile("file1.txt")))).isEqualTo("Saving file file1.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenOpenAndSaveTextFileOperationExecutorInstance_whenCalledExecuteOperationWithLambdaExpression_thenBothAssertion() {
|
||||||
|
TextFileOperationExecutor textFileOperationExecutor = new TextFileOperationExecutor();
|
||||||
|
assertThat(textFileOperationExecutor.executeOperation(() -> "Opening file file1.txt")).isEqualTo("Opening file file1.txt");
|
||||||
|
assertThat(textFileOperationExecutor.executeOperation(() -> "Saving file file1.txt")).isEqualTo("Saving file file1.txt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.baeldung.pattern.command.test;
|
package com.baeldung.command.test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import com.baeldung.pattern.command.receiver.TextFile;
|
|
||||||
import org.junit.Test;
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.baeldung.command.receiver.TextFile;
|
||||||
|
|
||||||
public class TextFileUnitTest {
|
public class TextFileUnitTest {
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package com.baeldung.templatemethod.test;
|
package com.baeldung.templatemethod.test;
|
||||||
|
|
||||||
import com.baeldung.pattern.templatemethod.model.Computer;
|
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||||
import com.baeldung.pattern.templatemethod.model.HighEndComputerBuilder;
|
|
||||||
import com.baeldung.pattern.templatemethod.model.StandardComputerBuilder;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
|
||||||
import static org.junit.Assert.assertThat;
|
import com.baeldung.templatemethod.model.Computer;
|
||||||
|
import com.baeldung.templatemethod.model.HighEndComputerBuilder;
|
||||||
|
import com.baeldung.templatemethod.model.StandardComputerBuilder;
|
||||||
|
|
||||||
public class TemplateMethodPatternIntegrationTest {
|
public class TemplateMethodPatternIntegrationTest {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue