Debian Codegraph @

common/src/main/java/com/android/utils/DateProvider.java

raw
1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
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.utils;
18
19 import java.util.Date;
20
21 /**
22 * Provides abstraction over @{link Date#Date()}, to allow code to swap out calls to system date by
23 * a fake date in tests to create reliable tests.
24 */
25 public interface DateProvider {
26 /**
27 * Implementation that calls to the real @{link Date#Date()}. This should never be called
28 * through directly in code. The right pattern is to create a variable and assign that variable
29 * to {@link #SYSTEM} upon initialization and override the variable in tests.
30 */
31 DateProvider SYSTEM =
32 new DateProvider() {
33 @Override
34 public Date now() {
35 return new Date();
36 }
37 };
38
39 /**
40 * Provides this DataProvider's notion of 'now'.
41 */
42 Date now();
43 }