Exemplo n.º 1
0
  @Test
  public void shouldShallowCopyFieldValuesIntoMock() throws Exception {
    // given
    from.defaultField = "foo";
    from.instancePublicField = new SomeOtherObject();
    from.privateField = 1;
    from.privateTransientField = 2;
    from.protectedField = 3;

    assertNotEquals(from.defaultField, to.defaultField);
    assertNotEquals(from.instancePublicField, to.instancePublicField);
    assertNotEquals(from.privateField, to.privateField);
    assertNotEquals(from.privateTransientField, to.privateTransientField);
    assertNotEquals(from.protectedField, to.protectedField);

    // when
    tool.copyToMock(from, to);

    // then
    assertEquals(from.defaultField, to.defaultField);
    assertEquals(from.instancePublicField, to.instancePublicField);
    assertEquals(from.privateField, to.privateField);
    assertEquals(from.privateTransientField, to.privateTransientField);
    assertEquals(from.protectedField, to.protectedField);
  }
Exemplo n.º 2
0
  @Test
  public void shouldShallowCopyTransientPrivateFields() throws Exception {
    // given
    from.privateTransientField = 1000;
    assertNotEquals(1000, to.privateTransientField);

    // when
    tool.copyToMock(from, to);

    // then
    assertEquals(1000, to.privateTransientField);
  }
Exemplo n.º 3
0
  @Test
  public void shouldBeAbleToCopyFromRealObjectToRealObject() throws Exception {

    // given
    from.defaultField = "defaultField";
    from.instancePublicField = new SomeOtherObject();
    from.privateField = 1;
    from.privateTransientField = 2;
    from.protectedField = "protectedField";
    from.protectedInherited = "protectedInherited";
    to = new SomeObject(0);

    // when
    tool.copyToRealObject(from, to);

    // then
    assertEquals(from.defaultField, to.defaultField);
    assertEquals(from.instancePublicField, to.instancePublicField);
    assertEquals(from.privateField, to.privateField);
    assertEquals(from.privateTransientField, to.privateTransientField);
    assertEquals(from.protectedField, to.protectedField);
    assertEquals(from.protectedInherited, to.protectedInherited);
  }