Skip to content

Commit

Permalink
Merge branch 'fkromer-test_bridge'
Browse files Browse the repository at this point in the history
  • Loading branch information
faif committed May 16, 2016
2 parents 85d9fa3 + 44cb963 commit ad59bd5
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class BridgeTest(unittest.TestCase):

def test_bridge_shall_draw_with_concrete_implementation(cls):
def test_bridge_shall_draw_with_concrete_api_implementation(cls):
ci1 = DrawingAPI1()
ci2 = DrawingAPI2()
with patch.object(ci1, 'draw_circle') as mock_ci1_draw_circle,\
Expand All @@ -25,15 +25,27 @@ def test_bridge_shall_draw_with_concrete_implementation(cls):
sh2.draw()
cls.assertEqual(mock_ci2_draw_circle.call_count, 1)

def test_bridge_shall_scale_with_own_implementation(cls):
ci = DrawingAPI1()
sh = CircleShape(1, 2, 3, ci)
sh.scale(2)
cls.assertEqual(sh._radius, 6)
with patch.object(sh, 'scale') as mock_sh_scale_circle:
sh.scale(2)
cls.assertEqual(mock_sh_scale_circle.call_count, 1)
def test_bridge_shall_scale_both_api_circles_with_own_implementation(cls):
SCALE_FACTOR = 2
CIRCLE_FACTOR = 3
CIRCLE1_RADIUS = 3
EXPECTED_CIRCLE1_RADIUS = 6
CIRCLE2_RADIUS = CIRCLE1_RADIUS * CIRCLE1_RADIUS
EXPECTED_CIRCLE2_RADIUS = CIRCLE2_RADIUS * SCALE_FACTOR
ci1 = DrawingAPI1()
ci2 = DrawingAPI2()
sh1 = CircleShape(1, 2, CIRCLE1_RADIUS, ci1)
sh2 = CircleShape(1, 2, CIRCLE2_RADIUS, ci2)
sh1.scale(SCALE_FACTOR)
sh2.scale(SCALE_FACTOR)
cls.assertEqual(sh1._radius, EXPECTED_CIRCLE1_RADIUS)
cls.assertEqual(sh2._radius, EXPECTED_CIRCLE2_RADIUS)
with patch.object(sh1, 'scale') as mock_sh1_scale_circle,\
patch.object(sh2, 'scale') as mock_sh2_scale_circle:
sh1.scale(2)
sh2.scale(2)
cls.assertEqual(mock_sh1_scale_circle.call_count, 1)
cls.assertEqual(mock_sh2_scale_circle.call_count, 1)

if __name__ == "__main__":
unittest.main()

0 comments on commit ad59bd5

Please sign in to comment.