1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.testutils; 18 19 import java.time.Clock; 20 import java.time.Duration; 21 import java.time.Instant; 22 import java.time.ZoneId; 23 24 /** A fake {@link Clock} class for testing. */ 25 public final class FakeClock extends Clock { 26 private long mCurrentTimeMillis; 27 FakeClock()28 public FakeClock() {} 29 30 /** Sets the time in millis for {@link Clock#millis()} method. */ setCurrentTime(Duration duration)31 public void setCurrentTime(Duration duration) { 32 mCurrentTimeMillis = duration.toMillis(); 33 } 34 35 @Override getZone()36 public ZoneId getZone() { 37 throw new UnsupportedOperationException("unsupported!"); 38 } 39 40 @Override withZone(ZoneId zone)41 public Clock withZone(ZoneId zone) { 42 throw new UnsupportedOperationException("unsupported!"); 43 } 44 45 @Override instant()46 public Instant instant() { 47 throw new UnsupportedOperationException("unsupported!"); 48 } 49 50 @Override millis()51 public long millis() { 52 return mCurrentTimeMillis; 53 } 54 } 55