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  
18  package org.apache.commons.lang3;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  import static org.junit.jupiter.api.Assertions.assertSame;
22  
23  import org.junit.jupiter.api.Test;
24  
25  /**
26   * Tests {@link ArrayFill}.
27   */
28  public class ArrayFillTest extends AbstractLangTest {
29  
30      @Test
31      public void testFillByteArray() {
32          final byte[] array = new byte[3];
33          final byte val = (byte) 1;
34          final byte[] actual = ArrayFill.fill(array, val);
35          assertSame(array, actual);
36          for (final byte v : actual) {
37              assertEquals(val, v);
38          }
39      }
40  
41      @Test
42      public void testFillCharArray() {
43          final char[] array = new char[3];
44          final char val = 1;
45          final char[] actual = ArrayFill.fill(array, val);
46          assertSame(array, actual);
47          for (final char v : actual) {
48              assertEquals(val, v);
49          }
50      }
51  
52      @Test
53      public void testFillDoubleArray() {
54          final double[] array = new double[3];
55          final double val = 1;
56          final double[] actual = ArrayFill.fill(array, val);
57          assertSame(array, actual);
58          for (final double v : actual) {
59              assertEquals(val, v);
60          }
61      }
62  
63      @Test
64      public void testFillFloatArray() {
65          final float[] array = new float[3];
66          final float val = 1;
67          final float[] actual = ArrayFill.fill(array, val);
68          assertSame(array, actual);
69          for (final float v : actual) {
70              assertEquals(val, v);
71          }
72      }
73  
74      @Test
75      public void testFillIntArray() {
76          final int[] array = new int[3];
77          final int val = 1;
78          final int[] actual = ArrayFill.fill(array, val);
79          assertSame(array, actual);
80          for (final int v : actual) {
81              assertEquals(val, v);
82          }
83      }
84  
85      @Test
86      public void testFillLongArray() {
87          final long[] array = new long[3];
88          final long val = 1;
89          final long[] actual = ArrayFill.fill(array, val);
90          assertSame(array, actual);
91          for (final long v : actual) {
92              assertEquals(val, v);
93          }
94      }
95  
96      @Test
97      public void testFillObjectArray() {
98          final String[] array = new String[3];
99          final String val = "A";
100         final String[] actual = ArrayFill.fill(array, val);
101         assertSame(array, actual);
102         for (final String v : actual) {
103             assertEquals(val, v);
104         }
105     }
106 
107     @Test
108     public void testFillShortArray() {
109         final short[] array = new short[3];
110         final short val = (byte) 1;
111         final short[] actual = ArrayFill.fill(array, val);
112         assertSame(array, actual);
113         for (final short v : actual) {
114             assertEquals(val, v);
115         }
116     }
117 }