View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau.assertions;
18  
19  import static org.apache.juneau.assertions.Assertions.*;
20  import static org.apache.juneau.assertions.Verify.*;
21  
22  import java.util.*;
23  
24  import org.apache.juneau.*;
25  import org.junit.jupiter.api.*;
26  
27  @Deprecated
28  class Verify_Test extends TestBase {
29  
30  	//-----------------------------------------------------------------------------------------------------------------
31  	// Helpers
32  	//-----------------------------------------------------------------------------------------------------------------
33  
34  	private StringAssertion test(Object value) {
35  		return assertString(value).setSilent();
36  	}
37  
38  	//-----------------------------------------------------------------------------------------------------------------
39  	// Basic tests
40  	//-----------------------------------------------------------------------------------------------------------------
41  
42  	@Test void a01_basic() {
43  		var x1 = verify("foo");
44  		var x2 = verify(null);
45  		var x3 = verify(new Date(0));
46  
47  		test(x1.is("foo")).isNull();
48  		test(x1.is("bar")).is("Expected 'bar' but was 'foo'.");
49  		test(x1.is(null)).is("Expected 'null' but was 'foo'.");
50  		test(x2.is(null)).isNull();
51  		test(x2.is("foo")).is("Expected 'foo' but was 'null'.");
52  		test(x3.is(new Date(0))).isNull();
53  
54  		test(x1.isType(String.class)).isNull();
55  		test(x1.isType(Integer.class)).is("Expected type 'java.lang.Integer' but was 'java.lang.String'.");
56  		test(x2.isType(null)).isNull();
57  		test(x2.isType(String.class)).is("Expected type 'java.lang.String' but was 'null'.");
58  		test(x1.isType(null)).is("Expected type 'null' but was 'java.lang.String'.");
59  
60  
61  		test(verify(true).isTrue()).isNull();
62  		test(verify(false).isFalse()).isNull();
63  		test(verify(null).isTrue()).is("Expected 'true' but was 'null'.");
64  		test(verify(null).isFalse()).is("Expected 'false' but was 'null'.");
65  		test(verify(Boolean.TRUE).isTrue()).isNull();
66  		test(verify(Boolean.FALSE).isFalse()).isNull();
67  		test(x1.is("foo")).isNull();
68  
69  		test(verify("foo").msg("bar{0}", "baz").is("foo")).isNull();
70  		test(verify("foo").msg("bar{0}", "baz").is("bar")).is("barbaz");
71  		test(verify("foo").msg("bar{0}", "baz").isType(Integer.class)).is("barbaz");
72  		test(verify(null).msg("bar{0}", "baz").is("bar")).is("barbaz");
73  		test(verify("foo").msg("bar{0}", "baz").is(null)).is("barbaz");
74  	}
75  }