Skip to content
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

Fix is collection object log #927

Merged
merged 4 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ public static boolean isNonEmptyPrimitiveCollectionOrMap(Object collectionOrMap)
}

public static boolean isCollection(Object object) {
return Collection.class.isInstance(object);
return Collection.class.isInstance(object);// && ;
}

public static boolean isNonEmptyPrimitiveCollection(Object object) {
if (isCollection(object) && !((Collection) object).isEmpty()) {
if (!object.getClass().getName().startsWith("java.util")) {
//System.out.println(object.getClass().getName() + " is a custom implementation of collection, skipping...");
return false;
}
Collection collection = (Collection) object;
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
Expand Down
Binary file modified dspot/src/main/resources/compare/objectlog/ObjectLogUtils.class
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.Test;

import java.io.File;
import java.io.Serializable;
import java.util.*;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -38,6 +39,9 @@ private static class MyInternalClass {
public MyInternalClass(int a, int b) {
this.a = a;
this.b = b;
this.myList = new MyList();
this.myList.add("toto");
this.myList.add("tata");
}

public List<Integer> getObject() {
Expand Down Expand Up @@ -67,6 +71,13 @@ public Iterable<String> getIterable() {
public Collection<String> getCollection() {
return Collections.singleton("");
}
public static class MyList extends ArrayList implements Serializable {
public int aValue = 23;
}
public MyList myList;
public MyList getMyList() {
return this.myList;
}
}

public static Integer add(Integer a, Integer b) {
Expand All @@ -88,7 +99,7 @@ public void test() throws Exception {
assertNotNull(add__0);
// assertEquals(1, add__0.getNotDeterministValues().size());
final Map<String, Object> observationValues = add__0.getObservationValues();
assertEquals(5, observationValues.size());
assertEquals(6, observationValues.size());
// assertEquals(25, observationValues.get("(myInternalClass ).compute()"));
assertEquals(3, observationValues.get("(myInternalClass ).getA()"));
assertEquals(20, observationValues.get("(myInternalClass ).getB()"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@
*/
public class ObjectLogUtilsTest {

public class MyList extends ArrayList {

}

@Test//TODO empty collection / map are considered as primitive, we may need to found a semantic of the method.
public void testIsPrimitiveCollectionOrMap() throws Exception {

MyList mylist = new MyList();
mylist.add("");
assertFalse(ObjectLogUtils.isNonEmptyPrimitiveCollectionOrMap(mylist));

final ArrayList<Integer> list = new ArrayList<>();
assertFalse(ObjectLogUtils.isNonEmptyPrimitiveCollectionOrMap(list));
list.add(1);
Expand All @@ -32,6 +41,7 @@ public void testIsPrimitiveCollectionOrMap() throws Exception {
assertTrue(ObjectLogUtils.isNonEmptyPrimitiveCollectionOrMap(set));

assertFalse(ObjectLogUtils.isNonEmptyPrimitiveCollectionOrMap(1));

}

@Test
Expand Down