### Question:
TerraformMojo extends AbstractMojo { protected final Properties getFieldsAsProperties() throws MojoExecutionException { Class clazz = this.getClass(); List<Field> fieldList = Arrays.stream(clazz.getDeclaredFields()) .collect(Collectors.toList()); Properties properties = new Properties(); for (Field field : fieldList) { try { field.setAccessible(true); Object fieldVal = field.get(this); if (fieldVal == null || (fieldVal.equals(false) && !field.getName().startsWith("refresh")) || (Number.class.isAssignableFrom(fieldVal.getClass()) && ((Number)fieldVal).longValue() <= 0)) { continue; } if (field.getName().equalsIgnoreCase("tfvars")) { fieldVal = getTFvars(fieldVal); } properties.put(field.getName(), fieldVal); } catch (NullPointerException npe) { } catch (IllegalAccessException iae) { throw new MojoExecutionException("Unable to access " + field.getName() + " from Mojo!", iae); } catch (JsonProcessingException jpe) { throw new MojoExecutionException("Unable to convert " + field.getName() + " to json", jpe); } } return properties; }    }### Answer:
@Test public void getFieldAsPropertiesGetsOnlyTheSetSubclassFieldsAsProperties() throws MojoExecutionException { TerraformMojoStub terraformMojoStub = new TerraformMojoStub(); terraformMojoStub.boolProp = true; terraformMojoStub.intProp = 22; terraformMojoStub.longProp = 1000; terraformMojoStub.stringProp = "Hello"; properties = terraformMojoStub.getFieldsAsProperties(); Assert.assertEquals(properties.size(), 5); Assert.assertEquals(properties.get("boolProp"), true); Assert.assertEquals(properties.get("intProp"), 22); Assert.assertEquals(properties.get("longProp"), 1000L); Assert.assertEquals(properties.get("stringProp"), "Hello"); terraformMojoStub.boolProp = false; terraformMojoStub.intProp = 0; terraformMojoStub.longProp = 0; properties = terraformMojoStub.getFieldsAsProperties(); Assert.assertEquals(properties.size(), 2); Assert.assertEquals(properties.get("stringProp"), "Hello"); }
@Test public void getFieldAsPropertiesToDisplayRefreshStateFalseParameter() throws MojoExecutionException { TerraformMojoStub terraformMojoStub = new TerraformMojoStub(); terraformMojoStub.refreshState = false; properties = terraformMojoStub.getFieldsAsProperties(); Assert.assertEquals(properties.get("refreshState"), false); }