I'm developing an Android application which would remotely connect to an insurance database and perform some basic CRUD operations and I'd like to learn how to keep clean app's architecture from Fernando Cejas' and Uncle Bob's blog entries. Presented below domain layer contains entities and use cases which I don't want to be affected by any database or UI - they are pure general business rules, but I have few questions regarding their implementation before I proceed to writing data layer, which will obtain data from a cloud, or presenter layer, which would be an Android GUI.


package com.domain.model;

import java.util.Collection;

public class Oc {

    private final String ocId;

    public Oc(String ocId) {
        this.ocId = ocId;

    private Collection<Discount> discounts;

    public Collection<Discount> getDiscounts() {
        return discounts;

    public void setDiscounts(Collection<Discount> discounts) {
        this.discounts = discounts;


package com.domain.model;

public interface Discount {
    enum Type {ADD, MULTIPLY}


package com.domain.model;

public class DiscountImpl implements Discount {
    private String name;
    private float value;
    private Type type;

    public DiscountImpl(String name) {
        this.name = name;

    public String getName() {
        return name;

I have many empty interfaces for Oc's objects like Discount.java as I wanted to follow ISP and DI. Is that quantity of interfaces a good approach? Should I implement custom annotations for them?


package com.domain.repository;

import com.domain.exception.ErrorBundle;
import com.domain.model.Customer;
import com.domain.model.Oc;

import java.util.Collection;

public interface OcRepository {
    void getOcRecentList(final int userId, OcListCallback ocListCallback);
    void getOcById(final int ocId, OcCallback ocCallback);
    void getOcByRegistrationNumber(int ocRegistrationNumber, OcCallback ocCallback);
    void getOcByCustomer(Customer customer, OcListCallback ocListCallback);
    void addOc(Oc oc, OcAddCallback ocAddCallback);
    void removeOc(final int ocId, OcRemoveCallback ocRemoveCallback);
    void modifyOc(Oc oc, OcModifyCallback ocModifyCallback);

    interface ErrorHandle{
        void onError(ErrorBundle errorBundle);

    interface OcListCallback extends ErrorHandle{
        void onOcListReceived(Collection<Oc> ocCollection);

    interface OcCallback extends ErrorHandle{
        void onOcReceived(Oc oc);

    interface OcAddCallback extends ErrorHandle{
        void onOcAdded();

    interface OcRemoveCallback extends ErrorHandle{
        void onOcRemoved();

    interface OcModifyCallback extends ErrorHandle{
        void onOcModified();

Will these Repository pattern's hard-coded methods (getOc by id, registrationNumber, Customer...) make my OcRepository rigid, and should I come up with some criteria solution? Can callbacks be shared by a few methods (like OcCallback in this case)?

package com.domain.test;

import com.domain.model.Car;
import com.domain.model.Customer;
import com.domain.model.CustomerImpl;
import com.domain.model.Discount;
import com.domain.model.DiscountImpl;
import com.domain.model.Oc;
import com.domain.model.User;
import com.domain.model.UserImpl;
import com.domain.model.Vehicle;
import com.domain.model.Zone;
import com.domain.model.ZoneImpl;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class OcTest {

    private Oc oc;
    private Customer customer;
    private Vehicle car;
    private Collection<Discount> discounts = new List<Discount>() {(...)};
    private Zone zone;
    private User user;

    public void setUp() throws Exception {
        DiscountImpl discount1 = new DiscountImpl("New car");

        DiscountImpl discount2 = new DiscountImpl("Disabled");


        Car car = new Car("ASD 5256");

        this.car = car;

        ZoneImpl zone = new ZoneImpl(1);

        this.zone = zone;

        CustomerImpl customer = new CustomerImpl("9876541231");

        UserImpl user = new UserImpl("X001");

        this.oc = new Oc("0266");

    public void tearDown() throws Exception {


    public void testSetCustomer() throws Exception {
        Assert.assertEquals(this.customer, oc.getCustomer());

    public void testSetVehicle() throws Exception {
        Assert.assertEquals(this.car, oc.getVehicle());

    public void testSetDiscounts() throws Exception {
        Assert.assertEquals(this.discounts, oc.getDiscounts());

    public void testSetInsurer() throws Exception {
        Assert.assertEquals(this.user, oc.getInsurer());


Whole source code

Are there any other unit tests I should perform on such entities' relations? I didn't come up with anything more that this to check for any errors, and simple checking setters and getters is useless. Any other comments regarding the design pattern, SOLID principles, unit testing or whatever will be appreciated.


1 Answer 1


After cloning your project and reviewing the blog post you mentioned I find that your structure is close. I can see that you tried copying what he did, but missed a few points: Your tests are in the same directory as your production code. This is frowned upon in all words of languages that I've been in (C# being my current, but Java and Android all apply). Looking at Android10's github link and I see that he correctly put his tests in a different directory (domain/src/main for production code, domain/src/test for his tests) than his production code. So that is my first item in your review: Move your tests out of your production code. I would be angry if I saw JUnit library floating around on my android device!

Short blurb about names. What is OC? I've read the source, I've read your tests, but can't figure out what OC stands for. Use a better name. Uncle Bob would have wagged his finger at you for that. :)

OcTest: I'm not sure if this is just the initial phase of your tests, but they are not very good. In general testing anything with a Cyclomatic Complexity (Wiki Page) of one is not needed nor is it helpful. The reason for that is is that it adds no value to your code. Doing this is akin to testing the framework and not the behavior of your system; It makes for brittle tests. I say brittle because properties change, structures change and if Oc is going to only be a model with getters and setters you don't want to have to change all your tests around it because of a small change like that. Look through Android10's tests and see how he does his tests. From what I've read so far his tests are good.

If you really really still wanted to have unit tests on your model, at least come up with a system that uses reflection to get all your getters and setters and exercises them. This way your model and change, but your tests won't.

I see that your code base is kind of big so there are other things you could open a new thread about. I'd be more than happy to review those as well if you put them up here.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.