Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • 24
    A bit off-topic, but Motor probably shouldn't have a speed at all. It should have a throttle and compute a torque based on the current rpm and throttle. It's the car's job to use a Transmission to integrate that into a current speed, and to turn that into an rpm to signal back to the Motor... But I guess, you weren't in it for the realism anyway, were you? Commented Mar 20, 2018 at 14:34
  • 17
    The code smell is that your constructor takes null without complaining in the first place. If you think this is acceptable (you might have your reasons for this): go ahead, test it! Commented Mar 20, 2018 at 16:02
  • 4
    Consider the Null-Object pattern. It often simplifies code, while also making it NPE-safe. Commented Mar 20, 2018 at 18:21
  • 17
    Congratulations: you have tested that with a null radio, the speed limit is correctly computed. Now you may want to create a test to validate the speed limit with a radio; just in case the behavior differs... Commented Mar 21, 2018 at 8:16
  • 4
    Not sure about this example, but sometimes the fact that you only want to test half a class is a clue that something should be broken up Commented Mar 21, 2018 at 14:08