commits tests for testing decorator pattern.

This commit is contained in:
ehsan 2019-12-13 23:57:49 +03:30
parent c52e12aa05
commit 59eb36e4ab

View File

@ -0,0 +1,43 @@
package com.designpatterns.decorator;
import com.designpatterns.structural.decorator.EmailSender;
import com.designpatterns.structural.decorator.EncodingDecorator;
import com.designpatterns.structural.decorator.Sender;
import com.designpatterns.structural.decorator.SenderDecorator;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Base64;
public class DecoratorDemo {
@Test
public void testDecorator_sendEmailAsPlainText() {
String message = "test message";
EmailSender sender = new EmailSender();
String content = sender.send(message);
Assertions.assertEquals(content, message);
}
@Test
public void testDecorator_sendEmailAsEncodedTest() {
String message = "test message";
Sender sender = new SenderDecorator(
new EncodingDecorator(
new EmailSender()
)
);
String encodedContent = sender.send(message);
Assertions.assertEquals(
new String(Base64.getDecoder().decode (encodedContent)),
message
);
}
}