Best Assertj code snippet using org.assertj.core.api.AbstractMapAssert.doesNotContainKey
Source:DocumentAssert.java
...45 * <pre>46 * <code>47 * Document document = Document.parse("{ $set: { concreteInnerList: [ { foo: "bar", _class: ⦠}] } }");48 *49 * assertThat(mappedUpdate).containsKey("$set.concreteInnerList.[0].foo").doesNotContainKey("$set.concreteInnerList.[0].bar");50 * </code>51 * </pre>52 *53 * @author Mark Paluch54 */55public class DocumentAssert extends AbstractMapAssert<DocumentAssert, Map<String, Object>, String, Object> {56 private final Document actual;57 DocumentAssert(Document actual) {58 super(actual, DocumentAssert.class);59 this.actual = actual;60 }61 /*62 * (non-Javadoc)63 * @see org.assertj.core.api.AbstractMapAssert#containsEntry(java.lang.Object, java.lang.Object)64 */65 @Override66 public DocumentAssert containsEntry(String key, Object value) {67 Assert.hasText(key, "The key to look for must not be empty!");68 Lookup<?> lookup = lookup(key);69 if (!lookup.isPathFound() || !ObjectUtils.nullSafeEquals(value, lookup.getValue())) {70 throw Failures.instance().failure(info, AssertErrors.shouldHaveProperty(actual, key, value));71 }72 return myself;73 }74 /*75 * (non-Javadoc)76 * @see org.assertj.core.api.AbstractMapAssert#doesNotContainEntry(java.lang.Object, java.lang.Object)77 */78 @Override79 public DocumentAssert doesNotContainEntry(String key, Object value) {80 Assert.hasText(key, "The key to look for must not be empty!");81 Lookup<?> lookup = lookup(key);82 if (lookup.isPathFound() && ObjectUtils.nullSafeEquals(value, lookup.getValue())) {83 throw Failures.instance().failure(info, AssertErrors.shouldNotHaveProperty(actual, key, value));84 }85 return myself;86 }87 /*88 * (non-Javadoc)89 * @see org.assertj.core.api.AbstractMapAssert#containsKey(java.lang.Object)90 */91 @Override92 public DocumentAssert containsKey(String key) {93 return containsKeys(key);94 }95 /*96 * (non-Javadoc)97 * @see org.assertj.core.api.AbstractMapAssert#containsKeys(java.lang.Object[])98 */99 @Override100 public final DocumentAssert containsKeys(String... keys) {101 Set<String> notFound = new LinkedHashSet<>();102 for (String key : keys) {103 if (!lookup(key).isPathFound()) {104 notFound.add(key);105 }106 }107 if (!notFound.isEmpty()) {108 throw Failures.instance().failure(info, shouldContainKeys(actual, notFound));109 }110 return myself;111 }112 /*113 * (non-Javadoc)114 * @see org.assertj.core.api.AbstractMapAssert#doesNotContainKey(java.lang.Object)115 */116 @Override117 public DocumentAssert doesNotContainKey(String key) {118 return doesNotContainKeys(key);119 }120 /*121 * (non-Javadoc)122 * @see org.assertj.core.api.AbstractMapAssert#doesNotContainKeys(java.lang.Object[])123 */124 @Override125 public final DocumentAssert doesNotContainKeys(String... keys) {126 Set<String> found = new LinkedHashSet<>();127 for (String key : keys) {128 if (lookup(key).isPathFound()) {129 found.add(key);130 }131 }132 if (!found.isEmpty()) {133 throw Failures.instance().failure(info, shouldNotContainKeys(actual, found));134 }135 return myself;136 }137 // override methods to annotate them with @SafeVarargs, we unfortunately can't do that in AbstractMapAssert as it is138 // used in soft assertions which need to be able to proxy method - @SafeVarargs requiring method to be final prevents139 // using proxies....
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!