From 59eb36e4abaf671ea41153bc873c302dd8c8f38a Mon Sep 17 00:00:00 2001 From: ehsan Date: Fri, 13 Dec 2019 23:57:49 +0330 Subject: [PATCH] commits tests for testing decorator pattern. --- .../decorator/DecoratorDemo.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/test/java/com/designpatterns/decorator/DecoratorDemo.java diff --git a/src/test/java/com/designpatterns/decorator/DecoratorDemo.java b/src/test/java/com/designpatterns/decorator/DecoratorDemo.java new file mode 100644 index 00000000..08aaf02b --- /dev/null +++ b/src/test/java/com/designpatterns/decorator/DecoratorDemo.java @@ -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 + ); + + + + } +}