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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.annotation;
import com.yahoo.document.DataType;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
* @author Einar M R Rosenvinge
*/
public class AnnotationTypeTestCase {
@Test
public void testBasic() {
AnnotationType a = new AnnotationType("foo");
AnnotationType b = new AnnotationType("foo");
assertEquals(a, b);
assertEquals(a.hashCode(), b.hashCode());
assertEquals(a.hashCode(), a.getId());
assertEquals(b.hashCode(), b.getId());
AnnotationType c = new AnnotationType("bar");
assertEquals(c.hashCode(), c.getId());
assertFalse(a.equals(c));
assertFalse(c.equals(a));
assertFalse(b.equals(c));
assertFalse(c.equals(b));
assertFalse(a.hashCode() == c.hashCode());
assertFalse(c.hashCode() == a.hashCode());
assertFalse(b.hashCode() == c.hashCode());
assertFalse(c.hashCode() == b.hashCode());
}
@Test
public void testBasic2() {
AnnotationType a = new AnnotationType("foo", DataType.INT);
AnnotationType b = new AnnotationType("foo", DataType.INT);
assertEquals(a, b);
assertEquals(a.hashCode(), b.hashCode());
assertEquals(a.hashCode(), a.getId());
assertEquals(b.hashCode(), b.getId());
AnnotationType c = new AnnotationType("foo", DataType.FLOAT);
assertEquals(c.hashCode(), c.getId());
assertEquals(a, c);
assertEquals(a.hashCode(), c.hashCode());
assertEquals(a.hashCode(), a.getId());
assertEquals(c.hashCode(), c.getId());
}
@Test
public void testPolymorphy() {
AnnotationType suuper = new AnnotationType("super");
AnnotationType sub = new AnnotationType("sub");
sub.inherit(suuper);
//reference type for super annotation type
AnnotationReferenceDataType refType = new AnnotationReferenceDataType(suuper);
Annotation superAnnotation = new Annotation(suuper);
Annotation subAnnotation = new Annotation(sub);
AnnotationReference ref1 = new AnnotationReference(refType, superAnnotation);
//this would fail without polymorphy support:
AnnotationReference ref2 = new AnnotationReference(refType, subAnnotation);
}
}
|