22# -*- coding: utf-8 -*-
33import unittest
44
5- from dft .parameter_injection import TimeDisplay , MidnightTimeProvider , ProductionCodeTimeProvider , datetime
5+ from dft .setter_injection import TimeDisplay , MidnightTimeProvider , ProductionCodeTimeProvider , datetime
66
77"""
8- Port of the Java example of "Parameter Injection" in
8+ Port of the Java example of "Setter Injection" in
99"xUnit Test Patterns - Refactoring Test Code" by Gerard Meszaros
1010(ISBN-10: 0131495054, ISBN-13: 978-0131495050) accessible in outdated version on
1111http://xunitpatterns.com/Dependency%20Injection.html.
@@ -29,8 +29,9 @@ def test_display_current_time_at_midnight(self):
2929 """
3030 time_provider_stub = MidnightTimeProvider ()
3131 class_under_test = TimeDisplay ()
32+ class_under_test .set_time_provider (time_provider_stub )
3233 expected_time = "<span class=\" tinyBoldText\" >24:01</span>"
33- self .assertEqual (class_under_test .get_current_time_as_html_fragment (time_provider_stub ), expected_time )
34+ self .assertEqual (class_under_test .get_current_time_as_html_fragment (), expected_time )
3435
3536 def test_display_current_time_at_current_time (self ):
3637 """
@@ -39,6 +40,7 @@ def test_display_current_time_at_current_time(self):
3940 """
4041 production_code_time_provider = ProductionCodeTimeProvider ()
4142 class_under_test = TimeDisplay ()
43+ class_under_test .set_time_provider (production_code_time_provider )
4244 current_time = datetime .datetime .now ()
4345 expected_time = "<span class=\" tinyBoldText\" >" + str (current_time .hour ) + ":" + str (current_time .minute ) + "</span>"
44- self .assertEqual (class_under_test .get_current_time_as_html_fragment (production_code_time_provider ), expected_time )
46+ self .assertEqual (class_under_test .get_current_time_as_html_fragment (), expected_time )
0 commit comments