How to use assertNotNull method of org.assertj.core.internal.Classes class

Best Assertj code snippet using org.assertj.core.internal.Classes.assertNotNull

Source:Classes.java Github

copy

Full Screen

...57 * @throws AssertionError if {@code actual} is {@code null}.58 * @throws AssertionError if the actual {@code Class} is not assignable from all of the {@code others} classes.59 */60 public void assertIsAssignableFrom(AssertionInfo info, Class<?> actual, Class<?>... others) {61 assertNotNull(info, actual);62 if (others == null || others.length == 0)63 throw new IllegalArgumentException("Expecting at least one Class to be specified");64 Set<Class<?>> expected = newLinkedHashSet(others);65 Set<Class<?>> missing = new LinkedHashSet<>();66 for (Class<?> other : expected) {67 classParameterIsNotNull(other);68 if (!actual.isAssignableFrom(other)) missing.add(other);69 }70 if (!missing.isEmpty()) throw failures.failure(info, shouldBeAssignableFrom(actual, expected, missing));71 }72 /**73 * Verifies that the actual {@code Class} is not an interface.74 * 75 * @param info contains information about the assertion.76 * @param actual the "actual" {@code Class}.77 * @throws AssertionError if {@code actual} is {@code null}.78 * @throws AssertionError if the actual {@code Class} is an interface.79 */80 public void assertIsNotInterface(AssertionInfo info, Class<?> actual) {81 assertNotNull(info, actual);82 if (actual.isInterface()) throw failures.failure(info, shouldNotBeInterface(actual));83 }84 /**85 * Verifies that the actual {@code Class} is an interface.86 * 87 * @param info contains information about the assertion.88 * @param actual the "actual" {@code Class}.89 * @throws AssertionError if {@code actual} is {@code null}.90 * @throws AssertionError if the actual {@code Class} is not an interface.91 */92 public void assertIsInterface(AssertionInfo info, Class<?> actual) {93 assertNotNull(info, actual);94 if (!actual.isInterface()) throw failures.failure(info, shouldBeInterface(actual));95 }96 /**97 * Verifies that the actual {@code Class} is not an annotation.98 * 99 * @param info contains information about the assertion.100 * @param actual the "actual" {@code Class}.101 * @throws AssertionError if {@code actual} is {@code null}.102 * @throws AssertionError if the actual {@code Class} is an annotation.103 */104 public void assertIsNotAnnotation(AssertionInfo info, Class<?> actual) {105 assertNotNull(info, actual);106 if (actual.isAnnotation()) throw failures.failure(info, shouldNotBeAnnotation(actual));107 }108 /**109 * Verifies that the actual {@code Class} is an annotation.110 * 111 * @param info contains information about the assertion.112 * @param actual the "actual" {@code Class}.113 * @throws AssertionError if {@code actual} is {@code null}.114 * @throws AssertionError if the actual {@code Class} is not an annotation.115 */116 public void assertIsAnnotation(AssertionInfo info, Class<?> actual) {117 assertNotNull(info, actual);118 if (!actual.isAnnotation()) throw failures.failure(info, shouldBeAnnotation(actual));119 }120 /**121 * Verifies that the actual {@code Class} is final.122 *123 * @param info contains information about the assertion.124 * @param actual the "actual" {@code Class}.125 * @throws AssertionError if {@code actual} is {@code null}.126 * @throws AssertionError if the actual {@code Class} is not final.127 */128 public void assertIsFinal(AssertionInfo info, Class<?> actual) {129 assertNotNull(info, actual);130 if (!Modifier.isFinal(actual.getModifiers())) throw failures.failure(info, shouldBeFinal(actual));131 }132 /**133 * Verifies that the actual {@code Class} is not final.134 *135 * @param info contains information about the assertion.136 * @param actual the "actual" {@code Class}.137 * @throws AssertionError if {@code actual} is {@code null}.138 * @throws AssertionError if the actual {@code Class} is final.139 */140 public void assertIsNotFinal(AssertionInfo info, Class<?> actual) {141 assertNotNull(info, actual);142 if (Modifier.isFinal(actual.getModifiers())) throw failures.failure(info, shouldNotBeFinal(actual));143 }144 /**145 * Verifies that the actual {@code Class} contains the given {@code Annotation}s.146 * 147 * @param info contains information about the assertion.148 * @param actual the "actual" {@code Class}.149 * @param annotations annotations who must be attached to the class150 * @throws AssertionError if {@code actual} is {@code null}.151 * @throws AssertionError if the actual {@code Class} doesn't contains all of these annotations.152 */153 public void assertContainsAnnotations(AssertionInfo info, Class<?> actual,154 @SuppressWarnings("unchecked") Class<? extends Annotation>... annotations) {155 assertNotNull(info, actual);156 Set<Class<? extends Annotation>> expected = newLinkedHashSet(annotations);157 Set<Class<? extends Annotation>> missing = new LinkedHashSet<>();158 for (Class<? extends Annotation> other : expected) {159 classParameterIsNotNull(other);160 if (actual.getAnnotation(other) == null) missing.add(other);161 }162 if (!missing.isEmpty()) throw failures.failure(info, shouldHaveAnnotations(actual, expected, missing));163 }164 /**165 * Verifies that the actual {@code Class} has the {@code fields}.166 * 167 * @param info contains information about the assertion.168 * @param actual the "actual" {@code Class}.169 * @param fields the fields who must be present in the class.170 * @throws AssertionError if {@code actual} is {@code null}.171 * @throws AssertionError if the actual {@code Class} doesn't contains all of the field.172 */173 public void assertHasFields(AssertionInfo info, Class<?> actual, String... fields) {174 assertNotNull(info, actual);175 Set<String> expectedFieldNames = newLinkedHashSet(fields);176 Set<String> missingFieldNames = newLinkedHashSet();177 Set<String> actualFieldNames = fieldsToName(actual.getFields());178 if (noMissingFields(actualFieldNames, expectedFieldNames, missingFieldNames)) return;179 throw failures.failure(info, shouldHaveFields(actual, expectedFieldNames, missingFieldNames));180 }181 private static boolean noMissingFields(Set<String> actualFieldNames, Set<String> expectedFieldNames,182 Set<String> missingFieldNames) {183 for (String field : expectedFieldNames) {184 if (!actualFieldNames.contains(field)) missingFieldNames.add(field);185 }186 return missingFieldNames.isEmpty();187 }188 /**189 * Verifies that the actual {@code Class} has the declared {@code fields}.190 * 191 * @param info contains information about the assertion.192 * @param actual the "actual" {@code Class}.193 * @param fields the fields who must be declared in the class.194 * @throws AssertionError if {@code actual} is {@code null}.195 * @throws AssertionError if the actual {@code Class} doesn't contains all of the field.196 */197 public void assertHasDeclaredFields(AssertionInfo info, Class<?> actual, String... fields) {198 assertNotNull(info, actual);199 Set<String> expectedFieldNames = newLinkedHashSet(fields);200 Set<String> missingFieldNames = newLinkedHashSet();201 Set<String> actualFieldNames = fieldsToName(actual.getDeclaredFields());202 if (noMissingFields(actualFieldNames, expectedFieldNames, missingFieldNames)) return;203 throw failures.failure(info, shouldHaveDeclaredFields(actual, expectedFieldNames, missingFieldNames));204 }205 private static Set<String> fieldsToName(Field[] fields) {206 Set<String> fieldsName = new LinkedHashSet<>();207 for (Field field : fields) {208 fieldsName.add(field.getName());209 }210 return fieldsName;211 }212 private static void assertNotNull(AssertionInfo info, Class<?> actual) {213 Objects.instance().assertNotNull(info, actual);214 }215 /**216 * used to check that the class to compare is not null, in that case throws a {@link NullPointerException} with an217 * explicit message.218 * 219 * @param clazz the date to check220 * @throws NullPointerException with an explicit message if the given class is null221 */222 private static void classParameterIsNotNull(Class<?> clazz) {223 checkNotNull(clazz, "The class to compare actual with should not be null");224 }225}...

