Skip to content

Commit

Permalink
Fix is collection object log (#927)
Browse files Browse the repository at this point in the history
* fix: isCollection

* test: update test

* fix: check when it is not empty and not in isCollection

* test: update test with new expected properties
  • Loading branch information
danglotb authored Nov 27, 2019
1 parent b1511eb commit 29a5ead
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
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

0 comments on commit 29a5ead

Please sign in to comment.