001/* 002 * Copyright (C) 2005 Christian Schulte <cs@schulte.it> 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without 006 * modification, are permitted provided that the following conditions 007 * are met: 008 * 009 * o Redistributions of source code must retain the above copyright 010 * notice, this list of conditions and the following disclaimer. 011 * 012 * o Redistributions in binary form must reproduce the above copyright 013 * notice, this list of conditions and the following disclaimer in 014 * the documentation and/or other materials provided with the 015 * distribution. 016 * 017 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 018 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 019 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 020 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, 021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 027 * 028 * $JOMC: ToolsTypeTest.java 5135 2016-04-08 13:53:07Z schulte $ 029 * 030 */ 031package org.jomc.tools.model.test; 032 033import java.util.ArrayList; 034import java.util.List; 035import javax.xml.bind.JAXBElement; 036import javax.xml.namespace.QName; 037import org.jomc.tools.model.ToolsType; 038import org.junit.Test; 039import static org.junit.Assert.assertNotNull; 040import static org.junit.Assert.fail; 041 042/** 043 * Test cases for class {@code org.jomc.tools.model.ToolsType}. 044 * 045 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.0 046 * @version $JOMC: ToolsTypeTest.java 5135 2016-04-08 13:53:07Z schulte $ 047 */ 048public class ToolsTypeTest 049{ 050 051 /** 052 * Creates a new {@code ToolsTypeTest} instance. 053 */ 054 public ToolsTypeTest() 055 { 056 super(); 057 } 058 059 /** 060 * Test {@code ToolsType}. 061 */ 062 public static class TestToolsType extends ToolsType 063 { 064 065 @Override 066 public <T> JAXBElement<T> getAnyElement( final List<Object> any, final String namespaceURI, 067 final String localPart, final Class<T> type ) 068 { 069 return super.getAnyElement( any, namespaceURI, localPart, type ); 070 } 071 072 @Override 073 public <T> T getAnyObject( final List<Object> any, final Class<T> clazz ) 074 { 075 return super.getAnyObject( any, clazz ); 076 } 077 078 } 079 080 @Test 081 public final void testGetAnyElement() throws Exception 082 { 083 final TestToolsType toolsObject = new TestToolsType(); 084 final List<Object> any = new ArrayList<Object>( 10 ); 085 final QName name = new QName( "http://jomc.org/tools/model", "test" ); 086 final JAXBElement<Object> element = new JAXBElement<Object>( name, Object.class, null, null ); 087 any.add( element ); 088 any.add( element ); 089 090 try 091 { 092 toolsObject.getAnyElement( any, "http://jomc.org/tools/model", "test", Object.class ); 093 fail( "Expected 'IllegalStateException' not thrown." ); 094 } 095 catch ( final IllegalStateException e ) 096 { 097 assertNotNull( e.getMessage() ); 098 System.out.println( e ); 099 } 100 } 101 102 @Test 103 public final void testGetAnyObject() throws Exception 104 { 105 final TestToolsType toolsObject = new TestToolsType(); 106 final List<Object> any = new ArrayList<Object>( 10 ); 107 any.add( "TEST" ); 108 any.add( "TEST" ); 109 110 try 111 { 112 toolsObject.getAnyObject( any, String.class ); 113 fail( "Expected 'IllegalStateException' not thrown." ); 114 } 115 catch ( final IllegalStateException e ) 116 { 117 assertNotNull( e.getMessage() ); 118 System.out.println( e ); 119 } 120 } 121 122}