CollectionListeners listeners = new CollectionListeners( getSessions() ); ParentWithCollection parent = createParentWithNullChildren( "parent" ); listeners.clear(); assertNull( parent.getChildren() ); Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); Collection collectionOrig = parent.getChildren(); parent.newChildren( createCollection() ); Child newChild = parent.addChild( "new" ); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) collectionOrig ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, collectionOrig, index++ ); } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, collectionOrig, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, collectionOrig, index++ ); if ( newChild instanceof ChildWithBidirectionalManyToMany ) { checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); } checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ ); checkNumberOfResults( listeners, index );
CollectionListeners listeners = new CollectionListeners( getSessions() ); ParentWithCollection parent = createParentWithNoChildren( "parent" ); listeners.clear(); assertEquals( 0, parent.getChildren().size() ); Session s = openSession(); Transaction tx = s.beginTransaction(); parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() ); Collection oldCollection = parent.getChildren(); parent.newChildren( createCollection() ); Child newChild = parent.addChild( "new" ); tx.commit(); s.close(); int index = 0; if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) { checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ ); } checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ ); checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ ); if ( newChild instanceof ChildWithBidirectionalManyToMany ) { checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ ); } checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ ); checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ ); checkNumberOfResults( listeners, index );
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/event/collection/AbstractCollectionEventTest.java
Method name: void testUpdateParentNullToOneChildDiffCollection() Method name: void testUpdateParentNoneToOneChildDiffCollection()
Number of AST nodes: 23 Number of AST nodes: 23
1
CollectionListeners listeners = new CollectionListeners( getSessions() );
1
CollectionListeners listeners = new CollectionListeners( getSessions() );
2
		ParentWithCollection parent = createParentWithNullChildren( "parent" );
2
		ParentWithCollection parent = createParentWithNoChildren( "parent" );
3
		listeners.clear();
3
		listeners.clear();
4
		assertNull( parent.getChildren() );
4
		assertEquals( 0, parent.getChildren().size() );
5
		Session s = openSession();
5
		Session s = openSession();
6
		Transaction tx = s.beginTransaction();
6
		Transaction tx = s.beginTransaction();
7
		parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
7
		parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );
8
		Collection collectionOrig = parent.getChildren();
8
		Collection oldCollection = parent.getChildren();
9
		parent.newChildren( createCollection() );
9
		parent.newChildren( createCollection() );
10
		Child newChild = parent.addChild( "new" );
10
		Child newChild = parent.addChild( "new" );
11
		tx.commit();
11
		tx.commit();
12
		s.close();
12
		s.close();
13
		int index = 0;
13
		int index = 0;
14
		if ( ( ( PersistentCollection ) collectionOrig ).wasInitialized() ) {
14
		if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {
15
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, collectionOrig, index++ );
15
			checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );
16
		}
16
		}
17
		checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, collectionOrig, index++ );
17
		checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );
18
		checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, collectionOrig, index++ );
18
		checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++ );
19
		if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
19
		if ( newChild instanceof ChildWithBidirectionalManyToMany ) {
20
			checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
20
			checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
21
			checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
21
			checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );
22
		}
22
		}
23
		checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
23
		checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );
24
		checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
24
		checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );
25
		checkNumberOfResults( listeners, index );
