public class PersistentBagTest extends FunctionalTestCase { public PersistentBagTest(String name) { super( name ); } public String[] getMappings() { return new String[] { "collection/bag/Mappings.hbm.xml" }; } public static Test suite() { return new FunctionalTestClassTestSuite( PersistentBagTest.class ); } public void testWriteMethodDirtying() { BagOwner parent = new BagOwner( "root" ); BagOwner child = new BagOwner( "c1" ); parent.getChildren().add( child ); child.setParent( parent ); BagOwner otherChild = new BagOwner( "c2" ); Session session = openSession(); session.beginTransaction(); session.save( parent ); session.flush(); // at this point, the list on parent has now been replaced with a PersistentBag... PersistentBag children = ( PersistentBag ) parent.getChildren(); assertFalse( children.remove( otherChild ) ); assertFalse( children.isDirty() ); ArrayList otherCollection = new ArrayList(); otherCollection.add( child ); assertFalse( children.retainAll( otherCollection ) ); assertFalse( children.isDirty() ); otherCollection = new ArrayList(); otherCollection.add( otherChild ); assertFalse( children.removeAll( otherCollection ) ); assertFalse( children.isDirty() ); children.clear(); session.delete( child ); assertTrue( children.isDirty() ); session.flush(); children.clear(); assertFalse( children.isDirty() ); session.delete( parent ); session.getTransaction().commit(); session.close();
public class PersistentListTest extends FunctionalTestCase { public PersistentListTest(String name) { super( name ); } public String[] getMappings() { return new String[] { "collection/list/Mappings.hbm.xml" }; } public static Test suite() { return new FunctionalTestClassTestSuite( PersistentListTest.class ); } public void testWriteMethodDirtying() { ListOwner parent = new ListOwner( "root" ); ListOwner child = new ListOwner( "c1" ); parent.getChildren().add( child ); child.setParent( parent ); ListOwner otherChild = new ListOwner( "c2" ); Session session = openSession(); session.beginTransaction(); session.save( parent ); session.flush(); // at this point, the list on parent has now been replaced with a PersistentList... PersistentList children = ( PersistentList ) parent.getChildren(); assertFalse( children.remove( otherChild ) ); assertFalse( children.isDirty() ); ArrayList otherCollection = new ArrayList(); otherCollection.add( child ); assertFalse( children.retainAll( otherCollection ) ); assertFalse( children.isDirty() ); otherCollection = new ArrayList(); otherCollection.add( otherChild ); assertFalse( children.removeAll( otherCollection ) ); assertFalse( children.isDirty() ); children.clear(); session.delete( child ); assertTrue( children.isDirty() ); session.flush(); children.clear(); assertFalse( children.isDirty() ); session.delete( parent ); session.getTransaction().commit(); session.close();
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/collection/bag/PersistentBagTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/java/org/hibernate/test/collection/list/PersistentListTest.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public class PersistentBagTest extends FunctionalTestCase {
1
public class PersistentListTest extends FunctionalTestCase {
2
	public PersistentBagTest(String name) {
2
	public PersistentListTest(String name) {
3
		super( name );
3
		super( name );
4
	}
4
	}
5
	public String[] getMappings() {
5
	public String[] getMappings() {
6
		return new String[] { "collection/bag/Mappings.hbm.xml" };
6
		return new String[] { "collection/list/Mappings.hbm.xml" };
7
	}
7
	}
8
	public static Test suite() {
8
	public static Test suite() {
9
		return new FunctionalTestClassTestSuite( PersistentBagTest.class );
9
		return new FunctionalTestClassTestSuite( PersistentListTest.class );
10
	}
10
	}
11
	public void testWriteMethodDirtying() {
11
	public void testWriteMethodDirtying() {
12
		BagOwner parent = new BagOwner( "root" );
12
		ListOwner parent = new ListOwner( "root" );
13
		BagOwner child = new BagOwner( "c1" );
13
		ListOwner child = new ListOwner( "c1" );
14
		parent.getChildren().add( child );
14
		parent.getChildren().add( child );
15
		child.setParent( parent );
15
		child.setParent( parent );
16
		BagOwner otherChild = new BagOwner( "c2" );
16
		ListOwner otherChild = new ListOwner( "c2" );
17
		Session session = openSession();
17
		Session session = openSession();
18
		session.beginTransaction();
18
		session.beginTransaction();
19
		session.save( parent );
19
		session.save( parent );
20
		session.flush();
20
		session.flush();
21
		// at this point, the list on parent has now been replaced with a PersistentBag...
21
		// at this point, the list on parent has now been replaced with a PersistentList...
22
		PersistentBag children = ( PersistentBag ) parent.getChildren();
22
		PersistentList children = ( PersistentList ) parent.getChildren();
23
		assertFalse( children.remove( otherChild ) );
23
		assertFalse( children.remove( otherChild ) );
24
		assertFalse( children.isDirty() );
24
		assertFalse( children.isDirty() );
25
		ArrayList otherCollection = new ArrayList();
25
		ArrayList otherCollection = new ArrayList();
26
		otherCollection.add( child );
26
		otherCollection.add( child );
27
		assertFalse( children.retainAll( otherCollection ) );
27
		assertFalse( children.retainAll( otherCollection ) );
28
		assertFalse( children.isDirty() );
28
		assertFalse( children.isDirty() );
29
		otherCollection = new ArrayList();
29
		otherCollection = new ArrayList();
30
		otherCollection.add( otherChild );
30
		otherCollection.add( otherChild );
31
		assertFalse( children.removeAll( otherCollection ) );
31
		assertFalse( children.removeAll( otherCollection ) );
32
		assertFalse( children.isDirty() );
32
		assertFalse( children.isDirty() );
33
		children.clear();
33
		children.clear();
34
		session.delete( child );
34
		session.delete( child );
35
		assertTrue( children.isDirty() );
35
		assertTrue( children.isDirty() );
36
		session.flush();
36
		session.flush();
37
		children.clear();
37
		children.clear();
38
		assertFalse( children.isDirty() );
38
		assertFalse( children.isDirty() );
39
		session.delete( parent );
39
		session.delete( parent );
40
		session.getTransaction().commit();
40
		session.getTransaction().commit();
41
		session.close();
41
		session.close();
42
	
42
	
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0