001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.test.json; 018 019import java.util.Map; 020 021import org.assertj.core.api.AbstractMapAssert; 022import org.assertj.core.api.AbstractObjectArrayAssert; 023import org.assertj.core.api.AbstractObjectAssert; 024import org.assertj.core.api.Assert; 025import org.assertj.core.api.Assertions; 026import org.assertj.core.internal.Objects; 027 028/** 029 * AssertJ {@link Assert} for {@link ObjectContent}. 030 * 031 * @param <A> the actual type 032 * @author Phillip Webb 033 * @since 1.4.0 034 */ 035public class ObjectContentAssert<A> 036 extends AbstractObjectAssert<ObjectContentAssert<A>, A> { 037 038 protected ObjectContentAssert(A actual) { 039 super(actual, ObjectContentAssert.class); 040 } 041 042 /** 043 * Verifies that the actual value is an array, and returns an array assertion, to 044 * allow chaining of array-specific assertions from this call. 045 * @return an array assertion object 046 */ 047 public AbstractObjectArrayAssert<?, Object> asArray() { 048 Objects.instance().assertIsInstanceOf(this.info, this.actual, Object[].class); 049 return Assertions.assertThat((Object[]) this.actual); 050 } 051 052 /** 053 * Verifies that the actual value is a map, and returns a map assertion, to allow 054 * chaining of map-specific assertions from this call. 055 * @return a map assertion object 056 */ 057 @SuppressWarnings("unchecked") 058 public AbstractMapAssert<?, ?, Object, Object> asMap() { 059 Objects.instance().assertIsInstanceOf(this.info, this.actual, Map.class); 060 return Assertions.assertThat((Map<Object, Object>) this.actual); 061 } 062 063}