001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.assertions; 014 015 016import org.apache.juneau.internal.*; 017 018/** 019 * Used for fluent assertion calls against longs. 020 * 021 * <h5 class='section'>Example:</h5> 022 * <p class='bcode w800'> 023 * <jc>// Validates the response length isn't too long.</jc> 024 * <jv>client</jv> 025 * .get(<jsf>URL</jsf>) 026 * .run() 027 * .assertLongHeader(<js>"Length"</js>).isLessThan(100000); 028 * </p> 029 * 030 * @param <R> The return type. 031 */ 032@FluentSetters(returns="FluentLongAssertion<R>") 033public class FluentLongAssertion<R> extends FluentComparableAssertion<R> { 034 035 private final Long value; 036 037 /** 038 * Constructor. 039 * 040 * @param value The value being tested. 041 * @param returns The object to return after the test. 042 */ 043 public FluentLongAssertion(Long value, R returns) { 044 this(null, value, returns); 045 } 046 047 /** 048 * Constructor. 049 * 050 * @param creator The assertion that created this assertion. 051 * @param value The value being tested. 052 * @param returns The object to return after the test. 053 */ 054 public FluentLongAssertion(Assertion creator, Long value, R returns) { 055 super(creator, value, returns); 056 this.value = value; 057 } 058 059 /** 060 * Converts this long into an integer and then returns it as an integer assertion. 061 * 062 * @return A new assertion. 063 */ 064 public FluentIntegerAssertion<R> integer() { 065 return new FluentIntegerAssertion<>(this, value == null ? null : value.intValue(), returns()); 066 } 067 068 @Override 069 protected int compareTo(Object value) { 070 return this.value.compareTo(((Number)value).longValue()); 071 } 072 073 @Override 074 protected Object equivalent(Object o) { 075 if (o instanceof Number) 076 return ((Number)o).longValue(); 077 return o; 078 } 079 080 // <FluentSetters> 081 082 @Override /* GENERATED - Assertion */ 083 public FluentLongAssertion<R> msg(String msg, Object...args) { 084 super.msg(msg, args); 085 return this; 086 } 087 088 @Override /* GENERATED - Assertion */ 089 public FluentLongAssertion<R> stderr() { 090 super.stderr(); 091 return this; 092 } 093 094 @Override /* GENERATED - Assertion */ 095 public FluentLongAssertion<R> stdout() { 096 super.stdout(); 097 return this; 098 } 099 100 // </FluentSetters> 101}