Refactored tests for Bridge
This commit is contained in:
parent
a5ec376089
commit
6f1736d2e6
@ -57,4 +57,9 @@ public class Hammer implements Weapon {
|
|||||||
LOGGER.info("The hammer is unwielded.");
|
LOGGER.info("The hammer is unwielded.");
|
||||||
enchantment.onDeactivate();
|
enchantment.onDeactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Enchantment getEnchantment() {
|
||||||
|
return enchantment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,4 +57,9 @@ public class Sword implements Weapon {
|
|||||||
LOGGER.info("The sword is unwielded.");
|
LOGGER.info("The sword is unwielded.");
|
||||||
enchantment.onDeactivate();
|
enchantment.onDeactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Enchantment getEnchantment() {
|
||||||
|
return enchantment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,4 +34,6 @@ public interface Weapon {
|
|||||||
void swing();
|
void swing();
|
||||||
|
|
||||||
void unwield();
|
void unwield();
|
||||||
|
|
||||||
|
Enchantment getEnchantment();
|
||||||
}
|
}
|
||||||
|
@ -24,32 +24,22 @@ package com.iluwatar.bridge;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
||||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date: 12/6/15 - 11:26 PM
|
* Tests for hammer
|
||||||
*
|
|
||||||
* @author Jeroen Meulemeester
|
|
||||||
*/
|
*/
|
||||||
public class FlyingMagicWeaponTest extends MagicWeaponTest {
|
public class HammerTest extends WeaponTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke all possible actions on the weapon and check if the actions are executed on the actual
|
* Invoke all possible actions on the weapon and check if the actions are executed on the actual
|
||||||
* underlying weapon implementation.
|
* underlying weapon implementation.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMjollnir() throws Exception {
|
public void testHammer() throws Exception {
|
||||||
// final Mjollnir mjollnir = spy(new Mjollnir());
|
final Hammer hammer = spy(new Hammer(mock(FlyingEnchantment.class)));
|
||||||
// final FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon(mjollnir);
|
testBasicWeaponActions(hammer);
|
||||||
//
|
|
||||||
// testBasicWeaponActions(flyingMagicWeapon, mjollnir);
|
|
||||||
//
|
|
||||||
// flyingMagicWeapon.fly();
|
|
||||||
// verify(mjollnir, times(1)).flyImp();
|
|
||||||
// verifyNoMoreInteractions(mjollnir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,55 +0,0 @@
|
|||||||
/**
|
|
||||||
* The MIT License
|
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
package com.iluwatar.bridge;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
||||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Date: 12/6/15 - 11:43 PM
|
|
||||||
*
|
|
||||||
* @author Jeroen Meulemeester
|
|
||||||
*/
|
|
||||||
public class SoulEatingMagicWeaponTest extends MagicWeaponTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Invoke all possible actions on the weapon and check if the actions are executed on the actual
|
|
||||||
* underlying weapon implementation.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testStormBringer() throws Exception {
|
|
||||||
// final Stormbringer stormbringer = spy(new Stormbringer());
|
|
||||||
// final Sword soulEatingMagicWeapon = new Sword(stormbringer);
|
|
||||||
//
|
|
||||||
// testBasicWeaponActions(soulEatingMagicWeapon, stormbringer);
|
|
||||||
//
|
|
||||||
// soulEatingMagicWeapon.eatSoul();
|
|
||||||
// verify(stormbringer, times(1)).eatSoulImp();
|
|
||||||
// verifyNoMoreInteractions(stormbringer);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -24,32 +24,22 @@ package com.iluwatar.bridge;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
||||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date: 12/6/15 - 11:15 PM
|
* Tests for sword
|
||||||
*
|
|
||||||
* @author Jeroen Meulemeester
|
|
||||||
*/
|
*/
|
||||||
public class BlindingMagicWeaponTest extends MagicWeaponTest {
|
public class SwordTest extends WeaponTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke all possible actions on the weapon and check if the actions are executed on the actual
|
* Invoke all possible actions on the weapon and check if the actions are executed on the actual
|
||||||
* underlying weapon implementation.
|
* underlying weapon implementation.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExcalibur() throws Exception {
|
public void testSword() throws Exception {
|
||||||
// final Excalibur excalibur = spy(new Excalibur());
|
final Sword sword = spy(new Sword(mock(FlyingEnchantment.class)));
|
||||||
// final Hammer blindingMagicWeapon = new Hammer(excalibur);
|
testBasicWeaponActions(sword);
|
||||||
//
|
|
||||||
// testBasicWeaponActions(blindingMagicWeapon, excalibur);
|
|
||||||
//
|
|
||||||
// blindingMagicWeapon.blind();
|
|
||||||
// verify(excalibur, times(1)).blindImp();
|
|
||||||
// verifyNoMoreInteractions(excalibur);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
@ -28,37 +28,32 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date: 12/6/15 - 11:28 PM
|
* Base class for weapon tests
|
||||||
*
|
|
||||||
* @author Jeroen Meulemeester
|
|
||||||
*/
|
*/
|
||||||
public abstract class MagicWeaponTest {
|
public abstract class WeaponTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke the basic actions of the given weapon, and test if the underlying weapon implementation
|
* Invoke the basic actions of the given weapon, and test if the underlying enchantment implementation
|
||||||
* is invoked
|
* is invoked
|
||||||
*
|
*
|
||||||
* @param weaponImpl The spied weapon implementation where actions are bridged to
|
|
||||||
* @param weapon The weapon, handled by the app
|
|
||||||
*/
|
*/
|
||||||
protected final void testBasicWeaponActions(final Weapon weapon,
|
protected final void testBasicWeaponActions(final Weapon weapon) {
|
||||||
final Enchantment weaponImpl) {
|
assertNotNull(weapon);
|
||||||
// assertNotNull(weapon);
|
Enchantment enchantment = weapon.getEnchantment();
|
||||||
// assertNotNull(weaponImpl);
|
assertNotNull(enchantment);
|
||||||
// assertNotNull(weapon.getEnchantment());
|
assertNotNull(weapon.getEnchantment());
|
||||||
//
|
|
||||||
// weapon.swing();
|
|
||||||
// verify(weaponImpl, times(1)).swingImp();
|
|
||||||
// verifyNoMoreInteractions(weaponImpl);
|
|
||||||
//
|
|
||||||
// weapon.wield();
|
|
||||||
// verify(weaponImpl, times(1)).wieldImp();
|
|
||||||
// verifyNoMoreInteractions(weaponImpl);
|
|
||||||
//
|
|
||||||
// weapon.unwield();
|
|
||||||
// verify(weaponImpl, times(1)).unwieldImp();
|
|
||||||
// verifyNoMoreInteractions(weaponImpl);
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
|
weapon.swing();
|
||||||
|
verify(enchantment, times(1)).apply();
|
||||||
|
verifyNoMoreInteractions(enchantment);
|
||||||
|
|
||||||
|
weapon.wield();
|
||||||
|
verify(enchantment, times(1)).onActivate();
|
||||||
|
verifyNoMoreInteractions(enchantment);
|
||||||
|
|
||||||
|
weapon.unwield();
|
||||||
|
verify(enchantment, times(1)).onDeactivate();
|
||||||
|
verifyNoMoreInteractions(enchantment);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user