25
		checkNumberOfResults( listeners, index );
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.3
Clones locationClones are declared in the same class
Number of node comparisons206
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements23
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)8.8
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    CollectionListeners listeners = new CollectionListeners(getSessions());
    1
    CollectionListeners listeners = new CollectionListeners(getSessions());
    2
    ParentWithCollection parent = createParentWithNullChildren("parent");
    2
    ParentWithCollection parent = createParentWithNullChildren("parent");
    2
    ParentWithCollection parent = createParentWithNoChildren("parent");
    Differences
    Expression1Expression2Difference
    createParentWithNullChildrencreateParentWithNoChildrenMETHOD_INVOCATION_NAME_MISMATCH
    2
    ParentWithCollection parent = createParentWithNoChildren("parent");
    3
    listeners.clear();
    3
    listeners.clear();
    4
    assertNull(parent.getChildren());
    4
    assertNull(parent.getChildren());
    4
    assertEquals(0, parent.getChildren().size());
    Differences
    Expression1Expression2Difference
    assertNullassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    assertNull(parent.getChildren())assertEquals(0,parent.getChildren().size())ARGUMENT_NUMBER_MISMATCH
    Preondition Violations
    Expression assertNull(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    Expression assertNull(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertNull(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    4
    assertEquals(0, parent.getChildren().size());
    5
    Session s = openSession();
    5
    Session s = openSession();
    6
    Transaction tx = s.beginTransaction();
    6
    Transaction tx = s.beginTransaction();
    7
    parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId());
    7
    parent = (ParentWithCollection)s.get(parent.getClass(), parent.getId());
    8
    Collection collectionOrig = parent.getChildren();
    8
    Collection collectionOrig = parent.getChildren();
    8
    Collection oldCollection = parent.getChildren();
    Differences
    Expression1Expression2Difference
    collectionOrigoldCollectionVARIABLE_NAME_MISMATCH
    8
    Collection oldCollection = parent.getChildren();
    9
    parent.newChildren(createCollection());
    9
    parent.newChildren(createCollection());
    10
    Child newChild = parent.addChild("new");
    10
    Child newChild = parent.addChild("new");
    11
    tx.commit();
    11
    tx.commit();
    12
    s.close();
    12
    s.close();
    13
    int index = 0;
    13
    int index = 0;
    14
    if (((PersistentCollection)collectionOrig).wasInitialized())
    14
    if (((PersistentCollection)collectionOrig).wasInitialized())
    14
    if (((PersistentCollection)oldCollection).wasInitialized())
    Differences
    Expression1Expression2Difference
    collectionOrigoldCollectionVARIABLE_NAME_MISMATCH
    14
    if (((PersistentCollection)oldCollection).wasInitialized())
    15
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, collectionOrig, index++);
    15
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, collectionOrig, index++);
    15
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++);
    Differences
    Expression1Expression2Difference
    collectionOrigoldCollectionVARIABLE_NAME_MISMATCH
    15
    checkResult(listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++);
    16
    checkResult(listeners, listeners.getPreCollectionRemoveListener(), parent, collectionOrig, index++);
    16
    checkResult(listeners, listeners.getPreCollectionRemoveListener(), parent, collectionOrig, index++);
    16
    checkResult(listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++);
    Differences
    Expression1Expression2Difference
    collectionOrigoldCollectionVARIABLE_NAME_MISMATCH
    16
    checkResult(listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++);
    17
    checkResult(listeners, listeners.getPostCollectionRemoveListener(), parent, collectionOrig, index++);
    17
    checkResult(listeners, listeners.getPostCollectionRemoveListener(), parent, collectionOrig, index++);
    17
    checkResult(listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++);
    Differences
    Expression1Expression2Difference
    collectionOrigoldCollectionVARIABLE_NAME_MISMATCH
    17
    checkResult(listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++);
    18
    if (newChild instanceof ChildWithBidirectionalManyToMany)
    18
    if (newChild instanceof ChildWithBidirectionalManyToMany)
    19
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), (ChildWithBidirectionalManyToMany)newChild, index++);
    19
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), (ChildWithBidirectionalManyToMany)newChild, index++);
    20
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), (ChildWithBidirectionalManyToMany)newChild, index++);
    20
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), (ChildWithBidirectionalManyToMany)newChild, index++);
    21
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), parent, index++);
    21
    checkResult(listeners, listeners.getPreCollectionRecreateListener(), parent, index++);
    22
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), parent, index++);
    22
    checkResult(listeners, listeners.getPostCollectionRecreateListener(), parent, index++);
    23
    checkNumberOfResults(listeners, index);
    23
    checkNumberOfResults(listeners, index);
    Precondition Violations (8)
    Row Violation
    1Expression assertNull(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression assertNull(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    4Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized
    5Expression assertNull(parent.getChildren()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression assertEquals(0,parent.getChildren().size()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression assertNull(parent.getChildren()) is a void method call, and thus it cannot be parameterized
    8Expression assertEquals(0,parent.getChildren().size()) is a void method call, and thus it cannot be parameterized