Asserting your method get valid arguments can’t be easier than using …

Just wanted to help myself and anyone interested in topic simplify asserting my methods receive valid arguments before ever executing main logic.
One easy way to do so is using Java’s assert keyword.

So, say you have method:

     private static int populateMatrixSortedAscending() {
        int counter = 0;
        final int totalRows = matrix.length;
        for (int i = 0; i < totalRows; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                int newEntry = newEntry();
                while (!isValidNewEntry(newEntry, i, j)) {
                    newEntry = newEntry();
                matrix[i][j] = newEntry;
        return counter;

Continue reading