001package org.apache.commons.beanutils2; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020import static org.apache.commons.beanutils2.BeanUtils.on; 021import static org.junit.Assert.assertNull; 022import static org.junit.Assert.assertTrue; 023 024import java.util.HashMap; 025 026import org.apache.commons.beanutils2.testbeans.TestBean; 027import org.junit.After; 028import org.junit.Before; 029import org.junit.Test; 030 031/** 032 * Test case to make sure, that methods with void signature are handled correctly. 033 */ 034public class VoidMethodsTestCase 035{ 036 037 private BeanAccessor<?> voidAccessor = null; 038 039 @Before 040 public void setUp() 041 throws Exception 042 { 043 voidAccessor = on( TestBean.class ).invokeStatic( "incrementCounter" ).with(); 044 assertTrue( voidAccessor instanceof NullBeanAccessor ); 045 } 046 047 @After 048 public void tearDown() 049 { 050 voidAccessor = null; 051 } 052 053 @Test 054 public void get() 055 throws Exception 056 { 057 assertNull( voidAccessor.get() ); 058 } 059 060 @Test( expected = NullPointerException.class ) 061 public void getProperty() 062 throws Exception 063 { 064 voidAccessor.get( "propertyName" ); 065 } 066 067 @Test( expected = NullPointerException.class ) 068 public void getIndexed() 069 throws Exception 070 { 071 voidAccessor.getIndexed( "propertyName" ); 072 } 073 074 @Test( expected = NullPointerException.class ) 075 public void getMapped() 076 throws Exception 077 { 078 voidAccessor.getMapped( "propertyName" ); 079 } 080 081 @Test( expected = NullPointerException.class ) 082 public void setProperty() 083 throws Exception 084 { 085 voidAccessor.set( "propertyName" ); 086 } 087 088 @Test( expected = NullPointerException.class ) 089 public void setIndexed() 090 throws Exception 091 { 092 voidAccessor.setIndexed( "propertyName" ); 093 } 094 095 @Test( expected = NullPointerException.class ) 096 public void setMapped() 097 throws Exception 098 { 099 voidAccessor.setMapped( "propertyName" ); 100 } 101 102 @Test 103 public void cast() 104 { 105 assertNull( voidAccessor.cast() ); 106 } 107 108 @Test 109 public void cloneBean() 110 throws Exception 111 { 112 assertNull( voidAccessor.cloneBean() ); 113 } 114 115 @Test( expected = NullPointerException.class ) 116 public void describe() 117 throws Exception 118 { 119 voidAccessor.describe(); 120 } 121 122 @Test( expected = NullPointerException.class ) 123 public void populate() 124 throws Exception 125 { 126 voidAccessor.populate( new HashMap<String, Object>( 0 ) ); 127 } 128 129 @Test 130 public void copyPropertiesTo() 131 throws Exception 132 { 133 // no idea how to invoke this 134 // voidAccessor.copyPropertiesTo( target ); 135 } 136 137 @Test( expected = NullPointerException.class ) 138 public void invoke() 139 throws Exception 140 { 141 voidAccessor.invoke( "methodName" ); 142 } 143 144 @Test( expected = NullPointerException.class ) 145 public void invokeExact() 146 throws Exception 147 { 148 voidAccessor.invokeExact( "methodName" ); 149 } 150 151}