001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.junit.bct; 018 019/** 020 * Functional interface for computing the size of objects in test assertions. 021 * 022 * <p> 023 * Sizers are used by {@link BeanConverter#size(Object)} to determine the size of collection-like 024 * objects when validating test assertions. This provides a flexible way to compute sizes for custom 025 * types without needing to convert them to lists first. 026 * 027 * <h5 class='section'>Usage Example:</h5> 028 * <p class='bjava'> 029 * <jc>// Register a sizer for a custom collection type</jc> 030 * <jk>var</jk> <jv>converter</jv> = BasicBeanConverter.<jsm>builder</jsm>() 031 * .defaultSettings() 032 * .addSizer(MyCustomCollection.<jk>class</jk>, (<jp>coll</jp>, <jp>conv</jp>) -> <jp>coll</jp>.count()) 033 * .build(); 034 * 035 * <jc>// Use in assertions</jc> 036 * <jk>int</jk> <jv>size</jv> = <jv>converter</jv>.size(<jv>myCustomCollection</jv>); 037 * </p> 038 * 039 * <h5 class='section'>See Also:</h5> 040 * <ul class='seealso'> 041 * <li class='jic'>{@link BeanConverter} 042 * </ul> 043 * 044 * @param <T> The type of object this sizer handles. 045 */ 046@FunctionalInterface 047public interface Sizer<T> { 048 049 /** 050 * Computes the size of the given object. 051 * 052 * @param o The object to compute the size of. Will not be <jk>null</jk>. 053 * @param bc The bean converter for accessing additional conversion utilities if needed. 054 * @return The size of the object. 055 */ 056 int size(T o, BeanConverter bc); 057}