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 testFillByteArrayNull() {
43          final byte[] array = null;
44          final byte val = (byte) 1;
45          final byte[] actual = ArrayFill.fill(array, val);
46          assertSame(array, actual);
47      }
48  
49      @Test
50      public void testFillCharArray() {
51          final char[] array = new char[3];
52          final char val = 1;
53          final char[] actual = ArrayFill.fill(array, val);
54          assertSame(array, actual);
55          for (final char v : actual) {
56              assertEquals(val, v);
57          }
58      }
59  
60      @Test
61      public void testFillCharArrayNull() {
62          final char[] array = null;
63          final char val = 1;
64          final char[] actual = ArrayFill.fill(array, val);
65          assertSame(array, actual);
66      }
67  
68      @Test
69      public void testFillDoubleArray() {
70          final double[] array = new double[3];
71          final double val = 1;
72          final double[] actual = ArrayFill.fill(array, val);
73          assertSame(array, actual);
74          for (final double v : actual) {
75              assertEquals(val, v);
76          }
77      }
78  
79      @Test
80      public void testFillDoubleArrayNull() {
81          final double[] array = null;
82          final double val = 1;
83          final double[] actual = ArrayFill.fill(array, val);
84          assertSame(array, actual);
85      }
86  
87      @Test
88      public void testFillFloatArray() {
89          final float[] array = new float[3];
90          final float val = 1;
91          final float[] actual = ArrayFill.fill(array, val);
92          assertSame(array, actual);
93          for (final float v : actual) {
94              assertEquals(val, v);
95          }
96      }
97  
98      @Test
99      public void testFillFloatArrayNull() {
100         final float[] array = null;
101         final float val = 1;
102         final float[] actual = ArrayFill.fill(array, val);
103         assertSame(array, actual);
104     }
105 
106     @Test
107     public void testFillIntArray() {
108         final int[] array = new int[3];
109         final int val = 1;
110         final int[] actual = ArrayFill.fill(array, val);
111         assertSame(array, actual);
112         for (final int v : actual) {
113             assertEquals(val, v);
114         }
115     }
116 
117     @Test
118     public void testFillIntArrayNull() {
119         final int[] array = null;
120         final int val = 1;
121         final int[] actual = ArrayFill.fill(array, val);
122         assertSame(array, actual);
123     }
124 
125     @Test
126     public void testFillLongArray() {
127         final long[] array = new long[3];
128         final long val = 1;
129         final long[] actual = ArrayFill.fill(array, val);
130         assertSame(array, actual);
131         for (final long v : actual) {
132             assertEquals(val, v);
133         }
134     }
135 
136     @Test
137     public void testFillLongArrayNull() {
138         final long[] array = null;
139         final long val = 1;
140         final long[] actual = ArrayFill.fill(array, val);
141         assertSame(array, actual);
142     }
143 
144     @Test
145     public void testFillObjectArray() {
146         final String[] array = new String[3];
147         final String val = "A";
148         final String[] actual = ArrayFill.fill(array, val);
149         assertSame(array, actual);
150         for (final String v : actual) {
151             assertEquals(val, v);
152         }
153     }
154 
155     @Test
156     public void testFillObjectArrayNull() {
157         final Object[] array = null;
158         final Object val = 1;
159         final Object[] actual = ArrayFill.fill(array, val);
160         assertSame(array, actual);
161     }
162 
163     @Test
164     public void testFillShortArray() {
165         final short[] array = new short[3];
166         final short val = (byte) 1;
167         final short[] actual = ArrayFill.fill(array, val);
168         assertSame(array, actual);
169         for (final short v : actual) {
170             assertEquals(val, v);
171         }
172     }
173 
174     @Test
175     public void testFillShortArrayNull() {
176         final short[] array = null;
177         final short val = 1;
178         final short[] actual = ArrayFill.fill(array, val);
179         assertSame(array, actual);
180     }
181 }