Proxy pattern: Improve the example
This commit is contained in:
@@ -27,21 +27,21 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Date: 12/28/15 - 9:18 PM
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
* Tests for {@link IvoryTower}
|
||||
*/
|
||||
public class WizardTowerTest {
|
||||
public class IvoryTowerTest {
|
||||
|
||||
private InMemoryAppender appender;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
appender = new InMemoryAppender(WizardTower.class);
|
||||
appender = new InMemoryAppender(IvoryTower.class);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -58,8 +58,8 @@ public class WizardTowerTest {
|
||||
new Wizard("Merlin")
|
||||
};
|
||||
|
||||
final WizardTower tower = new WizardTower();
|
||||
for (final Wizard wizard : wizards) {
|
||||
IvoryTower tower = new IvoryTower();
|
||||
for (Wizard wizard : wizards) {
|
||||
tower.enter(wizard);
|
||||
}
|
||||
|
||||
@@ -69,5 +69,4 @@ public class WizardTowerTest {
|
||||
assertTrue(appender.logContains("Merlin enters the tower."));
|
||||
assertEquals(4, appender.getLogSize());
|
||||
}
|
||||
|
||||
}
|
@@ -27,18 +27,15 @@ import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Date: 12/28/15 - 9:02 PM
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
* Tests for {@link Wizard}
|
||||
*/
|
||||
public class WizardTest {
|
||||
|
||||
@Test
|
||||
public void testToString() throws Exception {
|
||||
final String[] wizardNames = {"Gandalf", "Dumbledore", "Oz", "Merlin"};
|
||||
for (final String name : wizardNames) {
|
||||
for (String name : wizardNames) {
|
||||
assertEquals(name, new Wizard(name).toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -31,9 +31,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Date: 12/28/15 - 9:18 PM
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
* Tests for {@link WizardTowerProxy}
|
||||
*/
|
||||
public class WizardTowerProxyTest {
|
||||
|
||||
@@ -58,9 +56,9 @@ public class WizardTowerProxyTest {
|
||||
new Wizard("Merlin")
|
||||
};
|
||||
|
||||
final WizardTowerProxy tower = new WizardTowerProxy();
|
||||
for (final Wizard wizard : wizards) {
|
||||
tower.enter(wizard);
|
||||
final WizardTowerProxy proxy = new WizardTowerProxy(new IvoryTower());
|
||||
for (Wizard wizard : wizards) {
|
||||
proxy.enter(wizard);
|
||||
}
|
||||
|
||||
assertTrue(appender.logContains("Gandalf enters the tower."));
|
||||
@@ -69,5 +67,4 @@ public class WizardTowerProxyTest {
|
||||
assertTrue(appender.logContains("Merlin is not allowed to enter!"));
|
||||
assertEquals(4, appender.getLogSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user