aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/test/java/com/yahoo/document/DocumentRemoveTestCase.java
blob: 5d6706b9cd752325acc4ae1bcf796b8413871d1c (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

/**
 * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
 * @since 5.1.10
 */
public class DocumentRemoveTestCase {

    @Test
    public void requireThatToStringWorks() {
        DocumentId docId = new DocumentId("id:this:is::a:test");
        DocumentRemove r = new DocumentRemove(docId);
        assertTrue(r.toString().contains(docId.toString()));
    }

    @Test
    public void requireThatEqualsAndHashCodeWorks() {
        DocumentRemove r1 = new DocumentRemove(new DocumentId("id:this:is::a:test"));
        DocumentRemove r2 = new DocumentRemove(new DocumentId("id:this:is::a:test"));
        DocumentRemove r3 = new DocumentRemove(new DocumentId("id:this:is::nonequal"));

        assertEquals(r1, r1);
        assertEquals(r1, r2);
        assertEquals(r2, r1);
        assertEquals(r1.hashCode(), r2.hashCode());

        assertNotEquals(r1, r3);
        assertNotEquals(r3, r1);
        assertNotEquals(r2, r3);
        assertNotEquals(r3, r2);
        assertNotEquals(r1.hashCode(), r3.hashCode());

        assertNotEquals(r1, new Object());
        assertFalse(r1.equals("banana"));
    }
}