All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.assertj.assertions.generator.description.FieldDescription Maven / Gradle / Ivy

/**
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 * Copyright 2012-2015 the original author or authors.
 */
package org.assertj.assertions.generator.description;

import static org.apache.commons.lang3.StringUtils.capitalize;


/**
 * Stores the information needed to generate an assertion for a public field.
 * 

* Let's say we have the following method in class Person : * *

 * public int age
 * 
*

* To generate PersonAssert hasAge(int expectedAge) assertion in PersonAssert, we * need to know : *

    *
  • the field name, here "age"
  • *
  • the field type
  • *
* This class is immutable. * * @author Joel Costigliola */ public class FieldDescription extends DataDescription implements Comparable { public FieldDescription(String name, TypeDescription typeDescription) { super(name, name, typeDescription); } @Override public int compareTo(FieldDescription other) { return getName().compareTo(other.getName()); } @Override public String toString() { return "FieldDescription[name=" + getName() + ", typeDescription=" + typeDescription + "]"; } @Override public boolean isPredicate() { return typeDescription.isBoolean(); } @Override public String getPredicate() { final String retval = super.getNegativePredicate(); return retval == null ? "is" + capitalize(originalMember) : originalMember; } @Override public String getNegativePredicate() { final String retval = super.getNegativePredicate(); return retval == null ? "isNot" + capitalize(originalMember) : retval; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy