curioustechizen / android-ago

An Android TextView that always displays an auto refreshing relative time span with respect to a reference time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add automated tests

curioustechizen opened this issue · comments

Introduce an abstraction for getting time (instead of using System.currentTimeMillis()) directly in RTTV.

Build on top of this to add automated tests, especially around scheduling the UpdateTimeTask.

Hello,

I'm in the process of adding unit tests, but I'm running into a couple dependency problems. Adding some setters and hooking into the init seems a possible solution, but I wanted to run it by you first (and introduce myself I suppose).

For example, RTTV currently instantiates its own handler for use on line 190. Adding a setter to set a Mockito variant would be helpful for unit testing, plus having everything instantiate in init() would add some consistency

private void init(Context context, AttributeSet attrs) {
    ...
    
    if (mHandler == null) {
        mHandler = new Handler();
    }
}

=======================
EDIT:
There's an ongoing problem with tight coupling that makes testing difficult (impossible?) without an API change, e.g. Handler.post() invoked by init(), which is invoked in constructor. Consider moving setReferenceTime() to separate "start()" function?

@kwak123 Thanks for taking a stab at this. I will not have time to look into it in detail for a couple of weeks though. That said, your inputs are appreciated and I will follow up on your comments when I have time.

No problem. If you're fine with it, I can open up a PR with a possible approach

I'd prefer to discuss first before you put in the effort to make a PR!