From c7e6caed43f6c678aa67ba327b97841e3fc5d4bf Mon Sep 17 00:00:00 2001 From: Aidan Follestad Date: Tue, 28 Feb 2017 21:44:57 -0600 Subject: [PATCH] Fixed build, added test coverage --- src/main/java/com/afollestad/ason/Util.java | 5 +++-- src/test/java/com/afollestad/ason/UtilTest.java | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/afollestad/ason/Util.java b/src/main/java/com/afollestad/ason/Util.java index 18065a8..8b4626b 100644 --- a/src/main/java/com/afollestad/ason/Util.java +++ b/src/main/java/com/afollestad/ason/Util.java @@ -218,8 +218,9 @@ static boolean isList(Class cls) { } static boolean shouldIgnore(Field field) { - return field.getName().startsWith("this$") || - field.getAnnotation(AsonIgnore.class) != null; + return field.getName().startsWith("this$") + || field.getName().equals("$jacocoData") // used with Jacoco testing + || field.getAnnotation(AsonIgnore.class) != null; } static String fieldName(Field field) { diff --git a/src/test/java/com/afollestad/ason/UtilTest.java b/src/test/java/com/afollestad/ason/UtilTest.java index aa1a43c..1a22b0b 100644 --- a/src/test/java/com/afollestad/ason/UtilTest.java +++ b/src/test/java/com/afollestad/ason/UtilTest.java @@ -13,7 +13,7 @@ /** * @author Aidan Follestad (afollestad) */ -public class UtilTest { +@SuppressWarnings("unused") public class UtilTest { @SuppressWarnings("unused") static class DefaultCtorClass { @@ -113,4 +113,14 @@ public class UtilTest { } catch (Throwable ignored) { } } + + @AsonIgnore Field ignoreYes1; + Field $jacocoData; + Field ignoreNo2; + + @Test public void test_should_ignore() throws Exception { + assertTrue(shouldIgnore(getClass().getDeclaredField("ignoreYes1"))); + assertTrue(shouldIgnore(getClass().getDeclaredField("$jacocoData"))); + assertFalse(shouldIgnore(getClass().getDeclaredField("ignoreNo2"))); + } }