Skip to content

Commit

Permalink
Modificators processing in AssembleModelGenerator and UtBotFieldModif…
Browse files Browse the repository at this point in the history
…icatorsSearcher corrected (UnitTestBot#1029)

* Improve modificators analysis in UtBotFieldModificatorsSearcher and AssembleModelGenerator

* Apply review comments

* Fixed test

* One more correction for package names
  • Loading branch information
EgorkaKulikov authored and AbdullinAM committed Oct 17, 2022
1 parent a5d628c commit ba08cb7
Show file tree
Hide file tree
Showing 35 changed files with 104 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.arrays;
package org.utbot.examples.assemble;

/**
* A class with array of objects that are arrays of complex fields themselves.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.arrays;
package org.utbot.examples.assemble;

/**
* A class with a two-dimensional array field.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.arrays;
package org.utbot.examples.assemble;

/**
* A class with an array with a default value.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.arrays;
package org.utbot.examples.assemble;

import org.utbot.examples.assemble.PrimitiveFields;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.constructors;
package org.utbot.examples.assemble;

/**
* A class without default constructor and with complex one.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.constructors;
package org.utbot.examples.assemble;

/**
* A class without default constructor and with complex one,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.constructors;
package org.utbot.examples.assemble;

public class ConstructorModifyingStatic {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.defaults;
package org.utbot.examples.assemble;

/**
* A class with a field with default value that is not a default value of type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.utbot.examples.assemble.defaults;
package org.utbot.examples.assemble;

public class DefaultFieldModifiedInConstructor {
int z;
public int z;

@SuppressWarnings("Unused")
DefaultFieldModifiedInConstructor(int z_) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.defaults;
package org.utbot.examples.assemble;

/**
* A class with a field with default value that is not a default value of type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.defaults;
package org.utbot.examples.assemble;

/**
* A class with a field with setter default value that is not a default value of type.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.utbot.examples.assemble;

/**
* Need to be located at the same package as [AssembleTestUtils]
* because requires a setter for package-private field.
*/
public class DefaultPackagePrivateField {
int z = 10;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.constructors;
package org.utbot.examples.assemble;

/**
* A class with a primitive constructor that inherits a complex constructor.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.constructors;
package org.utbot.examples.assemble;

/**
* A class with a primitive constructor that inherits another primitive constructor.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.arrays;
package org.utbot.examples.assemble;

/**
* A class with an array with elements of primitive type.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.constructors;
package org.utbot.examples.assemble;

/**
* A class without default constructor and with primitive one.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.constructors;
package org.utbot.examples.assemble;

/**
* A class without default constructor and with another one with default field
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.constructors;
package org.utbot.examples.assemble;

/**
* A class with private constructor.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.constructors;
package org.utbot.examples.assemble;

/**
* A class with a constructor that seems to be complex
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.statics;
package org.utbot.examples.assemble;

/**
* A class with primitive constructor and static field
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.utbot.examples.assemble.arrays;
package org.utbot.examples.assemble.another;

/**
* A test class with fake method under test.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.manual.examples;

import org.utbot.examples.assemble.arrays.ArrayOfComplexArrays;
import org.utbot.examples.assemble.ArrayOfComplexArrays;

public class ArrayOfComplexArraysExample {
public int getValue(ArrayOfComplexArrays a) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.manual.examples;

import org.utbot.examples.assemble.arrays.ArrayOfPrimitiveArrays;
import org.utbot.examples.assemble.ArrayOfPrimitiveArrays;

public class ArrayOfPrimitiveArraysExample {
int assign10(ArrayOfPrimitiveArrays a) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.utbot.examples.manual.examples;

import org.utbot.examples.assemble.arrays.AssignedArray;
import org.utbot.examples.assemble.AssignedArray;

public class AssignedArrayExample {
public void foo(AssignedArray aa) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import org.utbot.common.PathUtil;
import org.utbot.examples.assemble.DirectAccess;
import org.utbot.examples.assemble.PrimitiveFields;
import org.utbot.examples.assemble.arrays.ArrayOfComplexArrays;
import org.utbot.examples.assemble.arrays.ArrayOfPrimitiveArrays;
import org.utbot.examples.assemble.arrays.AssignedArray;
import org.utbot.examples.assemble.arrays.ComplexArray;
import org.utbot.examples.assemble.ArrayOfComplexArrays;
import org.utbot.examples.assemble.ArrayOfPrimitiveArrays;
import org.utbot.examples.assemble.AssignedArray;
import org.utbot.examples.assemble.ComplexArray;
import org.utbot.examples.manual.examples.*;
import org.utbot.examples.manual.examples.customer.B;
import org.utbot.examples.manual.examples.customer.C;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ import org.utbot.examples.assemble.ListItem
import org.utbot.examples.assemble.NoModifier
import org.utbot.examples.assemble.PackagePrivateFields
import org.utbot.examples.assemble.PrimitiveFields
import org.utbot.examples.assemble.arrays.ArrayOfComplexArrays
import org.utbot.examples.assemble.arrays.ArrayOfPrimitiveArrays
import org.utbot.examples.assemble.arrays.AssignedArray
import org.utbot.examples.assemble.arrays.ComplexArray
import org.utbot.examples.assemble.arrays.MethodUnderTest
import org.utbot.examples.assemble.arrays.PrimitiveArray
import org.utbot.examples.assemble.constructors.ComplexConstructor
import org.utbot.examples.assemble.constructors.ComplexConstructorWithSetter
import org.utbot.examples.assemble.constructors.ConstructorModifyingStatic
import org.utbot.examples.assemble.constructors.InheritComplexConstructor
import org.utbot.examples.assemble.constructors.InheritPrimitiveConstructor
import org.utbot.examples.assemble.constructors.PrimitiveConstructor
import org.utbot.examples.assemble.constructors.PrimitiveConstructorWithDefaultField
import org.utbot.examples.assemble.constructors.PrivateConstructor
import org.utbot.examples.assemble.constructors.PseudoComplexConstructor
import org.utbot.examples.assemble.defaults.DefaultField
import org.utbot.examples.assemble.defaults.DefaultFieldModifiedInConstructor
import org.utbot.examples.assemble.defaults.DefaultFieldWithDirectAccessor
import org.utbot.examples.assemble.defaults.DefaultFieldWithSetter
import org.utbot.examples.assemble.defaults.DefaultPackagePrivateField
import org.utbot.examples.assemble.statics.StaticField
import org.utbot.examples.assemble.ArrayOfComplexArrays
import org.utbot.examples.assemble.ArrayOfPrimitiveArrays
import org.utbot.examples.assemble.AssignedArray
import org.utbot.examples.assemble.ComplexArray
import org.utbot.examples.assemble.another.MethodUnderTest
import org.utbot.examples.assemble.PrimitiveArray
import org.utbot.examples.assemble.ComplexConstructor
import org.utbot.examples.assemble.ComplexConstructorWithSetter
import org.utbot.examples.assemble.ConstructorModifyingStatic
import org.utbot.examples.assemble.InheritComplexConstructor
import org.utbot.examples.assemble.InheritPrimitiveConstructor
import org.utbot.examples.assemble.PrimitiveConstructor
import org.utbot.examples.assemble.PrimitiveConstructorWithDefaultField
import org.utbot.examples.assemble.PrivateConstructor
import org.utbot.examples.assemble.PseudoComplexConstructor
import org.utbot.examples.assemble.DefaultField
import org.utbot.examples.assemble.DefaultFieldModifiedInConstructor
import org.utbot.examples.assemble.DefaultFieldWithDirectAccessor
import org.utbot.examples.assemble.DefaultFieldWithSetter
import org.utbot.examples.assemble.DefaultPackagePrivateField
import org.utbot.examples.assemble.StaticField
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.ExecutableId
import org.utbot.framework.plugin.api.FieldId
Expand All @@ -58,7 +58,6 @@ import org.utbot.framework.util.SootUtils
import org.utbot.framework.util.instanceCounter
import org.utbot.framework.util.modelIdCounter
import kotlin.reflect.full.functions
import org.utbot.examples.assemble.*
import org.utbot.framework.codegen.model.constructor.util.arrayTypeOf

/**
Expand Down Expand Up @@ -150,8 +149,7 @@ class AssembleModelGeneratorTests {
fields(testClassId, "a" to 5, "b" to 3)
)

val methodFromAnotherPackage =
MethodUnderTest::class.functions.first()
val methodFromAnotherPackage = MethodUnderTest::class.functions.first()

createModelAndAssert(compositeModel, null, methodFromAnotherPackage.executableId)
}
Expand Down Expand Up @@ -413,7 +411,7 @@ class AssembleModelGeneratorTests {
val baseClassId = PrimitiveFields::class.id

val thisFields = fields(inheritedFieldClassId, "i" to 5, "d" to 3.0)
val baseFields = fields(baseClassId, "a" to 2, "b" to 4)
val baseFields = fields(baseClassId, "b" to 4)

val compositeModel = UtCompositeModel(
modelIdCounter.incrementAndGet(),
Expand All @@ -425,7 +423,6 @@ class AssembleModelGeneratorTests {
val v1 = statementsChain.addExpectedVariableDecl<InheritedField>()
statementsChain.add("$v1." + ("i" `=` 5))
statementsChain.add("$v1." + ("d" `=` 3.0))
statementsChain.add("$v1." + addExpectedSetter("a", 2))
statementsChain.add("$v1." + ("b" `=` 4))

val expectedRepresentation = printExpectedModel(inheritedFieldClassId.simpleName, v1, statementsChain)
Expand Down Expand Up @@ -1448,9 +1445,9 @@ class AssembleModelGeneratorTests {
private fun createModelsAndAssert(
models: List<UtModel>,
expectedModelRepresentations: List<String?>,
assembleTestUtils: ExecutableId = AssembleTestUtils::class.id.allMethods.first(),
assembleTestDummyMethod: ExecutableId = AssembleTestUtils::class.id.allMethods.first(),
) {
val modelsMap = AssembleModelGenerator(assembleTestUtils.classId.packageName).createAssembleModels(models)
val modelsMap = AssembleModelGenerator(assembleTestDummyMethod.classId.packageName).createAssembleModels(models)
//we sort values to fix order of models somehow (IdentityHashMap does not guarantee the order)
val assembleModels = modelsMap.values
.filterIsInstance<UtAssembleModel>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ internal class UtBotFieldModificatorsTest {

//We use sorting here to make comparing with sorted in advance expected collections easier
private fun runFieldModificatorsSearch(analysisMode: AnalysisMode) =
fieldsModificatorsSearcher.findModificators(analysisMode, PrimitiveModifications::class.java.packageName)
fieldsModificatorsSearcher.findModificators(analysisMode)
.map { (key, value) ->
val modificatorNames = value.filterNot { it.name.startsWith("direct_set_") }.map { it.name }
key.name to modificatorNames.toSortedSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.utbot.framework.plugin.api.UtArrayModel
import org.utbot.framework.plugin.api.UtClassRefModel
import org.utbot.framework.plugin.api.UtCompositeModel
import org.utbot.framework.plugin.api.UtModel
import org.utbot.framework.plugin.api.util.executableId
import org.utbot.framework.plugin.api.util.id
import java.lang.reflect.Field
import java.lang.reflect.Method
Expand Down
Loading

0 comments on commit ba08cb7

Please sign in to comment.