View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util;
17  
18  import org.junit.Assert;
19  import org.junit.Test;
20  
21  public class CounterTest {
22  
23  	@Test
24  	public void testMax() {
25  		try {
26  			Counter counter = new Counter(Integer.MAX_VALUE);
27  			counter.increment();
28  			Assert.fail("Should have failed");
29  		} catch (IllegalArgumentException e) {
30  			// expected
31  		}
32  	}
33  
34  	@Test
35  	public void testMin() {
36  		try {
37  			Counter counter = new Counter(Integer.MIN_VALUE);
38  			counter.decrement();
39  			Assert.fail("Should have failed");
40  		} catch (IllegalArgumentException e) {
41  			// expected
42  		}
43  	}
44  
45  	@Test
46  	public void testMaxLong() {
47  		try {
48  			LongCounter counter = new LongCounter(Long.MAX_VALUE);
49  			counter.increment();
50  			Assert.fail("Should have failed");
51  		} catch (IllegalArgumentException e) {
52  			// expected
53  		}
54  	}
55  
56  	@Test
57  	public void testMinLong() {
58  		try {
59  			LongCounter counter = new LongCounter(Long.MIN_VALUE);
60  			counter.decrement();
61  			Assert.fail("Should have failed");
62  		} catch (IllegalArgumentException e) {
63  			// expected
64  		}
65  	}
66  }