@@ -45,8 +45,14 @@ public class EngineVersionCheckTest extends BaseTest {
45
45
// EngineVersionCheck instance = new EngineVersionCheck();
46
46
// instance.update();
47
47
// }
48
- private long getEpoch (String date ) {
49
- return DateTime .parse (date ).toInstant ().getMillis () / 1000 ;
48
+ /**
49
+ * Converts a date in the form of yyyy-MM-dd into the epoch milliseconds.
50
+ * @param date a date in the format of yyyy-MM-dd
51
+ * @return milliseconds
52
+ */
53
+ private long dateToMilliseconds (String date ) {
54
+ DateTimeFormatter dtf = DateTimeFormat .forPattern ("yyyy-MM-dd" );
55
+ return DateTime .parse (date , dtf ).toInstant ().getMillis ();
50
56
}
51
57
52
58
/**
@@ -72,8 +78,8 @@ public String getProperty(String key) {
72
78
String updateToVersion = "1.2.6" ;
73
79
String currentVersion = "1.2.6" ;
74
80
75
- long lastChecked = getEpoch ("2014-12-01" );
76
- long now = getEpoch ("2014-12-01" );
81
+ long lastChecked = dateToMilliseconds ("2014-12-01" );
82
+ long now = dateToMilliseconds ("2014-12-01" );
77
83
78
84
EngineVersionCheck instance = new EngineVersionCheck ();
79
85
boolean expResult = false ;
@@ -83,8 +89,8 @@ public String getProperty(String key) {
83
89
84
90
updateToVersion = "1.2.5" ;
85
91
currentVersion = "1.2.5" ;
86
- lastChecked = getEpoch ("2014-10-01" );
87
- now = getEpoch ("2014-12-01" );
92
+ lastChecked = dateToMilliseconds ("2014-10-01" );
93
+ now = dateToMilliseconds ("2014-12-01" );
88
94
expResult = true ;
89
95
instance .setUpdateToVersion (updateToVersion );
90
96
result = instance .shouldUpdate (lastChecked , now , properties , currentVersion );
@@ -93,44 +99,44 @@ public String getProperty(String key) {
93
99
94
100
updateToVersion = "1.2.5" ;
95
101
currentVersion = "1.2.5" ;
96
- lastChecked = getEpoch ("2014-12-01" );
97
- now = getEpoch ("2014-12-03" );
102
+ lastChecked = dateToMilliseconds ("2014-12-01" );
103
+ now = dateToMilliseconds ("2014-12-03" );
98
104
expResult = false ;
99
105
instance .setUpdateToVersion (updateToVersion );
100
106
result = instance .shouldUpdate (lastChecked , now , properties , currentVersion );
101
107
assertEquals (expResult , result );
102
108
103
109
updateToVersion = "1.2.6" ;
104
110
currentVersion = "1.2.5" ;
105
- lastChecked = getEpoch ("2014-12-01" );
106
- now = getEpoch ("2014-12-03" );
111
+ lastChecked = dateToMilliseconds ("2014-12-01" );
112
+ now = dateToMilliseconds ("2014-12-03" );
107
113
expResult = true ;
108
114
instance .setUpdateToVersion (updateToVersion );
109
115
result = instance .shouldUpdate (lastChecked , now , properties , currentVersion );
110
116
assertEquals (expResult , result );
111
117
112
118
updateToVersion = "1.2.5" ;
113
119
currentVersion = "1.2.6" ;
114
- lastChecked = getEpoch ("2014-12-01" );
115
- now = getEpoch ("2014-12-08" );
120
+ lastChecked = dateToMilliseconds ("2014-12-01" );
121
+ now = dateToMilliseconds ("2014-12-08" );
116
122
expResult = false ;
117
123
instance .setUpdateToVersion (updateToVersion );
118
124
result = instance .shouldUpdate (lastChecked , now , properties , currentVersion );
119
125
assertEquals (expResult , result );
120
126
121
127
updateToVersion = "" ;
122
128
currentVersion = "1.2.5" ;
123
- lastChecked = getEpoch ("2014-12-01" );
124
- now = getEpoch ("2014-12-03" );
129
+ lastChecked = dateToMilliseconds ("2014-12-01" );
130
+ now = dateToMilliseconds ("2014-12-03" );
125
131
expResult = false ;
126
132
instance .setUpdateToVersion (updateToVersion );
127
133
result = instance .shouldUpdate (lastChecked , now , properties , currentVersion );
128
134
assertEquals (expResult , result );
129
135
130
136
updateToVersion = "" ;
131
137
currentVersion = "1.2.5" ;
132
- lastChecked = getEpoch ("2014-12-01" );
133
- now = getEpoch ("2015-12-08" );
138
+ lastChecked = dateToMilliseconds ("2014-12-01" );
139
+ now = dateToMilliseconds ("2015-12-08" );
134
140
expResult = true ;
135
141
instance .setUpdateToVersion (updateToVersion );
136
142
result = instance .shouldUpdate (lastChecked , now , properties , currentVersion );
0 commit comments