Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fce147ae authored by Michael Enoma's avatar Michael Enoma
Browse files

Convert class 'Clock' to an interface

parent 85f590b4
Loading
Loading
Loading
Loading
+0 −32
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.fsck.k9;

/**
 * A class provide the current time (like {@link System#currentTimeMillis()}).
 * It's intended to be mocked out for unit tests.
 */
public class Clock {
    public static final Clock INSTANCE = new Clock();

    protected Clock() {
    }

    public long getTime() {
        return System.currentTimeMillis();
    }
}
+14 −0
Original line number Diff line number Diff line
package com.fsck.k9

/***
 * An interface to provide the current time.
 */

interface Clock {
    val time: Long
}

internal class RealClock : Clock {
    override val time: Long
        get() = System.currentTimeMillis()
}
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -271,7 +271,8 @@ object K9 : EarlyInit {
                return false
            }

            val quietTimeChecker = QuietTimeChecker(Clock.INSTANCE, quietTimeStarts, quietTimeEnds)
            val clock = DI.get<Clock>()
            val quietTimeChecker = QuietTimeChecker(clock, quietTimeStarts, quietTimeEnds))
            return quietTimeChecker.isQuietTime
        }

+1 −1
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ val mainModule = module {
    single { TrustManagerFactory.createInstance(get()) }
    single { LocalKeyStoreManager(get()) }
    single<TrustedSocketFactory> { DefaultTrustedSocketFactory(get(), get()) }
    single { Clock.INSTANCE }
    single<Clock> { RealClock() }
    factory { ServerNameSuggester() }
    factory { EmailAddressValidator() }
    factory { ServerSettingsSerializer() }
+2 −2
Original line number Diff line number Diff line
@@ -9,5 +9,5 @@ val jobModule = module {
    single<WorkerFactory> { K9WorkerFactory(get(), get()) }
    single { get<WorkManagerProvider>().getWorkManager() }
    single { K9JobManager(get(), get(), get()) }
    factory { MailSyncWorkerManager(get(), Clock.INSTANCE) }
    factory { MailSyncWorkerManager(workManager = get(), clock = get()) }
}
 No newline at end of file
Loading