@Test public void getFieldAsPropertiesToDisplayRefreshStateFalseParameter() throws MojoExecutionException { TerraformMojoStub terraformMojoStub = new TerraformMojoStub(); terraformMojoStub.refreshState = false; properties = terraformMojoStub.getFieldsAsProperties(); Assert.assertEquals(properties.get("refreshState"), false); }
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; }
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; } }
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; }  }
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; }   }
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; }    }