GeezerVison is showing github.com — ToString support for abstract collection using makeSymbolic #391 by CaelmBleidd · Pull Request #402 · UnitTestBot/UTBotJava
ToString support for abstract collection using makeSymbolic #391
#402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.java
(5)
.kt
(4)
All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
@@ -0,0 +1,13 @@
package org.utbot.engine.overrides.collections;
import org.utbot.api.annotation.UtClassMock;
import static org.utbot.api.mock.UtMock.makeSymbolic;
@UtClassMock(target = java.util.AbstractCollection.class, internalUsage = true)
public abstract class AbstractCollection<E> implements java.util.Collection<E> {
@Override
public String toString() {
return makeSymbolic();
}
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -19,9 +19,9 @@
import org.utbot.engine.overrides.stream.UtStream;
import static org.utbot.api.mock.UtMock.assume;
import static org.utbot.api.mock.UtMock.assumeOrExecuteConcretely;
import static org.utbot.engine.ResolverKt.MAX_LIST_SIZE;
import static org.utbot.engine.overrides.UtOverrideMock.alreadyVisited;
import static org.utbot.api.mock.UtMock.assumeOrExecuteConcretely;
import static org.utbot.engine.overrides.UtOverrideMock.executeConcretely;
import static org.utbot.engine.overrides.UtOverrideMock.parameter;
import static org.utbot.engine.overrides.UtOverrideMock.visit;
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -15,9 +15,9 @@
import org.jetbrains.annotations.Nullable;
import static org.utbot.api.mock.UtMock.assume;
import static org.utbot.api.mock.UtMock.makeSymbolic;
import static org.utbot.engine.overrides.UtOverrideMock.alreadyVisited;
import static org.utbot.engine.overrides.UtOverrideMock.doesntThrow;
import static org.utbot.engine.overrides.UtOverrideMock.executeConcretely;
import static org.utbot.engine.overrides.UtOverrideMock.parameter;
import static org.utbot.engine.overrides.UtOverrideMock.visit;
Expand Down
Expand Up
@@ -556,8 +556,7 @@ public final boolean remove(Object o) {
// TODO rewrite it JIRA:1604
@Override
public String toString() {
executeConcretely();
return super.toString();
return makeSymbolic();
}
public final class Entry implements Map.Entry<K, V> {
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,9 @@
package org.utbot.engine.overrides.stream;
import org.utbot.api.annotation.UtClassMock;
import org.utbot.engine.overrides.collections.UtArrayList;
import java.util.List;
import java.util.stream.Stream;
@UtClassMock(target = java.util.Arrays.class, internalUsage = true)
Expand All
@@ -16,5 +18,12 @@ public static <T> Stream<T> stream(T[] array, int startInclusive, int endExclusi
return new UtStream<>(array, startInclusive, endExclusive);
}
@SuppressWarnings({"unused", "varargs"})
@SafeVarargs
public static <T> List<T> asList(T... a) {
// TODO immutable collection https://github.com/UnitTestBot/UTBotJava/issues/398
return new UtArrayList<>(a);
}
// TODO primitive arrays https://github.com/UnitTestBot/UTBotJava/issues/146
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -83,16 +83,23 @@ abstract class BaseOverriddenWrapper(protected val overriddenClassName: String)
return listOf(GraphResult(method.jimpleBody().graph()))
}
val overriddenMethod = overriddenClass.findMethodOrNull(method.subSignature)
if (overriddenMethod == null) {
// We need to find either an override from the class (for example, implementation
// of the method from the wrapper) or a method from its ancestors.
// Note that the method from the ancestor might have substitutions as well.
// I.e., it is `toString` method for `UtArrayList` that is defined in
// `AbstractCollection` and has its own overridden implementation.
val overriddenMethod = overriddenClass
.findMethodOrNull(method.subSignature)
?.let { typeRegistry.findSubstitutionOrNull(it) ?: it }
return if (overriddenMethod == null) {
// No overridden method has been found, switch to concrete execution
pathLogger.warn("Method ${overriddenClass.name}::${method.subSignature} not found, executing concretely")
return emptyList()
emptyList()
} else {
val jimpleBody = overriddenMethod.jimpleBody()
val graphResult = GraphResult(jimpleBody.graph())
return listOf(graphResult)
listOf(graphResult)
}
}
}
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -2536,7 +2536,8 @@ class UtBotSymbolicEngine(
if (methodSignature != makeSymbolicMethod.signature && methodSignature != nonNullableMakeSymbolic.signature) return null
val method = environment.method
val isInternalMock = method.hasInternalMockAnnotation || method.declaringClass.allMethodsAreInternalMocks
val declaringClass = method.declaringClass
val isInternalMock = method.hasInternalMockAnnotation || declaringClass.allMethodsAreInternalMocks || declaringClass.isOverridden
val parameters = resolveParameters(invokeExpr.args, invokeExpr.method.parameterTypes)
val mockMethodResult = mockStaticMethod(invokeExpr.method, parameters)?.single()
?: error("Unsuccessful mock attempt of the `makeSymbolic` method call: $invokeExpr")
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -32,6 +32,8 @@ import org.utbot.engine.overrides.collections.UtOptional
import org.utbot.engine.overrides.collections.UtOptionalDouble
import org.utbot.engine.overrides.collections.UtOptionalInt
import org.utbot.engine.overrides.collections.UtOptionalLong
import org.utbot.engine.overrides.collections.AbstractCollection
import org.utbot.engine.overrides.stream.Arrays
import org.utbot.engine.overrides.stream.Stream
import org.utbot.engine.overrides.stream.UtStream
import java.io.File
Expand Down
Expand Up
@@ -91,6 +93,7 @@ private fun addBasicClasses(vararg classes: KClass<*>) {
}
private val classesToLoad = arrayOf(
AbstractCollection::class,
UtMock::class,
UtOverrideMock::class,
UtLogicMock::class,
Expand Down
Expand Up
@@ -133,6 +136,7 @@ private val classesToLoad = arrayOf(
UtStringBuilder::class,
UtStringBuffer::class,
Stream::class,
Arrays::class,
Collection::class,
List::class,
UtStream::class,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -589,4 +589,14 @@ internal class StringExamplesTest : AbstractTestCaseGeneratorTest(
)
}
}
@Test
fun testListToString() {
check(
StringExamples::listToString,
eq(1),
{ r -> r == "[a, b, c]"},
coverage = DoNotCalculate
)
}
}
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
package org.utbot.examples.strings;
import java.util.Arrays;
import static java.lang.Boolean.valueOf;
class IntPair {
Expand Down
Expand Up
@@ -411,4 +413,8 @@ public String equalsIgnoreCase(String s) {
return "failure";
}
}
public String listToString() {
return Arrays.asList("a", "b", "c").toString();
}
}
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.