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.bct.assertions; 018 019import java.io.*; 020import java.nio.charset.*; 021import java.util.function.*; 022 023 024/** 025 * Used for assertion calls against byte arrays. 026 * 027 * <h2 class='section'>Example:</h2> 028 * <p class='bjava'> 029 * <jc>// Validates the byte array contains the string "foo".</jc> 030 * <jsm>assertBytes</jsm>(<jv>myByteArray</jv>).asHex().is(<js>"666F6F"</js>); 031 * </p> 032 * 033 * 034 * <h2 class='section'>Test Methods:</h2> 035 * <ul class='javatree'> 036 * <li class='jc'>{@link FluentPrimitiveArrayAssertion} 037 * <ul class='javatreec'> 038 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#isHas(Object...) isHas(Object...)} 039 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#is(Predicate) is(Predicate)} 040 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#isAny(Predicate) isAny(Predicate)} 041 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#isAll(Predicate) isAll(Predicate)} 042 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#isEmpty() isEmpty()} 043 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#isNotEmpty() isNotEmpty()} 044 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#isSize(int) isSize(int)} 045 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#isContains(Object) isContains(Object)} 046 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#isNotContains(Object) isNotContains(Object)} 047 * </ul> 048 * <li class='jc'>{@link FluentObjectAssertion} 049 * <ul class='javatreec'> 050 * <li class='jm'>{@link FluentObjectAssertion#isExists() isExists()} 051 * <li class='jm'>{@link FluentObjectAssertion#is(Object) is(Object)} 052 * <li class='jm'>{@link FluentObjectAssertion#is(Predicate) is(Predicate)} 053 * <li class='jm'>{@link FluentObjectAssertion#isNot(Object) isNot(Object)} 054 * <li class='jm'>{@link FluentObjectAssertion#isAny(Object...) isAny(Object...)} 055 * <li class='jm'>{@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)} 056 * <li class='jm'>{@link FluentObjectAssertion#isNull() isNull()} 057 * <li class='jm'>{@link FluentObjectAssertion#isNotNull() isNotNull()} 058 * <li class='jm'>{@link FluentObjectAssertion#isString(String) isString(String)} 059 * <li class='jm'>{@link FluentObjectAssertion#isSame(Object) isSame(Object)} 060 * <li class='jm'>{@link FluentObjectAssertion#isType(Class) isType(Class)} 061 * <li class='jm'>{@link FluentObjectAssertion#isExactType(Class) isExactType(Class)} 062 * </ul> 063 * </ul> 064 * 065 * <h2 class='section'>Transform Methods:</h2> 066 * <ul class='javatree'> 067 * <li class='jc'>{@link FluentByteArrayAssertion} 068 * <ul class='javatreec'> 069 * <li class='jm'>{@link FluentByteArrayAssertion#asString() asString()} 070 * <li class='jm'>{@link FluentByteArrayAssertion#asString(Charset) asString(Charset)} 071 * <li class='jm'>{@link FluentByteArrayAssertion#asBase64() asBase64()} 072 * <li class='jm'>{@link FluentByteArrayAssertion#asHex() asHex()} 073 * <li class='jm'>{@link FluentByteArrayAssertion#asSpacedHex() asSpacedHex()} 074 * </ul> 075 * <li class='jc'>{@link FluentPrimitiveArrayAssertion} 076 * <ul class='javatreec'> 077 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#asItem(int) asItem(int)} 078 * <li class='jm'>{@link FluentPrimitiveArrayAssertion#asLength() asLength()} 079 * </ul> 080 * <li class='jc'>{@link FluentObjectAssertion} 081 * <ul class='javatreec'> 082 * <li class='jm'>{@link FluentObjectAssertion#asString() asString()} 083 * <li class='jm'>{@link FluentObjectAssertion#asString(ThrowingFunction) asString(ThrowingFunction)} 084 * <li class='jm'>{@link FluentObjectAssertion#asTransformed(UnaryOperator) asTransformed(UnaryOperator)} 085 * <li class='jm'>{@link FluentObjectAssertion#asAny() asAny()} 086 * </ul> 087 * </ul> 088 * 089 * <h2 class='section'>Configuration Methods:</h2> 090 * <ul class='javatree'> 091 * <li class='jc'>{@link Assertion} 092 * <ul class='javatreec'> 093 * <li class='jm'>{@link Assertion#setMsg(String, Object...) setMsg(String, Object...)} 094 * <li class='jm'>{@link Assertion#setOut(PrintStream) setOut(PrintStream)} 095 * <li class='jm'>{@link Assertion#setSilent() setSilent()} 096 * <li class='jm'>{@link Assertion#setStdOut() setStdOut()} 097 * <li class='jm'>{@link Assertion#setThrowable(Class) setThrowable(Class)} 098 * </ul> 099 * </ul> 100 * 101 * <h2 class='section'>See Also:</h2><ul> 102 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauEcosystemOverview">Juneau Ecosystem</a> 103 * </ul> 104 */ 105@SuppressWarnings({ 106 "java:S110" // Inheritance depth acceptable for ByteArrayAssertion hierarchy 107}) 108public class ByteArrayAssertion extends FluentByteArrayAssertion<ByteArrayAssertion> { 109 110 /** 111 * Static creator. 112 * 113 * @param value 114 * The object being tested. 115 * <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value). 116 * @return A new assertion object. 117 */ 118 public static ByteArrayAssertion create(byte[] value) { 119 return new ByteArrayAssertion(value); 120 } 121 122 /** 123 * Constructor. 124 * 125 * @param value 126 * The object being tested. 127 * <br>Can be <jk>null</jk> (assertions such as {@code isNull()} then operate on the absence of a value). 128 */ 129 public ByteArrayAssertion(byte[] value) { 130 super(value, null); 131 } 132 133 @Override /* Overridden from Assertion */ 134 public ByteArrayAssertion setMsg(String msg, Object...args) { 135 super.setMsg(msg, args); 136 return this; 137 } 138 139 @Override /* Overridden from Assertion */ 140 public ByteArrayAssertion setOut(PrintStream value) { 141 super.setOut(value); 142 return this; 143 } 144 145 @Override /* Overridden from Assertion */ 146 public ByteArrayAssertion setSilent() { 147 super.setSilent(); 148 return this; 149 } 150 151 @Override /* Overridden from Assertion */ 152 public ByteArrayAssertion setStdOut() { 153 super.setStdOut(); 154 return this; 155 } 156 157 @Override /* Overridden from Assertion */ 158 public ByteArrayAssertion setThrowable(Class<? extends RuntimeException> value) { 159 super.setThrowable(value); 160 return this; 161 } 162}