How to use isPrimitiveOrWrapper method of org.assertj.core.util.introspection.ClassUtils class

Best Assertj code snippet using org.assertj.core.util.introspection.ClassUtils.isPrimitiveOrWrapper

Source:RecursiveAssertionDriver.java Github

copy

Full Screen

...20import static org.assertj.core.api.recursive.comparison.FieldLocation.rootFieldLocation;21import static org.assertj.core.util.Lists.list;22import static org.assertj.core.util.Sets.newHashSet;23import static org.assertj.core.util.introspection.ClassUtils.isOptionalOrPrimitiveOptional;24import static org.assertj.core.util.introspection.ClassUtils.isPrimitiveOrWrapper;25import java.util.Collection;26import java.util.List;27import java.util.Map;28import java.util.Optional;29import java.util.OptionalDouble;30import java.util.OptionalInt;31import java.util.OptionalLong;32import java.util.Set;33import java.util.function.Predicate;34import org.assertj.core.api.recursive.comparison.FieldLocation;35import org.assertj.core.util.Arrays;36public class RecursiveAssertionDriver {37 private static final String NULL = "null";38 private static final String INDEX_FORMAT = "[%d]";39 private static final String KEY_FORMAT = "KEY[%s]";40 private static final String VALUE_FORMAT = "VAL[%s]";41 private final Set<String> visitedNodeIds = newHashSet();42 private final List<FieldLocation> fieldsFailingTheAssertion = list();43 private final RecursiveAssertionConfiguration configuration;44 public RecursiveAssertionDriver(RecursiveAssertionConfiguration configuration) {45 this.configuration = configuration;46 }47 public List<FieldLocation> assertOverObjectGraph(Predicate<Object> predicate, Object graphNode) {48 assertRecursively(predicate, graphNode, graphNode.getClass(), rootFieldLocation());49 return fieldsFailingTheAssertion.stream().sorted().collect(toList());50 }51 public void reset() {52 visitedNodeIds.clear();53 fieldsFailingTheAssertion.clear();54 }55 private void assertRecursively(Predicate<Object> predicate, Object node, Class<?> nodeType, FieldLocation fieldLocation) {56 if (nodeMustBeIgnored(node, nodeType, fieldLocation)) return;57 boolean nodeAlreadyVisited = markNodeAsVisited(node);58 if (nodeAlreadyVisited) return;59 if (!isRootObject(fieldLocation) && shouldEvaluateAssertion(nodeType)) {60 evaluateAssertion(predicate, node, fieldLocation);61 }62 recurseIntoFieldsOfCurrentNode(predicate, node, nodeType, fieldLocation);63 }64 private boolean nodeMustBeIgnored(Object node, Class<?> nodeType, FieldLocation fieldLocation) {65 return isNullWhichAreIgnored(node)66 || isPrimitiveWhichAreIgnored(nodeType)67 || configuration.matchesAnIgnoredField(fieldLocation)68 || configuration.matchesAnIgnoredFieldRegex(fieldLocation)69 || configuration.getIgnoredTypes().contains(nodeType);70 }71 private boolean isRootObject(FieldLocation fieldLocation) {72 return fieldLocation.equals(rootFieldLocation());73 }74 private boolean isNullWhichAreIgnored(Object node) {75 return node == null && configuration.shouldIgnoreAllNullFields();76 }77 private boolean isPrimitiveWhichAreIgnored(Class<?> nodeType) {78 return configuration.shouldIgnorePrimitiveFields() && isPrimitiveOrWrapper(nodeType);79 }80 private void evaluateAssertion(Predicate<Object> predicate, Object node, FieldLocation fieldLocation) {81 if (assertionFails(predicate, node)) {82 fieldsFailingTheAssertion.add(fieldLocation);83 }84 }85 private boolean assertionFails(Predicate<Object> predicate, Object node) {86 return !predicate.test(node);87 }88 private boolean shouldEvaluateAssertion(Class<?> nodeType) {89 boolean ignoreContainerAssertion = configuration.shouldIgnoreContainer() && isContainer(nodeType);90 boolean ignoreMapAssertion = configuration.shouldIgnoreMap() && isMap(nodeType);91 boolean ignoreOptionalAssertion = configuration.shouldIgnoreOptional() && isOptionalOrPrimitiveOptional(nodeType);92 return !(ignoreContainerAssertion || ignoreMapAssertion || ignoreOptionalAssertion);...

Full Screen

Full Screen

Source:ClassUtils.java Github

copy

Full Screen

...97 * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte},98 * {@link Character}, {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}, {@link Void}).99 * @since 3.24.0100 */101 public static boolean isPrimitiveOrWrapper(final Class<?> type) {102 if (type == null) {103 return false;104 }105 return type.isPrimitive() || PRIMITIVE_WRAPPER_TYPES.contains(type);106 }107 /**108 * Returns whether the given {@code type} is a primitive or primitive wrapper ({@link Optional}, {@link OptionalInt},109 * {@link OptionalLong}, {@link OptionalDouble}).110 * <p>111 * Returns false if passed null since the method can't evaluate the class.112 *113 * @param type The class to query or null.114 * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Optional}, {@link OptionalInt},115 * {@link OptionalLong}, {@link OptionalDouble})....

Full Screen

Full Screen

Source:ClassUtils_isPrimitiveOrWrapper_Test.java Github

copy

Full Screen

...11 * Copyright 2012-2022 the original author or authors.12 */13package org.assertj.core.util.introspection;14import static org.assertj.core.api.BDDAssertions.then;15import static org.assertj.core.util.introspection.ClassUtils.isPrimitiveOrWrapper;16import java.util.List;17import java.util.Optional;18import java.util.concurrent.atomic.AtomicInteger;19import java.util.stream.Stream;20import org.junit.jupiter.params.ParameterizedTest;21import org.junit.jupiter.params.provider.MethodSource;22class ClassUtils_isPrimitiveOrWrapper_Test {23 @ParameterizedTest24 @MethodSource25 void isPrimitiveOrWrapper_should_detect_primitive_types_and_their_corresponding_wrapper(Class<?> clazz) {26 // WHEN27 boolean isPrimitive = isPrimitiveOrWrapper(clazz);28 // THEN29 then(isPrimitive).isTrue();30 }31 @ParameterizedTest32 @MethodSource33 void should_detect_as_not_primitive_types_or_their_corresponding_wrapper(Class<?> clazz) {34 // WHEN35 boolean isPrimitive = isPrimitiveOrWrapper(clazz);36 // THEN37 then(isPrimitive).isFalse();38 }39 private static Stream<Class<?>> isPrimitiveOrWrapper_should_detect_primitive_types_and_their_corresponding_wrapper() {40 return Stream.of(Boolean.class, Byte.class, Character.class, Short.class, Integer.class, Long.class, Double.class,41 Float.class, Void.class, Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE,42 Double.TYPE, Float.TYPE, Void.TYPE);43 }44 private static Stream<Class<?>> should_detect_as_not_primitive_types_or_their_corresponding_wrapper() {45 return Stream.of(Optional.class, String.class, List.class, AtomicInteger.class);46 }47}...

Full Screen

Full Screen

isPrimitiveOrWrapper

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.util.introspection.ClassUtils;2public class Main {3 public static void main(String[] args) {4 System.out.println(ClassUtils.isPrimitiveOrWrapper(int.class));5 System.out.println(ClassUtils.isPrimitiveOrWrapper(Integer.class));6 System.out.println(ClassUtils.isPrimitiveOrWrapper(String.class));7 }8}9import org.assertj.core.util.introspection.ClassUtil;10public class Main {11 public static void main(String[] args) {12 System.out.println(ClassUtil.isPrimitiveOrWrapper(int.class));13 System.out.println(ClassUtil.isPrimitiveOrWrapper(Integer.class));14 System.out.println(ClassUtil.isPrimitiveOrWrapper(String.class));15 }16}17import org.assertj.core.util.introspection.ClassUtil;18public class Main {19 public static void main(String[] args) {20 System.out.println(ClassUtil.isPrimitiveOrWrapper(int.class));21 System.out.println(ClassUtil.isPrimitiveOrWrapper(Integer.class));22 System.out.println(ClassUtil.isPrimitiveOrWrapper(String.class));23 }24}25import org.assertj.core.util.introspection.ClassUtil;26public class Main {27 public static void main(String[] args) {28 System.out.println(ClassUtil.isPrimitiveOrWrapper(int.class));29 System.out.println(ClassUtil.isPrimitiveOrWrapper(Integer.class));30 System.out.println(ClassUtil.isPrimitiveOrWrapper(String.class));31 }32}33import org.assertj.core.util.introspection.ClassUtil;34public class Main {35 public static void main(String[] args) {36 System.out.println(ClassUtil.isPrimitiveOrWrapper(int.class));37 System.out.println(ClassUtil.isPrimitiveOrWrapper(Integer.class));38 System.out.println(ClassUtil.isPrimitiveOrWrapper(String.class));39 }40}

Full Screen

Full Screen

isPrimitiveOrWrapper

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.util.introspection;2import static org.assertj.core.api.Assertions.assertThat;3import org.junit.Test;4public class ClassUtils_isPrimitiveOrWrapper_Test {5 public void should_return_true_if_given_class_is_primitive_or_wrapper() {6 assertThat(ClassUtils.isPrimitiveOrWrapper(boolean.class)).isTrue();7 assertThat(ClassUtils.isPrimitiveOrWrapper(Boolean.class)).isTrue();8 assertThat(ClassUtils.isPrimitiveOrWrapper(byte.class)).isTrue();9 assertThat(ClassUtils.isPrimitiveOrWrapper(Byte.class)).isTrue();10 assertThat(ClassUtils.isPrimitiveOrWrapper(char.class)).isTrue();11 assertThat(ClassUtils.isPrimitiveOrWrapper(Character.class)).isTrue();12 assertThat(ClassUtils.isPrimitiveOrWrapper(double.class)).isTrue();13 assertThat(ClassUtils.isPrimitiveOrWrapper(Double.class)).isTrue();14 assertThat(ClassUtils.isPrimitiveOrWrapper(float.class)).isTrue();15 assertThat(ClassUtils.isPrimitiveOrWrapper(Float.class)).isTrue();16 assertThat(ClassUtils.isPrimitiveOrWrapper(int.class)).isTrue();17 assertThat(ClassUtils.isPrimitiveOrWrapper(Integer.class)).isTrue();18 assertThat(ClassUtils.isPrimitiveOrWrapper(long.class)).isTrue();19 assertThat(ClassUtils.isPrimitiveOrWrapper(Long.class)).isTrue();20 assertThat(ClassUtils.isPrimitiveOrWrapper(short.class)).isTrue();21 assertThat(ClassUtils.isPrimitiveOrWrapper(Short.class)).isTrue();22 }23 public void should_return_false_if_given_class_is_not_primitive_or_wrapper() {24 assertThat(ClassUtils.isPrimitiveOrWrapper(Object.class)).isFalse();25 assertThat(ClassUtils.isPrimitiveOrWrapper(String.class)).isFalse();26 assertThat(ClassUtils.isPrimitiveOrWrapper(ClassUtils_isPrimitiveOrWrapper_Test.class)).isFalse();27 }28 public void should_return_false_if_given_class_is_null() {29 assertThat(ClassUtils.isPrimitiveOrWrapper(null)).isFalse();30 }31}32package org.assertj.core.util.introspection;33import static org.assertj.core.util.introspection.ClassUtils.isPrimitiveOrWrapper;34import org.junit.Test;35public class ClassUtils_isPrimitiveOrWrapper_Test {36 public void should_return_true_if_given_class_is_primitive_or_wrapper() {37 assertThat(isPrimitiveOrWrapper(boolean.class)).isTrue();38 assertThat(isPrimitiveOrWrapper(Boolean.class)).isTrue();39 assertThat(isPrimitiveOrWrapper(byte.class)).isTrue();40 assertThat(isPrimitiveOrWrapper(Byte.class)).isTrue();

Full Screen

Full Screen

isPrimitiveOrWrapper

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.util.introspection.ClassUtils;2public class 1 {3 public static void main(String[] args) {4 System.out.println(ClassUtils.isPrimitiveOrWrapper(String.class));5 }6}7public static boolean isPrimitiveOrWrapper(Class<?> clazz) {

Full Screen

Full Screen

isPrimitiveOrWrapper

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.util.introspection.ClassUtils;2import java.lang.reflect.Array;3public class MyClass {4 public static void main(String[] args) {5 Class<?>[] classes = new Class<?>[] {int.class, Integer.class, String.class, MyClass.class, Array.class};6 for (Class<?> clazz : classes) {7 System.out.println(clazz + " is primitive or wrapper: " + ClassUtils.isPrimitiveOrWrapper(clazz));8 }9 }10}11class [Ljava.lang.Object; is primitive or wrapper: false

Full Screen

Full Screen

isPrimitiveOrWrapper

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.util.introspection.ClassUtils;2import java.lang.reflect.Field;3import java.util.ArrayList;4import java.util.List;5import java.util.Map;6import java.util.Set;7public class MyClass {8 public static void main(String[] args) throws Exception {9 List<String> list = new ArrayList<>();10 list.add("Hello");11 list.add("World");12 list.add("Welcome");13 list.add("To");14 list.add("Java");15 Set<String> set = Set.of("Hello", "World", "Welcome", "To", "Java");16 Map<String, String> map = Map.of("Hello", "World", "Welcome", "To", "Java");17 System.out.println("List is primitive or wrapper: " + isPrimitiveOrWrapper(list));18 System.out.println("Set is primitive or wrapper: " + isPrimitiveOrWrapper(set));19 System.out.println("Map is primitive or wrapper: " + isPrimitiveOrWrapper(map));20 }21 public static boolean isPrimitiveOrWrapper(Object obj) throws Exception {22 if (obj == null) {23 return false;24 }25 if (obj instanceof Class) {26 return ClassUtils.isPrimitiveOrWrapper((Class<?>) obj);27 }28 Field typeField = obj.getClass().getDeclaredField("type");29 typeField.setAccessible(true);30 return ClassUtils.isPrimitiveOrWrapper((Class<?>) typeField.get(obj));31 }32}

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.

Run Assertj automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful