package jetbrains.mps.testRead.SNodeReadTest; /*Generated by MPS */ import jetbrains.mps.MPSLaunch; import jetbrains.mps.lang.test.runtime.BaseTransformationTest; import org.junit.Test; import jetbrains.mps.lang.test.runtime.BaseTestBody; import java.util.Set; import java.util.List; import jetbrains.mps.util.CollectionUtil; import junit.framework.Assert; import org.jetbrains.mps.openapi.model.SNode; import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations; import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory; import jetbrains.mps.smodel.NodeReadAccessCasterInEditor; import java.util.Map; import java.util.HashMap; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.lang.reflect.Modifier; import jetbrains.mps.util.Pair; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.beans.XMLDecoder; import java.util.HashSet; @MPSLaunch public class SNodeReadAccess_Test extends BaseTransformationTest { @Test public void test_checkContract() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_checkContract", true); } @Test public void test_addChild() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_addChild", true); } @Test public void test_getChildren() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_getChildren", true); } @Test public void test_getProperty() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_getProperty", true); } @Test public void test_getReference() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_getReference", true); } @Test public void test_getReferenceTarget() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_getReferenceTarget", true); } @Test public void test_getUserObject() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_getUserObject", true); } @Test public void test_hasProperty() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_hasProperty", true); } @Test public void test_insertChildBefore() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_insertChildBefore", true); } @Test public void test_putUserObject() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_putUserObject", true); } @Test public void test_removeChild() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_removeChild", true); } @Test public void test_setProperty() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_setProperty", true); } @Test public void test_setReference() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_setReference", true); } @Test public void test_setReferenceTarget() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_setReferenceTarget", true); } @Test public void test_parameterLessMethods() throws Throwable { initTest("${mps_home}", "r:ee85802d-3f17-4cb5-b08b-75e01c861019(jetbrains.mps.testRead.SNodeReadTest@tests)", false); runTest("jetbrains.mps.testRead.SNodeReadTest.SNodeReadAccess_Test$TestBody", "test_parameterLessMethods", true); } @MPSLaunch public static class TestBody extends BaseTestBody { public void test_checkContract() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); Set<String> savedMethods = this.getPreviousISNodeMethodsNames(); Set<String> currentMethods = this.getISNodeMethodsNames(true); List<String> newContract = CollectionUtil.subtract(currentMethods, savedMethods); List<String> deletedContract = CollectionUtil.subtract(savedMethods, currentMethods); StringBuilder error; error = new StringBuilder("Contract for SNode changed!"); error.append(System.getProperty("line.separator")); error.append("New methods in SNode:"); error.append(System.getProperty("line.separator")); for (String s : newContract) { error.append(s); error.append(System.getProperty("line.separator")); } error.append(System.getProperty("line.separator")); error.append("Deleted methods in SNode:"); error.append(System.getProperty("line.separator")); for (String s : deletedContract) { error.append(s); error.append(System.getProperty("line.separator")); } Assert.assertTrue(error.toString(), newContract.isEmpty() && deletedContract.isEmpty()); } public void test_addChild() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("8150353254540236424"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfc092b6b77L, "BlockStatement"))); SNode child = SNodeOperations.cast(getNodeById("8150353254540236551"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc67c7f0L, "LocalVariableDeclarationStatement"))); child.getParent().removeChild(child); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.addChild("", child); this.assertMethod("public void jetbrains.mps.smodel.SNode.addChild(java.lang.String,org.jetbrains.mps.openapi.model.SNode)", listener.getResults().o1); } public void test_getChildren() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("8150353254540236424"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfc092b6b77L, "BlockStatement"))); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.getChildren(MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfc092b6b77L, 0xfc092b6b78L, "statements")); this.assertMethod("public java.util.List<jetbrains.mps.smodel.SNode> jetbrains.mps.smodel.SNode.getChildren(java.lang.String)", listener.getResults().o1); } public void test_getProperty() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("4195712261513743413"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b217L, "IfStatement"))); sNode.setProperty(MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b217L, 0x3dffcc410476e370L, "forceOneLine"), "true"); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.getProperty(MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b217L, 0x3dffcc410476e370L, "forceOneLine")); this.assertMethod("public final java.lang.String jetbrains.mps.smodel.SNode.getProperty(java.lang.String)", listener.getResults().o1); } public void test_getReference() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("4265636116363098320"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8c77f1e98L, "VariableReference"))); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.getReference(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c77f1e98L, 0xf8cc6bf960L, "variableDeclaration")); this.assertMethod("public jetbrains.mps.smodel.SReference jetbrains.mps.smodel.SNode.getReference(java.lang.String)", listener.getResults().o1); } public void test_getReferenceTarget() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("4265636116363098320"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8c77f1e98L, "VariableReference"))); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.getReferenceTarget(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c77f1e98L, 0xf8cc6bf960L, "variableDeclaration")); this.assertMethod("public org.jetbrains.mps.openapi.model.SNode jetbrains.mps.smodel.SNode.getReferenceTarget(java.lang.String)", listener.getResults().o1); } public void test_getUserObject() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("8150353254540236424"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfc092b6b77L, "BlockStatement"))); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.getUserObject(null); this.assertMethod("public java.lang.Object jetbrains.mps.smodel.SNode.getUserObject(java.lang.Object)", listener.getResults().o1); } public void test_hasProperty() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("4195712261513743413"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b217L, "IfStatement"))); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.hasProperty(MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b217L, 0x3dffcc410476e370L, "forceOneLine")); this.assertMethod("public final boolean jetbrains.mps.smodel.SNode.hasProperty(java.lang.String)", listener.getResults().o1); } public void test_insertChildBefore() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("8150353254540236424"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfc092b6b77L, "BlockStatement"))); SNode child = SNodeOperations.cast(getNodeById("8150353254540236551"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc67c7f0L, "LocalVariableDeclarationStatement"))); child.getParent().removeChild(child); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.insertChildBefore(MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfc092b6b77L, 0xfc092b6b78L, "statements"), child, null); this.assertMethod("public void jetbrains.mps.smodel.SNode.insertChildBefore(java.lang.String,org.jetbrains.mps.openapi.model.SNode,org.jetbrains.mps.openapi.model.SNode)", listener.getResults().o1); } public void test_putUserObject() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("8150353254540236424"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfc092b6b77L, "BlockStatement"))); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.putUserObject("test", "test"); this.assertMethod("public void jetbrains.mps.smodel.SNode.putUserObject(java.lang.Object,java.lang.Object)", listener.getResults().o1); } public void test_removeChild() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("8150353254540236424"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfc092b6b77L, "BlockStatement"))); SNode child = SNodeOperations.cast(getNodeById("8150353254540236551"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc67c7f0L, "LocalVariableDeclarationStatement"))); child.getParent().removeChild(child); sNode.addChild(MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xfc092b6b77L, 0xfc092b6b78L, "statements"), child); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.removeChild(child); this.assertMethod("public void jetbrains.mps.smodel.SNode.removeChild(org.jetbrains.mps.openapi.model.SNode)", listener.getResults().o1); } public void test_setProperty() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("4195712261513743413"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc56b217L, "IfStatement"))); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.setProperty(MetaAdapterFactory.getProperty(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b217L, 0x3dffcc410476e370L, "forceOneLine"), "true"); this.assertMethod("public void jetbrains.mps.smodel.SNode.setProperty(java.lang.String,java.lang.String)", listener.getResults().o1); } public void test_setReference() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("4265636116363098320"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8c77f1e98L, "VariableReference"))); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.setReference(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c77f1e98L, 0xf8cc6bf960L, "variableDeclaration"), SNodeOperations.getReference(SNodeOperations.cast(getNodeById("4265636116363098320"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8c77f1e98L, "VariableReference"))), MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c77f1e98L, 0xf8cc6bf960L, "variableDeclaration"))); this.assertMethod("public void jetbrains.mps.smodel.SNode.setReference(java.lang.String,org.jetbrains.mps.openapi.model.SReference)", listener.getResults().o1); } public void test_setReferenceTarget() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("4265636116363098320"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8c77f1e98L, "VariableReference"))); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); sNode.setReferenceTarget(MetaAdapterFactory.getReferenceLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c77f1e98L, 0xf8cc6bf960L, "variableDeclaration"), SNodeOperations.cast(getNodeById("4195712261513781527"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xf8cc67c7efL, "LocalVariableDeclaration")))); this.assertMethod("public void jetbrains.mps.smodel.SNode.setReferenceTarget(java.lang.String,org.jetbrains.mps.openapi.model.SNode)", listener.getResults().o1); } public void test_parameterLessMethods() throws Exception { addNodeById("8150353254540236423"); addNodeById("8150353254540236549"); addNodeById("4195712261513743410"); SNode sNode = SNodeOperations.cast(getNodeById("8150353254540236424"), SNodeOperations.asSConcept(MetaAdapterFactory.getConcept(MetaAdapterFactory.getLanguage(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, "jetbrains.mps.baseLanguage"), 0xfc092b6b77L, "BlockStatement"))); StatCountNodeReadAccessInEditorListener listener = new StatCountNodeReadAccessInEditorListener(sNode); NodeReadAccessCasterInEditor.setCellBuildNodeReadAccessListener(listener); Map<String, Integer> prevCheck = this.getReadAccessMap(); Map<String, Integer> currentCheckChanged = new HashMap<String, Integer>(); Map<String, Integer> currentCheckNew = new HashMap<String, Integer>(); Map<String, Exception> currentException = new HashMap<String, Exception>(); Set<String> contractMethods = this.getISNodeMethodsNames(false); List<Method> methods = new ArrayList<Method>(); methods.addAll(Arrays.asList(jetbrains.mps.smodel.SNode.class.getDeclaredMethods())); // 'delete' must be last checked method for (int i = 0; i < methods.size(); i++) { if (methods.get(i).getName().equals("delete") && i != (methods.size() - 1)) { Collections.swap(methods, i, (methods.size() - 1)); break; } } for (Method method : methods) { if ((method.getModifiers() & (Modifier.PUBLIC | Modifier.PROTECTED)) > 0 && method.getParameterAnnotations().length == 0 && contractMethods.contains(method.getName())) { try { method.invoke(sNode); } catch (Exception e) { currentException.put(method.getName(), e); } finally { Pair<Integer, List<String>> pair = listener.getResults(); listener.resetResults(); if (prevCheck.containsKey(method.toGenericString())) { if (!(this.isReadsCountUnChanged(prevCheck.get(method.toGenericString()).intValue(), pair.o1.intValue()))) { currentCheckChanged.put(method.toGenericString(), pair.o1); } } else { currentCheckNew.put(method.toGenericString(), pair.o1); } } } } StringBuilder error = new StringBuilder("Some changes occured in read access in SNode after last check:"); error.append(System.getProperty("line.separator")); error.append("Methods with changed number of read access:"); error.append(System.getProperty("line.separator")); for (String s : currentCheckChanged.keySet()) { error.append("In method " + s + " current count " + currentCheckChanged.get(s) + ", prev count " + prevCheck.get(s)); error.append(System.getProperty("line.separator")); } error.append(System.getProperty("line.separator")); error.append("New methods with read access:"); error.append(System.getProperty("line.separator")); for (String s : currentCheckNew.keySet()) { error.append("In method " + s + " read count " + currentCheckNew.get(s)); error.append(System.getProperty("line.separator")); } error.append(System.getProperty("line.separator")); error.append("Methods ended with exception:"); error.append(System.getProperty("line.separator")); for (String s : currentException.keySet()) { Exception ce = currentException.get(s); error.append("There was an exception in method " + s + "\n"); for (StackTraceElement elem : ce.getStackTrace()) { error.append(elem + "\n"); } error.append(System.getProperty("line.separator")); } Assert.assertTrue(error.toString(), currentCheckChanged.isEmpty() && currentCheckNew.isEmpty() && currentException.isEmpty()); } public Map<String, Integer> getReadAccessMap() throws FileNotFoundException, IOException { InputStream stream = ((Object) this).getClass().getResourceAsStream("/SNodeMethodReads.xml"); XMLDecoder xmlDecoder = new XMLDecoder(stream); Map<String, Integer> map = (Map<String, Integer>) xmlDecoder.readObject(); stream.close(); return map; } public Set<String> getPreviousISNodeMethodsNames() throws FileNotFoundException, IOException { InputStream stream = ((Object) this).getClass().getResourceAsStream("/SNodeContract.xml"); XMLDecoder xmlDecoder = new XMLDecoder(stream); Set<String> set = (Set<String>) xmlDecoder.readObject(); xmlDecoder.close(); stream.close(); return set; } public Set<String> getISNodeMethodsNames(boolean fullQualified) throws FileNotFoundException, IOException { Set<String> set = new HashSet<String>(); for (Method method : SNode.class.getMethods()) { set.add((fullQualified ? method.toGenericString() : method.getName())); } return set; } public void assertMethod(String fullyQualifiedMethodName, int reads) throws FileNotFoundException, IOException { Map<String, Integer> map = this.getReadAccessMap(); Assert.assertTrue("Can't find method '" + fullyQualifiedMethodName + "' in previous check!", map.containsKey(fullyQualifiedMethodName)); Assert.assertTrue("In method " + fullyQualifiedMethodName + " current count " + reads + ", prev count " + map.get(fullyQualifiedMethodName).intValue(), this.isReadsCountUnChanged(map.get(fullyQualifiedMethodName).intValue(), reads)); } public boolean isReadsCountUnChanged(int previous, int current) { // just check that reads doesn't appear or disappear quietly return (previous == 0 ? current == 0 : current > 0); } } }