Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using TDD: File Synchronization with Client/Server

I started trying to learn tdd and wanted to use it on a real project. So I decided on programming a simple file synchronization with a client and a server in java. After more or less finishing the client part, I got stuck while writing the server part.

In order to unit test the logic without accessing external resources, I put those in separate classes, so that I could mock them. So far, so good.

Now here's my question:

This image shows how I imagined everything could look like, where green parts are finished and the yellow parts are not yet implemented.

In my case I'd have to pass RemoteServer a ConnectionManager. The ConnectionManager would a need a FileAdapter and a Communicator in order to create a ClientConnectionHandler. That sounds like a little bit too much passing for me. Is this normal for tdd'ing or am I doing something wrong in order to keep everything testable?

edit: The class ClientConnectionHandler is only responsible for the file sync logic on the server side, which means: Following my own mini protocol to receive files from a client.

like image 294
b1nh Avatar asked Nov 04 '22 15:11

b1nh


1 Answers

It's pretty normal. If you get one class that has many dependencies, it likely has too many responsibilities as well. But having one class that depends on another class that depends on another - that's normal.

This is why IoC Container libraries like Spring are popular. They make it easier to wire up (configure and resolve) all of the dependencies.

like image 151
TrueWill Avatar answered Nov 10 '22 15:11

TrueWill