Review Comments #324
This commit is contained in:
@ -1,27 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ The MIT License (MIT)
|
||||
~
|
||||
~ Copyright (c) 2015 Orange Foundry
|
||||
~
|
||||
~ Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
~ of this software and associated documentation files (the "Software"), to deal
|
||||
~ in the Software without restriction, including without limitation the rights
|
||||
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
~ copies of the Software, and to permit persons to whom the Software is
|
||||
~ furnished to do so, subject to the following conditions:
|
||||
~
|
||||
~ The above copyright notice and this permission notice shall be included in
|
||||
~ all copies or substantial portions of the Software.
|
||||
~
|
||||
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
~ THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
@ -44,7 +21,6 @@
|
||||
<dependency>
|
||||
<groupId>com.github.stefanbirkner</groupId>
|
||||
<artifactId>system-rules</artifactId>
|
||||
<version>1.14.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -1,34 +0,0 @@
|
||||
package com.iluwatar.delegation.simple;
|
||||
|
||||
/**
|
||||
* Extra layer of abstraction for the controller to allow the controller in this example {@link PrinterController} to
|
||||
* be as clean as possible. This just provides the default constructor and a simple getter method. The generic of
|
||||
* T allows any implementation of {@link Printer}
|
||||
*
|
||||
* @param <T> Printer
|
||||
* @see Printer
|
||||
* @see PrinterController
|
||||
*/
|
||||
public abstract class AbstractPrinterController<T extends Printer> implements Printer {
|
||||
|
||||
|
||||
private T printer;
|
||||
|
||||
/**
|
||||
* @param printer instance of T {@link Printer} this instance is the delegate
|
||||
*/
|
||||
public AbstractPrinterController(T printer) {
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to return the current instance of T {@link Printer} in order for
|
||||
* the controller to call operations on the {@link Printer}
|
||||
*
|
||||
* @return instance of Printer
|
||||
* @see Printer
|
||||
*/
|
||||
protected T getPrinter() {
|
||||
return printer;
|
||||
}
|
||||
}
|
@ -21,9 +21,9 @@ public class App {
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
AbstractPrinterController hpPrinterController = new PrinterController(new HpPrinter());
|
||||
AbstractPrinterController canonPrinterController = new PrinterController(new CanonPrinter());
|
||||
AbstractPrinterController epsonPrinterController = new PrinterController(new EpsonPrinter());
|
||||
PrinterController hpPrinterController = new PrinterController(new HpPrinter());
|
||||
PrinterController canonPrinterController = new PrinterController(new CanonPrinter());
|
||||
PrinterController epsonPrinterController = new PrinterController(new EpsonPrinter());
|
||||
|
||||
hpPrinterController.print(MESSAGE_TO_PRINT);
|
||||
canonPrinterController.print(MESSAGE_TO_PRINT);
|
||||
|
@ -8,7 +8,6 @@ import com.iluwatar.delegation.simple.printers.HpPrinter;
|
||||
* @see com.iluwatar.delegation.simple.printers.CanonPrinter
|
||||
* @see com.iluwatar.delegation.simple.printers.EpsonPrinter
|
||||
* @see HpPrinter
|
||||
* @see AbstractPrinterController
|
||||
*/
|
||||
public interface Printer {
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.iluwatar.delegation.simple;
|
||||
|
||||
public class PrinterController extends AbstractPrinterController {
|
||||
public class PrinterController implements Printer {
|
||||
|
||||
private final Printer printer;
|
||||
|
||||
public PrinterController(Printer printer) {
|
||||
super(printer);
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -16,6 +18,6 @@ public class PrinterController extends AbstractPrinterController {
|
||||
*/
|
||||
@Override
|
||||
public void print(String message) {
|
||||
getPrinter().print(message);
|
||||
printer.print(message);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class CanonPrinter implements Printer {
|
||||
*/
|
||||
@Override
|
||||
public void print(String message) {
|
||||
System.out.println("Canon Printer : " + message);
|
||||
System.out.print("Canon Printer : " + message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class EpsonPrinter implements Printer {
|
||||
*/
|
||||
@Override
|
||||
public void print(String message) {
|
||||
System.out.println("Epson Printer : " + message);
|
||||
System.out.print("Epson Printer : " + message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class HpPrinter implements Printer {
|
||||
*/
|
||||
@Override
|
||||
public void print(String message) {
|
||||
System.out.println("HP Printer : " + message);
|
||||
System.out.print("HP Printer : " + message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,26 +18,26 @@ public class DelegateTest {
|
||||
|
||||
@Test
|
||||
public void testCanonPrinter() throws Exception {
|
||||
AbstractPrinterController abstractController = new PrinterController(new CanonPrinter());
|
||||
abstractController.print(MESSAGE);
|
||||
PrinterController printerController = new PrinterController(new CanonPrinter());
|
||||
printerController.print(MESSAGE);
|
||||
|
||||
assertEquals("Canon Printer : Test Message Printed\n", systemOutRule.getLog());
|
||||
assertEquals("Canon Printer : Test Message Printed", systemOutRule.getLog());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHpPrinter() throws Exception {
|
||||
AbstractPrinterController abstractController = new PrinterController(new HpPrinter());
|
||||
abstractController.print(MESSAGE);
|
||||
PrinterController printerController = new PrinterController(new HpPrinter());
|
||||
printerController.print(MESSAGE);
|
||||
|
||||
assertEquals("HP Printer : Test Message Printed\n", systemOutRule.getLog());
|
||||
assertEquals("HP Printer : Test Message Printed", systemOutRule.getLog());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEpsonPrinter() throws Exception {
|
||||
AbstractPrinterController abstractController = new PrinterController(new EpsonPrinter());
|
||||
abstractController.print(MESSAGE);
|
||||
PrinterController printerController = new PrinterController(new EpsonPrinter());
|
||||
printerController.print(MESSAGE);
|
||||
|
||||
assertEquals("Epson Printer : Test Message Printed\n", systemOutRule.getLog());
|
||||
assertEquals("Epson Printer : Test Message Printed", systemOutRule.getLog());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user