Full Screen

Full Screen

assertNotNull

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2import static org.assertj.core.api.Assertions.assertThat;3import static org.assertj.core.api.Assertions.assertThatThrownBy;4import static org.assertj.core.api.Assertions.catchThrowable;5import static org.assertj.core.api.Assertions.catchThrowableOfType;6import static org.assertj.core.api.Assertions.contentOf;7import static org.assertj.core.api.Assertions.entry;8import static org.assertj.core.api.Assertions.fail;9import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;10import static org.assertj.core.api.Assertions.filter;11import static org.assertj.core.api.Assertions.in;12import static org.assertj.core.api.Assertions.not;13import static org.assertj.core.api.Assertions.tuple;14import static org.assertj.core.api.Assertions.useDefaultDateFormatsOnly;15import static org.assertj.core.api.Assertions.within;16import static org.assertj.core.api.Assertions.withinPercentage;17import static org.assertj.core.api.Assertions.withinPrecision;18import static org.assertj.core.api.Assertions.withinTime;19import static org.assertj.core.api.Assertions.withinZone;20import static org.assertj.core.api.Assertions.withinZoneSameInstant;21import static org.assertj.core.api.Assertions.allOf;22import static org.assertj.core.api.Assertions.anyOf;23import static org.assertj.core.api.Assertions.describedAs;24import static org.assertj.core.api.Assertions.doesNotHave;25import static org.assertj.core.api.Assertions.has;26import static org.assertj.core.api.Assertions.hasEntry;27import static org.assertj.core.api.Assertions.hasKey;28import static org.assertj.core.api.Assertions.hasSize;29import static org.assertj.core.api.Assertions.hasValue;30import static org.assertj.core.api.Assertions.isEqualTo;31import static org.assertj.core.api.Assertions.isIn;32import static org.assertj.core.api.Assertions.isNotEqualTo;33import static org.assertj.core.api.Assertions.isNotIn;34import static org.assertj.core.api.Assertions.isNotNull;35import static org.assertj.core.api.Assertions.isNull;36import static org.assertj.core.api.Assertions.matchesPattern;37import static org.assertj.core.api.Assertions.notIn;38import static org.assertj.core.api.Assertions.notMatchesPattern;39import static org.assertj.core.api.Assertions.notNullValue;40import static org.assertj.core.api.Assertions.nullValue;41import static org.assertj.core.api.Assertions.startsWith;42import static org.assertj.core.api.Assertions.endsWith;43import static org.assertj.core.api.Assertions.contains;44import static org.assertj.core.api.Assertions.containsIgnoringCase;45import static org.assertj.core.api.Assertions.containsOnly;46import static org.assertj.core.api.Assertions.containsOnlyOnce;47import static org.assertj.core.api.Assertions.containsSequence;48import static org.assertj.core.api.Assertions.containsSubsequence;49import static org.assertj.core.api

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful