Merge pull request #7365 from amit2103/BAEL-15974

[BAEL-15974] - Fixed issue in Command Pattern article
This commit is contained in:
Loredana Crusoveanu 2019-07-20 22:49:22 +03:00 committed by GitHub
commit 8e6a12f1a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 80 additions and 72 deletions

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.chainofresponsibility;
package com.baeldung.chainofresponsibility;
public abstract class AuthenticationProcessor {

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.chainofresponsibility;
package com.baeldung.chainofresponsibility;
public interface AuthenticationProvider {

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.chainofresponsibility;
package com.baeldung.chainofresponsibility;
public class OAuthAuthenticationProcessor extends AuthenticationProcessor {

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.chainofresponsibility;
package com.baeldung.chainofresponsibility;
public class OAuthTokenProvider implements AuthenticationProvider {

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.chainofresponsibility;
package com.baeldung.chainofresponsibility;
public class SamlAuthenticationProvider implements AuthenticationProvider {

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.chainofresponsibility;
package com.baeldung.chainofresponsibility;
public class UsernamePasswordAuthenticationProcessor extends AuthenticationProcessor {

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.chainofresponsibility;
package com.baeldung.chainofresponsibility;
public class UsernamePasswordProvider implements AuthenticationProvider {

View File

@ -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.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 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 TextFileApplication {

View File

@ -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 {

View File

@ -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 {

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.command.command;
package com.baeldung.command.command;
@FunctionalInterface
public interface TextFileOperation {

View File

@ -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.List;

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.command.receiver;
package com.baeldung.command.receiver;
public class TextFile {

View File

@ -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.pattern.templatemethod.model.StandardComputer;
import com.baeldung.pattern.templatemethod.model.HighEndComputer;
import com.baeldung.pattern.templatemethod.model.ComputerBuilder;
import com.baeldung.pattern.templatemethod.model.HighEndComputerBuilder;
import com.baeldung.pattern.templatemethod.model.StandardComputerBuilder;
import com.baeldung.templatemethod.model.Computer;
import com.baeldung.templatemethod.model.ComputerBuilder;
import com.baeldung.templatemethod.model.HighEndComputerBuilder;
import com.baeldung.templatemethod.model.StandardComputerBuilder;
public class Application {

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.templatemethod.model;
package com.baeldung.templatemethod.model;
import java.util.HashMap;
import java.util.Map;

View File

@ -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.HashMap;
import java.util.List;

View File

@ -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;
public class HighEndComputer extends Computer {

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.templatemethod.model;
package com.baeldung.templatemethod.model;
public class HighEndComputerBuilder extends ComputerBuilder {

View File

@ -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;
public class StandardComputer extends Computer {

View File

@ -1,4 +1,4 @@
package com.baeldung.pattern.templatemethod.model;
package com.baeldung.templatemethod.model;
public class StandardComputerBuilder extends ComputerBuilder {

View File

@ -1,14 +1,9 @@
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 org.junit.Test;
public class ChainOfResponsibilityIntegrationTest {
private static AuthenticationProcessor getChainOfAuthProcessor() {

View File

@ -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 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 {

View File

@ -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 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 {

View File

@ -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 org.junit.Test;
import static org.assertj.core.api.Assertions.*;
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 {
@ -65,4 +68,11 @@ public class TextFileOperationExecutorUnitTest {
Function<SaveTextFileOperation, String> executeMethodReference = SaveTextFileOperation::execute;
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");
}
}

View File

@ -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.Test;
import com.baeldung.command.receiver.TextFile;
public class TextFileUnitTest {

View File

@ -1,14 +1,16 @@
package com.baeldung.templatemethod.test;
import com.baeldung.pattern.templatemethod.model.Computer;
import com.baeldung.pattern.templatemethod.model.HighEndComputerBuilder;
import com.baeldung.pattern.templatemethod.model.StandardComputerBuilder;
import org.junit.Assert;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.junit.Assert;
import org.junit.BeforeClass;
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 {