mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-19 11:25:58 +00:00
Add simple tests for delegate pattern #324
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user