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.io.file;
19  
20  import static org.apache.commons.io.file.CounterAssertions.assertCounter;
21  import static org.apache.commons.io.file.CounterAssertions.assertCounts;
22  import static org.junit.jupiter.api.Assertions.assertEquals;
23  
24  import org.apache.commons.io.file.Counters.Counter;
25  import org.apache.commons.io.file.Counters.PathCounters;
26  import org.junit.jupiter.params.ParameterizedTest;
27  import org.junit.jupiter.params.provider.MethodSource;
28  
29  /**
30   * Tests {@link Counter} and implementations.
31   */
32  public class CountersTest extends TestArguments {
33  
34      @ParameterizedTest
35      @MethodSource("numberCounters")
36      public void testInitialValue(final Counter counter) {
37          assertCounter(0, counter, "");
38      }
39  
40      @ParameterizedTest
41      @MethodSource("pathCounters")
42      public void testInitialValues(final PathCounters pathCounter) {
43          // Does not blow up
44          assertCounts(0, 0, 0, pathCounter);
45      }
46  
47      @ParameterizedTest
48      @MethodSource("pathCounters")
49      public void testResetCounter(final PathCounters pathCounter) {
50          final Counter byteCounter = pathCounter.getByteCounter();
51          final long old = byteCounter.get();
52          byteCounter.add(1);
53          assertEquals(old + 1, byteCounter.get());
54          byteCounter.reset();
55          assertEquals(0, byteCounter.get());
56      }
57  
58      @ParameterizedTest
59      @MethodSource("pathCounters")
60      public void testResetPathCounter(final PathCounters pathCounter) {
61          final Counter byteCounter = pathCounter.getByteCounter();
62          final long old = byteCounter.get();
63          byteCounter.add(1);
64          assertEquals(old + 1, byteCounter.get());
65          pathCounter.reset();
66          assertEquals(0, byteCounter.get());
67      }
68  
69      @ParameterizedTest
70      @MethodSource("numberCounters")
71      public void testToString(final Counter counter) {
72          // Does not blow up
73          counter.toString();
74      }
75  
76      @ParameterizedTest
77      @MethodSource("pathCounters")
78      public void testToString(final PathCounters pathCounter) {
79          // Does not blow up
80          pathCounter.toString();
81      }
82  }