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.TestUtils.*;
20  import static org.apache.juneau.assertions.Assertions.*;
21  import static org.apache.juneau.assertions.Assertions.assertThrowable;
22  import static org.apache.juneau.commons.utils.CollectionUtils.*;
23  import static org.junit.jupiter.api.Assertions.*;
24  
25  import java.io.*;
26  import java.time.*;
27  import java.util.*;
28  
29  import org.apache.juneau.*;
30  import org.apache.juneau.commons.lang.*;
31  import org.apache.juneau.testutils.pojos.*;
32  import org.junit.jupiter.api.*;
33  import org.junit.jupiter.api.MethodOrderer.*;
34  
35  @TestMethodOrder(MethodName.class)
36  @Deprecated
37  class Assertions_Test extends TestBase {
38  
39  	//------------------------------------------------------------------------------------------------------------------
40  	// Basic tests
41  	//------------------------------------------------------------------------------------------------------------------
42  
43  	@Test void a01_assertDate() {
44  		assertDate(new Date()).isAfter(new Date(0));
45  	}
46  
47  	@Test void a02_assertInteger() {
48  		assertInteger(2).isGt(1);
49  	}
50  
51  	@Test void a03_assertLong() {
52  		assertLong(2L).isGt(1L);
53  	}
54  
55  	@Test void a04_assertObject() {
56  		assertObject("foo").asJson().is("'foo'");
57  	}
58  
59  	@Test void a06_assertThrowable() {
60  		assertThrowable(null).isNull();
61  	}
62  
63  	@Test void a07_assertArray() {
64  		assertArray(new String[0]).isEmpty();
65  	}
66  
67  	@Test void a08_assertCollection() {
68  		assertCollection(l()).isEmpty();
69  	}
70  
71  	@Test void a09_assertList() {
72  		assertList(l()).isEmpty();
73  	}
74  
75  	@Test void a10_assertStream() throws Exception {
76  		assertBytes(inputStream("foo")).asString().is("foo");
77  		assertBytes((InputStream)null).asString().isNull();
78  	}
79  
80  	@Test void a11_assertBytes() {
81  		assertBytes("foo".getBytes()).asString().is("foo");
82  		assertBytes((byte[])null).asString().isNull();
83  	}
84  
85  	@Test void a12_assertReader() throws Exception {
86  		assertReader(reader("foo")).is("foo");
87  		assertReader((Reader)null).isNull();
88  	}
89  
90  	@Test void a13_assertThrown() {
91  		assertThrows(RuntimeException.class, ()->{throw new RuntimeException("foo");}, "foo");
92  		assertThrown(()->{}).isNull();
93  	}
94  
95  	@Test void a14_assertZonedDateTime() {
96  		assertZonedDateTime(ZonedDateTime.now()).isExists();
97  	}
98  
99  	@Test void a15_assertBean() {
100 		assertBean("123").isExists();
101 	}
102 
103 	@Test void a16_assertBoolean() {
104 		assertTrue(true);
105 	}
106 
107 	@Test void a17_assertVersion() {
108 		assertVersion(Version.of("2")).isGt(Version.of("1"));
109 	}
110 
111 	@Test void a18_assertComparable() {
112 		assertComparable(2).isGt(1);
113 	}
114 
115 	@Test void a19_assertBeanList() {
116 		assertBeanList(l(ABean.get())).asJson().is("[{a:1,b:'foo'}]");
117 	}
118 
119 	@Test void a20a_assertIntArray() {
120 		assertIntArray(ints(1)).asLength().is(1);
121 	}
122 
123 	@Test void a20b_assertLongArray() {
124 		assertLongArray(longs(1L)).asLength().is(1);
125 	}
126 
127 	@Test void a20c_assertShortArray() {
128 		assertShortArray(shorts(1)).asLength().is(1);
129 	}
130 
131 	@Test void a20d_assertFloatArray() {
132 		assertFloatArray(floats(1)).asLength().is(1);
133 	}
134 
135 	@Test void a20e_assertDoubleArray() {
136 		assertDoubleArray(doubles(1)).asLength().is(1);
137 	}
138 
139 	@Test void a20f_assertBooleanArray() {
140 		assertBooleanArray(booleans(true)).asLength().is(1);
141 	}
142 
143 	@Test void a20g_assertCharArray() {
144 		assertCharArray(chars('a')).asLength().is(1);
145 	}
146 
147 	@Test void a20h_assertByteArray() {
148 		assertByteArray(bytes(1)).asLength().is(1);
149 	}
150 
151 	@Test void a21_assertMap() {
152 		assertMap(map(1,2)).asSize().is(1);
153 	}
154 
155 	@Test void a24_assertOptional() {
156 		assertOptional(opt(1)).isNotNull();
157 	}
158 
159 	@Test void a25_assertStringList() {
160 		assertStringList(l()).isNotNull();
161 		assertStringList(null).isNull();
162 	}
163 }