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 testUpdateParentNoneToOneChild()
|
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 = createParentWithNoChildren( "parent" );↵ | 2 | ParentWithCollection parent = createParentWithNoChildren( "parent" );↵ | |
3 | listeners.clear();↵ | 3 | listeners.clear();↵ | |
4 | assertEquals( 0, parent.getChildren().size() );↵ | 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 | Child newChild = ↵ | 8 | Collection oldCollection = parent.getChildren();↵ | |
9 | parent.addChild( "new" );↵ | 9 | parent.newChildren( null );↵ | |
10 | tx.commit();↵ | 10 | tx.commit();↵ | |
11 | s.close();↵ | 11 | s.close();↵ | |
12 | int index = 0;↵ | 12 | int index = 0;↵ | |
13 | if ( ( ( PersistentCollection ) parent.getChildren() ).wasInitialized() ) {↵ | 13 | if ( ( ( PersistentCollection ) oldCollection ).wasInitialized() ) {↵ | |
14 | checkResult( listeners, listeners.getInitializeCollectionListener(), parent, index++ );↵ | 14 | checkResult( listeners, listeners.getInitializeCollectionListener(), parent, oldCollection, index++ );↵ | |
15 | }↵ | 15 | }↵ | |
16 | checkResult( listeners, listeners.getPreCollectionUpdateListener(), parent, index++ );↵ | 16 | checkResult( listeners, listeners.getPreCollectionRemoveListener(), parent, oldCollection, index++ );↵ | |
17 | checkResult( listeners, listeners.getPostCollectionUpdateListener(), parent, index++ );↵ | 17 | checkResult( listeners, listeners.getPostCollectionRemoveListener(), parent, ↵ | |
18 | if ( newChild instanceof ChildWithBidirectionalManyToMany ) {↵ | |||
19 | ↵ | 18 | oldCollection, index++ );↵ | |
19 | // pre- and post- collection recreate events should be created when updating an entity with a "null" collection↵ | |||
20 | checkResult( listeners, listeners.getPreCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );↵ | 20 | checkResult( listeners, listeners.getPreCollectionRecreateListener(), parent, index++ );↵ | |
21 | checkResult( listeners, listeners.getPostCollectionRecreateListener(), ( ChildWithBidirectionalManyToMany ) newChild, index++ );↵ | 21 | checkResult( listeners, listeners.getPostCollectionRecreateListener(), parent, index++ );↵ | |
22 | }↵ | 22 | ↵ | |
23 | checkNumberOfResults( listeners, index ); | 23 |
| |
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.3 |
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 | 1 |
Number of unmapped statements in the second code fragment | 4 |
Time elapsed for statement mapping (ms) | 56.4 |
Clone type | Type 3 |
ID | Statement | ID | Statement | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | CollectionListeners listeners = new CollectionListeners(getSessions()); | 1 | CollectionListeners listeners = new CollectionListeners(getSessions()); | |||||||||||||||
2 | ParentWithCollection parent = createParentWithNoChildren("parent"); | 2 | ParentWithCollection parent = createParentWithNoChildren("parent"); | |||||||||||||||
3 | listeners.clear(); | 3 | listeners.clear(); | |||||||||||||||
4 | assertEquals(0, parent.getChildren().size()); | 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 oldCollection = parent.getChildren(); | |||||||||||||||
8 | Child newChild = parent.addChild("new"); |
| | |||||||||||||||
|
| 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++); | ||||||||||||||
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 Child newChild=parent.addChild("new"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | 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 |
4 | Expression parent.getChildren() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
5 | Expression oldCollection cannot be parameterized, because it has dependencies to/from statements that will be extracted |
6 | Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
7 | Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) cannot be parameterized, because it has dependencies to/from statements that will be extracted |
8 | Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,index++) is a void method call, and thus it cannot be parameterized |
9 | Expression checkResult(listeners,listeners.getInitializeCollectionListener(),parent,oldCollection,index++) is a void method call, and thus it cannot be parameterized |
10 | Unmatched statement checkResult(listeners,listeners.getPreCollectionRemoveListener(),parent,oldCollection,index++); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
11 | 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 |
12 | Expression listeners.getPreCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
13 | Expression listeners.getPreCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
14 | Expression listeners.getPostCollectionUpdateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
15 | Expression listeners.getPostCollectionRecreateListener() cannot be parameterized, because it has dependencies to/from statements that will be extracted |
16 | Clone fragment #1 returns variables parent, listeners, index , while Clone fragment #2 returns variables parent, listeners, index |