blob: 1c35199713c7810815f379c0a74b64aa943c8985 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.indexinglanguage.expressions;
import com.yahoo.document.DataType;
import com.yahoo.document.datatypes.FieldValue;
import com.yahoo.document.datatypes.LongFieldValue;
import com.yahoo.vespa.indexinglanguage.SimpleTestAdapter;
import org.junit.Test;
import static com.yahoo.vespa.indexinglanguage.expressions.ExpressionAssert.assertVerify;
import static org.junit.Assert.*;
/**
* @author Simon Thoresen Hult
*/
public class NowTestCase {
@Test
public void requireThatAccessorsWork() {
MyTimer timer = new MyTimer();
NowExpression exp = new NowExpression(timer);
assertSame(timer, exp.getTimer());
}
@Test
public void requireThatHashCodeAndEqualsAreImplemented() {
MyTimer timer = new MyTimer();
NowExpression exp = new NowExpression(timer);
assertFalse(exp.equals(new Object()));
assertFalse(exp.equals(new NowExpression(new MyTimer())));
assertEquals(exp, new NowExpression(timer));
assertEquals(exp.hashCode(), new NowExpression(timer).hashCode());
}
@Test
public void requireThatExpressionCanBeVerified() {
Expression exp = new NowExpression();
assertVerify(null, exp, DataType.LONG);
assertVerify(DataType.INT, exp, DataType.LONG);
assertVerify(DataType.STRING, exp, DataType.LONG);
}
@Test
public void requireThatCurrentTimeIsSet() {
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
new NowExpression(new MyTimer()).execute(ctx);
FieldValue val = ctx.getValue();
assertTrue(val instanceof LongFieldValue);
assertEquals(69L, ((LongFieldValue)val).getLong());
}
private class MyTimer implements NowExpression.Timer {
@Override
public long currentTimeSeconds() {
return 69L;
}
}
}
|