FamixMethod method = new FamixMethod("foo");
FamixClass declaredReturnedClass = new FamixClass("someClass");
method.setDeclaredReturnClass(declaredReturnedClass);
FamixLocalVariable lVar1 = new FamixLocalVariable("counter");
FamixLocalVariable lVar2 = new FamixLocalVariable("metricValue");
Set<FamixLocalVariable> lVars = new HashSet<FamixLocalVariable>();
lVars.add(lVar1);
lVars.add(lVar2);
method.setLocalVariables(lVars);
lVar1.setParent(method);
lVar2.setParent(method);
FamixClass anonymClass1 = new FamixClass("anonymClass1");
FamixClass anonymClass2 = new FamixClass("anonymClass2");
Set<FamixClass> anonyClasses = new HashSet<FamixClass>();
anonyClasses.add(anonymClass1);
anonyClasses.add(anonymClass2);
method.setAnonymClasses(anonyClasses);
anonymClass1.setParent(method);
anonymClass2.setParent(method);
FamixParameter fPar1 = new FamixParameter("parameter1");
FamixParameter fPar2 = new FamixParameter("parameter2");
List<FamixParameter> fPars = new ArrayList<FamixParameter>();
fPars.add(fPar1);
fPars.add(fPar2);
method.setParameters(fPars);
fPar1.setParent(method);
fPar2.setParent(method);
fEvolizerSession.startTransaction();
fEvolizerSession.saveObject(lVar1);
fEvolizerSession.saveObject(lVar2);
fEvolizerSession.saveObject(anonymClass1);
fEvolizerSession.saveObject(anonymClass2);
fEvolizerSession.saveObject(declaredReturnedClass);
fEvolizerSession.saveObject(fPar1);
fEvolizerSession.saveObject(fPar2);
fEvolizerSession.saveObject(method);
fEvolizerSession.endTransaction();
fEvolizerSession.close();
fEvolizerSession = fSessionHandler.getCurrentSession(fDBUrl);
List<FamixMethod> result = fEvolizerSession.query("from FamixMethod", FamixMethod.class);
assertEquals(1, result.size());
FamixMethod returnedFamixMethod = result.get(0);
assertEquals("foo", returnedFamixMethod.getUniqueName());
Set<FamixLocalVariable> returnedLVars = returnedFamixMethod.getLocalVariables();
assertEquals(2, returnedLVars.size());
for(Iterator<FamixLocalVariable> iter = returnedLVars.iterator();iter.hasNext();){
FamixLocalVariable var = iter.next();
assertTrue((var.getUniqueName().equals("counter") || var.getUniqueName().equals("metricValue")));
assertEquals("foo", var.getParent().getUniqueName());
assertTrue(returnedFamixMethod==var.getParent());
}
List<FamixParameter> returnedFormalPars = returnedFamixMethod.getParameters();
assertEquals(2, returnedFormalPars.size());
for(Iterator<FamixParameter> iter = returnedFamixMethod.getParameters().iterator();iter.hasNext();){