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/BrokenCollectionEventTest.java | |||
Method name: void testUpdateParentOneToTwoChildren()
|
Method name: void testUpdateParentNoChildrenToNullFailureExpected()
|
|||
Number of AST nodes: 19 | Number of AST nodes: 19 | |||
1 | CollectionListeners listeners = new CollectionListeners( getSessions() );↵ | 1 | CollectionListeners listeners = new CollectionListeners( getSessions() );↵ | |
2 | ParentWithCollection parent = createParentWithOneChild( "parent", "child" ↵ | 2 | ParentWithCollection parent = createParentWithNoChildren( "parent" );↵ | |
3 | );↵ | 3 | listeners.clear();↵ | |
4 | assertEquals( 1, parent.getChildren().size() );↵ | 4 | assertEquals( 0, parent.getChildren().size() );↵ | |
5 | listeners.clear();↵ | 5 | ↵ | |
6 | Session s = openSession();↵ | 6 | Session s = openSession();↵ | |
7 | Transaction tx = s.beginTransaction();↵ | 7 | Transaction tx = s.beginTransaction();↵ | |
8 | parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );↵ | 8 | parent = ( ParentWithCollection ) s.get( parent.getClass(), parent.getId() );↵ | |
9 | Child newChild = ↵ | 9 | Collection oldCollection = parent.getChildren();↵ | |
10 | parent.addChild( "new2" );↵ | 10 | parent.newChildren( null );↵ | |
11 | tx.commit();↵ | 11 | tx.commit();↵ | |
12 | s.close();↵ | 12 | s.close();↵ | |
13 | int index = 0;↵ | 13 | int index = 0;↵ | |
14 | if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {↵ | 14 | if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {↵ | |
15 | checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );↵ | 15 | checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );↵ | |
16 | }↵ | 16 | }↵ | |
17 | checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );↵ | 17 | checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );↵ | |
18 | checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );↵ | 18 | checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, ↵ | |
19 | if ( newChild instanceof ChildWithBidirectionalManyToMany ) {↵ | |||
20 | ↵ | 19 | oldCollection, index++ );↵ | |
20 | // pre- and post- collection recreate events should be created when updating an entity with a "null" collection↵ | |||
21 | checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );↵ | 21 | checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );↵ | |
22 | checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );↵ | 22 | checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );↵ | |
23 | }↵ | 23 | ↵ | |
24 | checkNumberOfResults( listeners, index ); | 24 |
| |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.2 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 172 |
Number of mapped statements | 15 |
Number of unmapped statements in the first code fragment | 4 |
Number of unmapped statements in the second code fragment | 4 |
Time elapsed for statement mapping (ms) | 8.4 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | CollectionListeners listeners = new CollectionListeners(getSessions()); | 1 | CollectionListeners listeners = new CollectionListeners(getSessions()); | |||||||||||||||
2 | ParentWithCollection parent = createParentWithOneChild("parent", "child"); |
| 2 | ParentWithCollection parent = createParentWithNoChildren("parent"); | ||||||||||||||
3 | assertEquals(1, parent.getChildren().size()); |
| 4 | assertEquals(0, parent.getChildren().size()); | ||||||||||||||
4 | listeners.clear(); | 3 | listeners.clear(); | |||||||||||||||
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 oldCollection = parent.getChildren(); | |||||||||||||||
8 | Child newChild = parent.addChild("new2"); | | ||||||||||||||||
|
| 9 | parent.newChildren(null); | |||||||||||||||
9 | tx.commit(); | 10 | tx.commit(); | |||||||||||||||
10 | s.close(); | 11 | s.close(); | |||||||||||||||
11 | int index = 0; | 12 | int index = 0; | |||||||||||||||
12 | if (((PersistentCollection)parent.getChildren()).wasInitialized()) |
| 13 | if (((PersistentCollection)oldCollection).wasInitialized()) | ||||||||||||||
13 | checkResult(listeners, listeners.getInitializeCollectionListener(), parent, index++); |
| 14 | checkResult(listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++); | ||||||||||||||
| 15 | checkResult(listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++); | ||||||||||||||||
|
| 16 | checkResult(listeners, listeners.getPostCollectionRemoveListener(), parent, oldCollection, index++); | |||||||||||||||
14 | checkResult(listeners, listeners.getPreCollectionUpdateListener(), parent, index++); |
| 17 | checkResult(listeners, listeners.getPreCollectionRecreateListener(), parent, index++); | ||||||||||||||
15 | checkResult(listeners, listeners.getPostCollectionUpdateListener(), parent, index++); |
| 18 | checkResult(listeners, listeners.getPostCollectionRecreateListener(), parent, index++); | ||||||||||||||
16 | if (newChild instanceof ChildWithBidirectionalManyToMany) | | ||||||||||||||||
17 | checkResult(listeners, listeners.getPreCollectionRecreateListener(), (ChildWithBidirectionalManyToMany)newChild, index++); | | ||||||||||||||||
18 | checkResult(listeners, listeners.getPostCollectionRecreateListener(), (ChildWithBidirectionalManyToMany)newChild, index++); |
| | |||||||||||||||
19 | checkNumberOfResults(listeners, index); | 19 | checkNumberOfResults(listeners, index); |
Row | Violation |
---|---|
1 | Unmatched statement Collection oldCollection=parent.getChildren(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
2 | Unmatched statement parent.newChildren(null); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | Expression parent.getChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
4 | Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
5 | Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
6 | Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) is a void method call, and thus it cannot be parameterized |
7 | Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) is a void method call, and thus it cannot be parameterized |
8 | Unmatched statement checkResult(listeners,listeners.getPostCollectionRemoveListener(),parent,oldCollection,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
9 | Expression listeners.getPreCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
10 | Expression listeners.getPreCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
11 | Expression listeners.getPostCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
12 | Expression listeners.getPostCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
13 | Unmatched statement checkResult(listeners,listeners.getPostCollectionRecreateListener(),(ChildWithBidirectionalManyToMany)newChild,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
14 | Clone fragment #1 returns variables parent, listeners, index , while Clone fragment #2 returns variables parent, listeners, index |