Add simple tests for delegate pattern #324

This commit is contained in:
Joseph McCarthy
2015-12-27 14:10:49 +00:00
parent fb0617e9c5
commit a49dbefb56
5 changed files with 56 additions and 11 deletions
@@ -0,0 +1,43 @@
package com.iluwatar.delegation.simple;
import com.iluwatar.delegation.simple.printers.CanonPrinter;
import com.iluwatar.delegation.simple.printers.EpsonPrinter;
import com.iluwatar.delegation.simple.printers.HPPrinter;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;
import static org.junit.Assert.assertEquals;
public class DelegateTest {
private static final String MESSAGE = "Test Message Printed";
@Rule
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();
@Test
public void testCanonPrinter() throws Exception {
AbstractPrinterController abstractController = new PrinterController(new CanonPrinter());
abstractController.print(MESSAGE);
assertEquals("Canon Printer : Test Message Printed\n", systemOutRule.getLog());
}
@Test
public void testHPPrinter() throws Exception {
AbstractPrinterController abstractController = new PrinterController(new HPPrinter());
abstractController.print(MESSAGE);
assertEquals("HP Printer : Test Message Printed\n", systemOutRule.getLog());
}
@Test
public void testEpsonPrinter() throws Exception {
AbstractPrinterController abstractController = new PrinterController(new EpsonPrinter());
abstractController.print(MESSAGE);
assertEquals("Epson Printer : Test Message Printed\n", systemOutRule.getLog());
}
}