@@ -357,7 +357,10 @@ class AssembleModelGenerator(private val methodUnderTest: UtMethod<*>) {
357
357
/* *
358
358
* Finds most appropriate constructor in class.
359
359
*
360
- * We prefer constructor that allows to set more fields than others
360
+ * If the [compositeModel].fields is empty, we don't care about affected fields, we would like to take an empty
361
+ * constructor or an appropriate constructor with the least number of arguments.
362
+ *
363
+ * Otherwise, we prefer constructor that allows to set more fields than others
361
364
* and use only simple assignments like "this.a = a".
362
365
*
363
366
* Returns null if no one appropriate constructor is found.
@@ -366,11 +369,19 @@ class AssembleModelGenerator(private val methodUnderTest: UtMethod<*>) {
366
369
val classId = compositeModel.classId
367
370
if (! classId.isVisible || classId.isInner) return null
368
371
369
- return classId.jClass.declaredConstructors
372
+ val constructorIds = classId.jClass.declaredConstructors
370
373
.filter { it.isVisible }
371
- .sortedByDescending { it.parameterCount }
372
374
.map { it.executableId }
373
- .firstOrNull { constructorAnalyzer.isAppropriate(it) }
375
+
376
+ return if (compositeModel.fields.isEmpty()) {
377
+ constructorIds
378
+ .sortedBy { it.parameters.size }
379
+ .firstOrNull { it.parameters.isEmpty() || constructorAnalyzer.isAppropriate(it) }
380
+ } else {
381
+ constructorIds
382
+ .sortedByDescending { it.parameters.size }
383
+ .firstOrNull { constructorAnalyzer.isAppropriate(it) }
384
+ }
374
385
}
375
386
376
387
private val ClassId .isVisible : Boolean
0 commit comments