View Javadoc

1   /**
2    * Copyright 2010-2013 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 junit.framework.Assert;
19  
20  import org.junit.Test;
21  
22  public class CounterTest {
23  
24  	@Test
25  	public void testMax() {
26  		try {
27  			Counter counter = new Counter(Integer.MAX_VALUE);
28  			counter.increment();
29  			Assert.fail("Should have failed");
30  		} catch (IllegalArgumentException e) {
31  			// expected
32  		}
33  	}
34  
35  	@Test
36  	public void testMin() {
37  		try {
38  			Counter counter = new Counter(Integer.MIN_VALUE);
39  			counter.decrement();
40  			Assert.fail("Should have failed");
41  		} catch (IllegalArgumentException e) {
42  			// expected
43  		}
44  	}
45  
46  	@Test
47  	public void testMaxLong() {
48  		try {
49  			LongCounter counter = new LongCounter(Long.MAX_VALUE);
50  			counter.increment();
51  			Assert.fail("Should have failed");
52  		} catch (IllegalArgumentException e) {
53  			// expected
54  		}
55  	}
56  
57  	@Test
58  	public void testMinLong() {
59  		try {
60  			LongCounter counter = new LongCounter(Long.MIN_VALUE);
61  			counter.decrement();
62  			Assert.fail("Should have failed");
63  		} catch (IllegalArgumentException e) {
64  			// expected
65  		}
66  	}
67  }