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