// Path: src/main/java/com/aragaer/jtt/mechanics/AndroidTicker.java
// public class AndroidTicker extends Handler implements Ticker {
//     public static final String ACTION_JTT_TICK = "com.aragaer.jtt.action.TICK";
// 
//     private final Clockwork _clockwork;
//     private final Announcer _announcer;
// 
//     public AndroidTicker(Clockwork clockwork, Announcer announcer) {
//         _clockwork = clockwork;
//         _announcer = announcer;
//     }
// 
//     public void start() {
//         sendEmptyMessage(0);
//     }
// 
//     public void stop() {
//         removeMessages(0);
//     }
// 
//     @Override public void handleMessage(@NonNull Message msg) {
//         removeMessages(0);
//         Log.d("JTT CLOCKWORK", "Handler ticked");
//         long now = System.currentTimeMillis();
//         _clockwork.setTime(now);
// 
//         long ms_passed = now - _clockwork.start;
//         int ticks_passed = (int) (ms_passed / _clockwork.repeat);
//         long next_tick = (ticks_passed + 1) * _clockwork.repeat + _clockwork.start;
//         long delay = next_tick - now;
//         sendEmptyMessageDelayed(0, delay);
//         Log.d("JTT CLOCKWORK", "Tick delay " + delay);
//         Log.d("JTT CLOCKWORK", "Next tick scheduled at "+(new SimpleDateFormat("HH:mm:ss.SSS", Locale.US).format(next_tick)));
//         _announcer.announce(now);
//     }
// }


import android.content.*;
import androidx.test.uiautomator.UiDevice;
import org.junit.*;
import com.aragaer.jtt.mechanics.AndroidTicker;
import static org.junit.Assert.*;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; -*-
// vim: et ts=4 sts=4 sw=4 syntax=java
package com.aragaer.jtt;






public class JttServiceTest {

    private Context context;
    private MyReceiver receiver;

    @Before public void setUp() {
        context = getInstrumentation().getTargetContext();
        receiver = new MyReceiver();
        context.removeStickyBroadcast(new Intent(AndroidTicker.ACTION_JTT_TICK));
        context.registerReceiver(receiver, new IntentFilter(AndroidTicker.ACTION_JTT_TICK));
    }

    @After public void cleanUp() {
        context.stopService(new Intent(context, JttService.class));
// Path: src/main/java/com/aragaer/jtt/mechanics/AndroidTicker.java
// public class AndroidTicker extends Handler implements Ticker {
//     public static final String ACTION_JTT_TICK = "com.aragaer.jtt.action.TICK";
// 
//     private final Clockwork _clockwork;
//     private final Announcer _announcer;
// 
//     public AndroidTicker(Clockwork clockwork, Announcer announcer) {
//         _clockwork = clockwork;
//         _announcer = announcer;
//     }
// 
//     public void start() {
//         sendEmptyMessage(0);
//     }
// 
//     public void stop() {
//         removeMessages(0);
//     }
// 
//     @Override public void handleMessage(@NonNull Message msg) {
//         removeMessages(0);
//         Log.d("JTT CLOCKWORK", "Handler ticked");
//         long now = System.currentTimeMillis();
//         _clockwork.setTime(now);
// 
//         long ms_passed = now - _clockwork.start;
//         int ticks_passed = (int) (ms_passed / _clockwork.repeat);
//         long next_tick = (ticks_passed + 1) * _clockwork.repeat + _clockwork.start;
//         long delay = next_tick - now;
//         sendEmptyMessageDelayed(0, delay);
//         Log.d("JTT CLOCKWORK", "Tick delay " + delay);
//         Log.d("JTT CLOCKWORK", "Next tick scheduled at "+(new SimpleDateFormat("HH:mm:ss.SSS", Locale.US).format(next_tick)));
//         _announcer.announce(now);
//     }
// }


// Path: src/androidTest/java/com/aragaer/jtt/JttServiceTest.java
import android.content.*;
import androidx.test.uiautomator.UiDevice;
import org.junit.*;
import com.aragaer.jtt.mechanics.AndroidTicker;
import static org.junit.Assert.*;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; -*-
// vim: et ts=4 sts=4 sw=4 syntax=java
package com.aragaer.jtt;






public class JttServiceTest {

    private Context context;
    private MyReceiver receiver;

    @Before public void setUp() {
        context = getInstrumentation().getTargetContext();
        receiver = new MyReceiver();
        context.removeStickyBroadcast(new Intent(AndroidTicker.ACTION_JTT_TICK));
        context.registerReceiver(receiver, new IntentFilter(AndroidTicker.ACTION_JTT_TICK));
    }

    @After public void cleanUp() {
        context.stopService(new Intent(context, JttService.class));
        context.removeStickyBroadcast(new Intent(AndroidTicker.ACTION_JTT_TICK));