Package org.libreplan.business.util.deepcopy.EntityExamples

Examples of org.libreplan.business.util.deepcopy.EntityExamples.EntityA


        assertSame(originalDate, copy.getSharedProperty());
    }

    @Test
    public void sharedCollectionsAreCopiedWithTheSameReference() {
        EntityA entityA = new EntityA();
        List<String> originalList = Arrays.asList("bla");
        entityA.setSharedListProperty(originalList);
        EntityA copy = new DeepCopy().copy(entityA);
        assertSame(originalList, copy.getSharedListProperty());
    }
View Full Code Here


        assertSame(originalList, copy.getSharedListProperty());
    }

    @Test
    public void sharedCollectionElementsKeptTheReferences() {
        EntityA entityA = new EntityA();
        HashSet<Object> originalSet = new HashSet<Object>();
        originalSet.add(new Date());
        entityA.setSharedElementsProperty(originalSet);
        EntityA copy = new DeepCopy().copy(entityA);
        assertNotSame(originalSet, copy.getSharedElementsProperty());
        assertSame(originalSet.iterator().next(), copy
                .getSharedElementsProperty().iterator().next());
    }
View Full Code Here

                .getSharedElementsProperty().iterator().next());
    }

    @Test
    public void sharedKeyElementsKeepTheSameReferencesForTheKeys() {
        EntityA entityA = new EntityA();
        Map<Object, Object> originalMap = new HashMap<Object, Object>();
        EntityA originalValue = new EntityA();
        Date originalKey = new Date();
        originalMap.put(originalKey, originalValue);
        entityA.setSharedKeysMapProperty(originalMap);
        EntityA copy = new DeepCopy().copy(entityA);
        Map<Object, Object> sharedKeysMapProperty = copy
                .getSharedKeysMapProperty();
        assertSame(originalKey, sharedKeysMapProperty.keySet().iterator()
                .next());
        assertNotSame(originalValue, sharedKeysMapProperty.values().iterator()
                .next());
View Full Code Here

                .next());
    }

    @Test
    public void sharedValueElementsKeepTheSameReferencesForTheValues() {
        EntityA entityA = new EntityA();
        Map<Object, Object> originalMap = new HashMap<Object, Object>();
        EntityA originalValue = new EntityA();
        Date originalKey = new Date();
        originalMap.put(originalKey, originalValue);
        entityA.setSharedValuesMapProperty(originalMap);
        EntityA copy = new DeepCopy().copy(entityA);
        Map<Object, Object> copiedMap = copy
                .getSharedValuesMapProperty();
        assertNotSame(originalKey, copiedMap.keySet().iterator()
                .next());
        assertSame(originalValue, copiedMap.values().iterator()
                .next());
View Full Code Here

                .next());
    }

    @Test
    public void aSharedCollectionElementsMapKeepTheSameReferencesForTheKeysAndTheValues() {
        EntityA entityA = new EntityA();
        Map<Object, Object> originalMap = new HashMap<Object, Object>();
        EntityA originalValue = new EntityA();
        Date originalKey = new Date();
        originalMap.put(originalKey, originalValue);
        entityA.setSharedCollectionElementsMapProperty(originalMap);
        EntityA copy = new DeepCopy().copy(entityA);
        Map<Object, Object> copiedMap = copy
                .getSharedCollectionElementsMapProperty();
        assertSame(originalKey, copiedMap.keySet().iterator()
                .next());
        assertSame(originalValue, copiedMap.values().iterator()
                .next());
View Full Code Here

    }

    @Test
    public void ifNotInnmutableNorCustomCopyRecursivelyCopiesIt() {
        Parent parent = new Parent();
        EntityA entityAProperty = new EntityA();
        Date originalDate = new Date();
        entityAProperty.setDate(originalDate);
        parent.setEntityAProperty(entityAProperty);
        Parent copy = new DeepCopy().copy(parent);
        assertNotSame(parent, copy);
        assertThat(copy.getEntityAProperty().getDate(), equalTo(originalDate));
        assertNotSame(copy.getEntityAProperty().getDate(), originalDate);
View Full Code Here

    }

    @Test
    public void alreadyCopiedInstancesAreReused() {
        Parent parent = new Parent();
        EntityA entityA = new EntityA();
        parent.setEntityAProperty(entityA);
        entityA.setParentProperty(parent);
        Parent copy = new DeepCopy().copy(parent);
        assertSame(copy, copy.getEntityAProperty().getParentProperty());
    }
View Full Code Here

    }

    @Test
    public void alreadyCopiedSetsAreReused() {
        Parent parent = new Parent();
        EntityA entityA = new EntityA();
        parent.setEntityAProperty(entityA);
        entityA.setParentProperty(parent);
        HashSet<Object> originalSet = new HashSet<Object>();
        parent.setSetProperty(originalSet);
        entityA.setSetProperty(originalSet);
        Parent copy = new DeepCopy().copy(parent);
        assertSame(copy.getSetProperty(), copy.getEntityAProperty()
                .getSetProperty());
    }
View Full Code Here

    @Test
    public void canSpecifyReplacements() {
        DeepCopy deepCopy = new DeepCopy();
        Parent parent = new Parent();
        EntityA entityA = new EntityA();
        parent.setEntityAProperty(entityA);
        EntityA anotherEntity = new EntityA();
        deepCopy.replace(entityA, anotherEntity);
        Parent copy = deepCopy.copy(parent);
        assertSame(copy.getEntityAProperty(), anotherEntity);
    }
View Full Code Here

    }

    @Test
    public void afterCopyHooksCanBeDefined() {
        DeepCopy deepCopy = new DeepCopy();
        EntityA entityA = new EntityA();
        EntityA copy = deepCopy.copy(entityA);
        assertTrue(copy.isFirstHookCalled());
        assertTrue(copy.isSecondHookCalled());
    }
View Full Code Here

TOP

Related Classes of org.libreplan.business.util.deepcopy.EntityExamples.EntityA

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.