@Test
 public void test_toStringExcludeCollectionWithNull() {
   final List<String> excludeList = new ArrayList<String>();
   excludeList.add(null);
   final String toString =
       ReflectionToStringBuilder.toStringExclude(new TestFixture(), excludeList);
   this.validateSecretFieldPresent(toString);
 }
예제 #2
0
 /**
  * Uses <code>ReflectionToStringBuilder</code> to generate a <code>toString</code> for the
  * specified object.
  *
  * @param <T> the type of the object
  * @param object the Object to be output
  * @param style the style of the <code>toString</code> to create, may be <code>null</code>
  * @param outputTransients whether to include transient fields
  * @param reflectUpToClass the superclass to reflect up to (inclusive), may be <code>null</code>
  * @return the String result
  * @see ReflectionToStringBuilder#toString(Object,ToStringStyle,boolean,boolean,Class)
  * @since 2.0
  */
 public static <T> String reflectionToString(
     final T object,
     final ToStringStyle style,
     final boolean outputTransients,
     final Class<? super T> reflectUpToClass) {
   return ReflectionToStringBuilder.toString(
       object, style, outputTransients, false, reflectUpToClass);
 }
 @Test
 public void test_toStringExcludeCollection() {
   final List<String> excludeList = new ArrayList<String>();
   excludeList.add(SECRET_FIELD);
   final String toString =
       ReflectionToStringBuilder.toStringExclude(new TestFixture(), excludeList);
   this.validateSecretFieldAbsent(toString);
 }
 public static <T> String reflectionToString(
     T paramT,
     ToStringStyle paramToStringStyle,
     boolean paramBoolean,
     Class<? super T> paramClass) {
   return ReflectionToStringBuilder.toString(
       paramT, paramToStringStyle, paramBoolean, false, paramClass);
 }
  @Test
  public void test_toStringExclude() {
    final String toString = ReflectionToStringBuilder.toString(new TestFixture());

    assertThat(toString, not(containsString(EXCLUDED_FIELD_NAME)));
    assertThat(toString, not(containsString(EXCLUDED_FIELD_VALUE)));
    assertThat(toString, containsString(INCLUDED_FIELD_NAME));
    assertThat(toString, containsString(INCLUDED_FIELD_VALUE));
  }
예제 #6
0
 /**
  * Uses <code>ReflectionToStringBuilder</code> to generate a <code>toString</code> for the
  * specified object.
  *
  * @param object the Object to be output
  * @param style the style of the <code>toString</code> to create, may be <code>null</code>
  * @param outputTransients whether to include transient fields
  * @return the String result
  * @see ReflectionToStringBuilder#toString(Object,ToStringStyle,boolean)
  */
 public static String reflectionToString(
     Object object, ToStringStyle style, boolean outputTransients) {
   return ReflectionToStringBuilder.toString(object, style, outputTransients, false, null);
 }
예제 #7
0
 /**
  * Uses <code>ReflectionToStringBuilder</code> to generate a <code>toString</code> for the
  * specified object.
  *
  * @param object the Object to be output
  * @param style the style of the <code>toString</code> to create, may be <code>null</code>
  * @return the String result
  * @see ReflectionToStringBuilder#toString(Object,ToStringStyle)
  */
 public static String reflectionToString(Object object, ToStringStyle style) {
   return ReflectionToStringBuilder.toString(object, style);
 }
예제 #8
0
 /**
  * Uses <code>ReflectionToStringBuilder</code> to generate a <code>toString</code> for the
  * specified object.
  *
  * @param object the Object to be output
  * @return the String result
  * @see ReflectionToStringBuilder#toString(Object)
  */
 public static String reflectionToString(Object object) {
   return ReflectionToStringBuilder.toString(object);
 }
 @Test
 public void test_toStringExcludeArrayWithNulls() {
   final String toString =
       ReflectionToStringBuilder.toStringExclude(new TestFixture(), new String[] {null, null});
   this.validateSecretFieldPresent(toString);
 }
 public static String reflectionToString(Object paramObject, ToStringStyle paramToStringStyle) {
   return ReflectionToStringBuilder.toString(paramObject, paramToStringStyle);
 }
 @Test
 public void test_toStringExcludeNullCollection() {
   final String toString =
       ReflectionToStringBuilder.toStringExclude(new TestFixture(), (Collection<String>) null);
   this.validateSecretFieldPresent(toString);
 }
 @Test
 public void test_toStringExcludeEmptyCollection() {
   final String toString =
       ReflectionToStringBuilder.toStringExclude(new TestFixture(), new ArrayList<String>());
   this.validateSecretFieldPresent(toString);
 }
 @Test
 public void test_toStringExcludeEmptyArray() {
   final String toString =
       ReflectionToStringBuilder.toStringExclude(new TestFixture(), ArrayUtils.EMPTY_STRING_ARRAY);
   this.validateSecretFieldPresent(toString);
 }
 public static String reflectionToString(
     Object paramObject, ToStringStyle paramToStringStyle, boolean paramBoolean) {
   return ReflectionToStringBuilder.toString(
       paramObject, paramToStringStyle, paramBoolean, false, null);
 }
 @Test
 public void test_toStringExcludeArray() {
   final String toString =
       ReflectionToStringBuilder.toStringExclude(new TestFixture(), new String[] {SECRET_FIELD});
   this.validateSecretFieldAbsent(toString);
 }
예제 #16
0
 public static int reflectionCompare(Object obj, Object obj1, Collection collection) {
   return reflectionCompare(obj, obj1, ReflectionToStringBuilder.toNoNullStringArray(collection));
 }
예제 #17
0
 /**
  * This method uses reflection to determine if the two <code>Object</code>s are equal.
  *
  * <p>It uses <code>AccessibleObject.setAccessible</code> to gain access to private fields. This
  * means that it will throw a security exception if run under a security manager, if the
  * permissions are not set up correctly. It is also not as efficient as testing explicitly.
  *
  * <p>Transient members will be not be tested, as they are likely derived fields, and not part of
  * the value of the Object.
  *
  * <p>Static fields will not be tested. Superclass fields will be included.
  *
  * @param lhs <code>this</code> object
  * @param rhs the other object
  * @param excludeFields Collection of String field names to exclude from testing
  * @return <code>true</code> if the two Objects have tested equals.
  */
 public static boolean reflectionEquals(Object lhs, Object rhs, Collection<String> excludeFields) {
   return reflectionEquals(lhs, rhs, ReflectionToStringBuilder.toNoNullStringArray(excludeFields));
 }