1+ /*
2+ * Copyright 2017 Patrick Favre-Bulle
3+ *
4+ * Licensed to the Apache Software Foundation (ASF) under one
5+ * or more contributor license agreements. See the NOTICE file
6+ * distributed with this work for additional information
7+ * regarding copyright ownership. The ASF licenses this file
8+ * to you under the Apache License, Version 2.0 (the
9+ * "License"); you may not use this file except in compliance
10+ * with the License. You may obtain a copy of the License at
11+ *
12+ * http://www.apache.org/licenses/LICENSE-2.0
13+ *
14+ * Unless required by applicable law or agreed to in writing,
15+ * software distributed under the License is distributed on an
16+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+ * KIND, either express or implied. See the License for the
18+ * specific language governing permissions and limitations
19+ * under the License.
20+ */
21+
22+ package at .favre .lib .bytes ;
23+
24+ import org .junit .Test ;
25+
26+ import static org .junit .Assert .assertFalse ;
27+ import static org .junit .Assert .assertTrue ;
28+
29+ public class BytesValidatorTest extends ABytesTest {
30+
31+ @ Test
32+ public void testOnlyOfValidator () throws Exception {
33+ assertFalse (Bytes .allocate (0 ).validateNotOnlyZeros ());
34+ assertFalse (Bytes .allocate (2 ).validateNotOnlyZeros ());
35+ assertTrue (Bytes .wrap (example_bytes_seven ).validateNotOnlyZeros ());
36+ assertTrue (Bytes .wrap (new byte []{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 }).validateNotOnlyZeros ());
37+ assertTrue (Bytes .random (128 ).validateNotOnlyZeros ());
38+
39+ assertTrue (Bytes .allocate (0 ).validate (BytesValidators .onlyOf ((byte ) 0 )));
40+ assertTrue (Bytes .wrap (new byte []{1 , 1 , 1 , 1 , 1 , 1 }).validate (BytesValidators .onlyOf ((byte ) 1 )));
41+ }
42+
43+ @ Test
44+ public void testLengthValidators () throws Exception {
45+ assertFalse (Bytes .allocate (0 ).validate (BytesValidators .longerThan (1 )));
46+ assertFalse (Bytes .allocate (1 ).validate (BytesValidators .longerThan (1 )));
47+ assertTrue (Bytes .allocate (2 ).validate (BytesValidators .longerThan (1 )));
48+
49+ assertFalse (Bytes .allocate (2 ).validate (BytesValidators .shorterThan (1 )));
50+ assertFalse (Bytes .allocate (1 ).validate (BytesValidators .shorterThan (1 )));
51+ assertTrue (Bytes .allocate (0 ).validate (BytesValidators .shorterThan (1 )));
52+
53+ assertFalse (Bytes .allocate (0 ).validate (BytesValidators .exactLength (1 )));
54+ assertTrue (Bytes .allocate (1 ).validate (BytesValidators .exactLength (1 )));
55+ assertFalse (Bytes .allocate (2 ).validate (BytesValidators .exactLength (1 )));
56+ }
57+ }
0 commit comments