File size: 1,450 Bytes
04f192c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * SPDX-FileCopyrightText: Copyright contributors to the CopilotJ project.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

package copilotj.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.jupiter.api.Test;

/**
 * Unit tests for {@link FromTo}, a minimal generic value pair with no validation
 * and no defined {@code equals}.
 */
public class FromToTest {

  @Test
  public void holdsFromAndToValues() {
    final FromTo<Integer> ft = new FromTo<>(1, 2);
    assertEquals(1, ft.from);
    assertEquals(2, ft.to);
  }

  @Test
  public void acceptsNullOnBothEnds() {
    final FromTo<String> ft = new FromTo<>(null, null);
    assertNull(ft.from);
    assertNull(ft.to);
  }

  @Test
  public void acceptsNullOnOneEnd() {
    final FromTo<String> ft = new FromTo<>(null, "x");
    assertNull(ft.from);
    assertEquals("x", ft.to);
  }

  @Test
  public void worksAsStringPair() {
    final FromTo<String> ft = new FromTo<>("a", "b");
    assertEquals("a", ft.from);
    assertEquals("b", ft.to);
  }

  @Test
  public void distinctInstancesAreNotEqualByReference() {
    // FromTo defines no equals; two equal-content instances remain distinct references.
    final FromTo<Integer> a = new FromTo<>(1, 2);
    final FromTo<Integer> b = new FromTo<>(1, 2);
    assertNotSame(a, b);
  }
}