Esempio n. 1
0
  @Test
  public void objectAttributes() {
    Anchor a = new Anchor();
    // TODO define before-id hashcode behaviour
    a.setId("123");
    int iStartHashCode = a.hashCode();
    a.setOffset(456.789);
    a.put("foo", "bar");
    int iEndHashCode = a.hashCode();
    assertEquals("Immutable hashcode:", iStartHashCode, iEndHashCode);
    assertEquals("456.789", a.toString());

    assertTrue("Equality reflexive", a.equals(a));
    Anchor a2 = new Anchor();
    assertFalse("equals before id set:", a.equals(a2));
    a2.setId("123");
    a2.setOffset(456.789);
    // no "foo" attribute, to ensure it doesn't contribute to equality
    assertTrue("id defines equality:", a.equals(a2));
    assertTrue("Equality is symmetric:", a2.equals(a));
    assertEquals("Comparable:", 0, a.compareTo(a2));

    a2.setOffset(123.456);
    assertTrue("offset doesn't affect equality:", a.equals(a2));

    a2.setId("different id");
    assertFalse("Different id:", a.equals(a2));
    assertTrue("Compare by offset - 456.123 > 123.456", a.compareTo(a2) > 0);
    a2.setOffset(a.getOffset());
    assertTrue(
        "Comparable: if offsets are equal, comparison is by ID - \"123\" < \"different id\"",
        a.compareTo(a2) < 0);
    a2.setOffset(null);
    assertTrue(
        "Comparable: if left offset is null, comparison is by ID - \"123\" < \"different id\"",
        a.compareTo(a2) < 0);
    assertTrue(
        "Comparable: if right offset is null, comparison is by ID - \"different id\" > \"123\"",
        a2.compareTo(a) > 0);
    a2.setId(a.getId());
    assertTrue("Resetting attribute resets equality:", a.equals(a2));

    LinkedHashMap<String, Object> aMap = new LinkedHashMap<String, Object>();
    aMap.putAll(a);
    assertFalse("A map with the same attributes isn't equal:", a.equals(aMap));
  }
Esempio n. 2
0
 @Test
 public void extendedAttributes() {
   Anchor a = new Anchor();
   a.setId("123");
   a.setOffset(456.789);
   a.put("alignmentStatus", 50);
   assertEquals(new Integer(50), a.get("alignmentStatus"));
 }
Esempio n. 3
0
  @Test
  public void basicAttributes() {
    // Default constructor
    Anchor a = new Anchor();
    a.setId("123");
    a.setOffset(456.789);
    assertEquals("123", a.getId());
    assertEquals("123", a.get("id"));
    assertEquals(new Double(456.789), a.getOffset());
    assertEquals(new Double(456.789), a.get("offset"));
    assertEquals("456.789", a.toString());

    // Basic constructor
    a = new Anchor("123", 456.789);
    assertEquals("123", a.getId());
    assertEquals("123", a.get("id"));
    assertEquals(new Double(456.789), a.getOffset());
    assertEquals(new Double(456.789), a.get("offset"));
    assertEquals("456.789", a.toString());
  }
Esempio n. 4
0
  @Test
  public void changeTracking() {
    Anchor a = new Anchor();
    a.setId("123");
    a.setOffset(456.789);
    a.put("foo", "bar");
    assertEquals(new Double(456.789), a.getOffset());
    assertEquals("Offset and original are the same", a.getOriginalOffset(), a.getOffset());
    assertEquals(Change.Operation.NoChange, a.getChange());

    a.put("foo", "foo");
    assertEquals("Only offset affects change:", Change.Operation.NoChange, a.getChange());

    a.setOffset(123.456);
    assertEquals(new Double(123.456), a.getOffset());
    assertEquals(
        "Original offset remembers first offset:", new Double(456.789), a.get("originalOffset"));
    assertEquals(
        "Original offset remembers first offset:", new Double(456.789), a.getOriginalOffset());
    assertEquals(Change.Operation.Update, a.getChange());

    a.setOffset(456.123);
    assertEquals(new Double(456.123), a.getOffset());
    assertEquals("Original offset only set once:", new Double(456.789), a.getOriginalOffset());
    assertEquals(Change.Operation.Update, a.getChange());

    a.rollback();
    assertEquals(new Double(456.789), a.getOffset());
    assertEquals("Offset and original are the same", a.getOriginalOffset(), a.getOffset());
    assertEquals(Change.Operation.NoChange, a.getChange());

    a.destroy();
    assertEquals(Change.Operation.Destroy, a.getChange());
    a.rollback();
    assertEquals(Change.Operation.NoChange, a.getChange());

    a.create();
    assertEquals(Change.Operation.Create, a.getChange());
    a.rollback();
    assertEquals("Create cannot be rolled back:", Change.Operation.Create, a.getChange());
  }