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.");
|
||||
enchantment.onDeactivate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enchantment getEnchantment() {
|
||||
return enchantment;
|
||||
}
|
||||
}
|
||||
|
@ -57,4 +57,9 @@ public class Sword implements Weapon {
|
||||
LOGGER.info("The sword is unwielded.");
|
||||
enchantment.onDeactivate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enchantment getEnchantment() {
|
||||
return enchantment;
|
||||
}
|
||||
}
|
||||
|
@ -34,4 +34,6 @@ public interface Weapon {
|
||||
void swing();
|
||||
|
||||
void unwield();
|
||||
|
||||
Enchantment getEnchantment();
|
||||
}
|
||||
|
@ -24,32 +24,22 @@ package com.iluwatar.bridge;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
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:26 PM
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
* Tests for hammer
|
||||
*/
|
||||
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
|
||||
* underlying weapon implementation.
|
||||
*/
|
||||
@Test
|
||||
public void testMjollnir() throws Exception {
|
||||
// final Mjollnir mjollnir = spy(new Mjollnir());
|
||||
// final FlyingMagicWeapon flyingMagicWeapon = new FlyingMagicWeapon(mjollnir);
|
||||
//
|
||||
// testBasicWeaponActions(flyingMagicWeapon, mjollnir);
|
||||
//
|
||||
// flyingMagicWeapon.fly();
|
||||
// verify(mjollnir, times(1)).flyImp();
|
||||
// verifyNoMoreInteractions(mjollnir);
|
||||
public void testHammer() throws Exception {
|
||||
final Hammer hammer = spy(new Hammer(mock(FlyingEnchantment.class)));
|
||||
testBasicWeaponActions(hammer);
|
||||
}
|
||||
|
||||
}
|
@ -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 static org.mockito.Mockito.mock;
|
||||
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:15 PM
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
* Tests for sword
|
||||
*/
|
||||
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
|
||||
* underlying weapon implementation.
|
||||
*/
|
||||
@Test
|
||||
public void testExcalibur() throws Exception {
|
||||
// final Excalibur excalibur = spy(new Excalibur());
|
||||
// final Hammer blindingMagicWeapon = new Hammer(excalibur);
|
||||
//
|
||||
// testBasicWeaponActions(blindingMagicWeapon, excalibur);
|
||||
//
|
||||
// blindingMagicWeapon.blind();
|
||||
// verify(excalibur, times(1)).blindImp();
|
||||
// verifyNoMoreInteractions(excalibur);
|
||||
public void testSword() throws Exception {
|
||||
final Sword sword = spy(new Sword(mock(FlyingEnchantment.class)));
|
||||
testBasicWeaponActions(sword);
|
||||
}
|
||||
|
||||
}
|
@ -28,37 +28,32 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
||||
|
||||
/**
|
||||
* Date: 12/6/15 - 11:28 PM
|
||||
*
|
||||
* @author Jeroen Meulemeester
|
||||
* Base class for weapon tests
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @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,
|
||||
final Enchantment weaponImpl) {
|
||||
// assertNotNull(weapon);
|
||||
// assertNotNull(weaponImpl);
|
||||
// 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);
|
||||
//
|
||||
}
|
||||
protected final void testBasicWeaponActions(final Weapon weapon) {
|
||||
assertNotNull(weapon);
|
||||
Enchantment enchantment = weapon.getEnchantment();
|
||||
assertNotNull(enchantment);
|
||||
assertNotNull(weapon.getEnchantment());
|
||||
|
||||
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