1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.mina.util; 20 21 import static org.hamcrest.CoreMatchers.is; 22 import static org.junit.Assert.assertThat; 23 24 import org.junit.Rule; 25 import org.junit.Test; 26 import org.junit.rules.ExpectedException; 27 28 /** 29 * Tests class {@link Assert} 30 * 31 * @author <a href="http://mina.apache.org">Apache MINA Project</a> 32 */ 33 public class AssertTest { 34 /** checks Exception parameters */ 35 @Rule 36 public final ExpectedException exception = ExpectedException.none(); 37 38 /** 39 * Tests if a {@link IllegalArgumentException} is thrown when a 40 * <code>null</code>-value is passed. 41 * 42 * @throws Exception 43 */ 44 @Test 45 public void parameterNotNullWithNullValue() throws Exception { 46 exception.expect(IllegalArgumentException.class); 47 exception.expectMessage("Parameter >parameterName< must not be null!"); 48 Assert.assertNotNull(null, "parameterName"); 49 } 50 51 /** Tests if a non <code>null</code> value is returned. */ 52 @Test 53 public void parameterNotNullWithNonNullValue() { 54 Integer result = Assert.assertNotNull(123, "parameterName"); 55 assertThat(result, is(123)); 56 } 57 58 /** 59 * Tests if a {@link IllegalArgumentException} is thrown when a 60 * <code>null</code>-value is passed. 61 * 62 * @throws Exception 63 */ 64 @Test 65 public void parameterNotNullWithMissingParameterName() throws Exception { 66 exception.expect(IllegalArgumentException.class); 67 exception.expectMessage("You must provide a parameter name!"); 68 Assert.assertNotNull("", null); 69 } 70 }