Skip to content

Latest commit

 

History

History
41 lines (33 loc) · 3.15 KB

File metadata and controls

41 lines (33 loc) · 3.15 KB

Java Report

Tech Stack

  • TCP:
    • TCP connections are very convenient to implement chat session between two users, as defined in the specifications: [CdC-Bs-9], [CdC-Bs-13]
    • In addition, they ensure that messages are correctly received, preventing desynchronization between the sender and the receiver's message history.
  • UDP:
    • UDP's broadcast feature is essential for discovering users on the local network without a central server.
  • SQLite:
    • SQLite is a lightweight database that is already installed on most systems. It is very convenient for local data storage of contacts and message history.
  • Swing:
    • Swing is a GUI toolkit for Java that is already installed on most systems. It allows us to create a GUI without heavy dependencies.
  • JUnit:
    • JUnit is the most widely used testing framework for Java. It allows us to write unit tests for our code.
  • Log4j2:
    • Log4j2 is the most widely used logging framework for Java. It allows us to log messages at different levels of severity to different outputs.
  • Apache Commons CLI:
    • Apache Commons CLI is a library that allows us to parse command line arguments in a standardised way.

Testing policy

I used code coverage tools to identify the parts of the code that were not tested. I then chose one class at a time and tested all of it's non-trivial public methods. I chose not to test the views since GUI code is difficult to test, and most bugs can be caught by manual testing. I also chose not to test the controllers since the high coupling between views and controllers makes it difficult to test them in isolation.

I wrote tests for the network classes, and other classes which depend on these on Windows, where it is possible to do the tests on localhost. However, do due differences in socket implementations on Linux, I had to create mock classes to simulate the network interaction.

Highlights

Overall, I am very proud of the structure of the code. I think that the separation of concerns between the different layers of the application is very clear.

Here are some highlights of the code:

  • The com.mgreen.database.DAO:
    • This class' methods, in particular the second executeQuery method, helped greatly simplify the SQL queries in other ...DAO classes, and is a good example of the DRY principle.
      • This method also requires the com.mgreen.database.SQLResultFunction functional interface for exception handling
    • Example usage in com.mgreen.user.storage.UserDAOSQLite
      • UserDAOSQLite::rsToUser implements SQLResultFunction
      • UserDAOSQLite::getAllOtherUsers makes use of executeQuery
    • The SQLiteDAO class is a good example of how this system can handle exceptions with different SQL flavours. The override of the executeUpdate method shows how exceptions such as ConstraintViolationException can be thrown from SQLite error codes.
  • com.mgreen.message.exchange.MessagingService
    • This class is a good example of how I use the network classes such as TCPManager and the observer pattern.
    • By implmenting the MessageHandler and TCPConnectionListener interfaces and setting itself as an observer of the TCPManager, it can contain the logic for handling connections and UserMessages in one place.