Skip to content

Instantly share code, notes, and snippets.

@camilleriluke
Created October 20, 2014 17:25
Show Gist options
  • Save camilleriluke/9ca5c468bf4a8ae07cdd to your computer and use it in GitHub Desktop.
Save camilleriluke/9ca5c468bf4a8ae07cdd to your computer and use it in GitHub Desktop.
Unit Testing Workshop Exercises Interfaces
public interface DBConnection {
/**
* Commits a student to this connection.
*
* @param student the student to be committed.
* @return <code>0</code> if committed successfully, <code>-1</code> otherwise.
*/
int commitStudent(Student student);
}
public interface StudentDB {
/**
* Adds a student to the database.
*
* Once a new student is added to the database, the database
* will be marked as dirty.
*
* @param student the student to be added
*/
void addStudent(Student student);
/**
* Removes a student to the database.
*
* Once a student is removed from the database, the database
* will be marked as dirty.
*
* @param student the student to be removed
*/
void removeStudent(Student student);
/**
* Returns the count of unique students in the database.
*
* @return a positive integer with the count of unique students in the database
*/
int countStudents();
/**
* Commits all the student to a given connection.
* Commits only when the database is set to dirty.
*
* @param connection to which all the students will be committed.
* @return <code>true</code> if all the students where committed successfully,
* <code>false</code> otherwise.
*/
boolean commit(DBConnection connection);
/**
* Is the database dirty with any uncommitted changes.
* @return <code>true</code> if there are any uncommitted changes, <code>false</code> otherwise.
*/
boolean isDirty();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment