001package org.apache.maven.building; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.junit.Assert.assertEquals; 023 024import java.io.InputStream; 025import java.util.Scanner; 026 027import org.junit.Test; 028 029public class StringSourceTest 030{ 031 @Test 032 public void testGetInputStream() 033 throws Exception 034 { 035 StringSource source = new StringSource( "Hello World!" ); 036 037 Scanner scanner = null; 038 InputStream is = null; 039 try 040 { 041 is = source.getInputStream(); 042 043 scanner = new Scanner( is ); 044 assertEquals( "Hello World!", scanner.nextLine() ); 045 } 046 finally 047 { 048 if ( scanner != null ) 049 { 050 scanner.close(); 051 } 052 if ( is != null ) 053 { 054 is.close(); 055 } 056 } 057 } 058 059 @Test 060 public void testGetLocation() 061 { 062 StringSource source = new StringSource( "Hello World!" ); 063 assertEquals( "(memory)", source.getLocation() ); 064 065 source = new StringSource( "Hello World!", "LOCATION" ); 066 assertEquals( "LOCATION", source.getLocation() ); 067 } 068 069 @Test 070 public void testGetContent() 071 { 072 StringSource source = new StringSource( null ); 073 assertEquals( "", source.getContent() ); 074 075 source = new StringSource( "Hello World!", "LOCATION" ); 076 assertEquals( "Hello World!", source.getContent() ); 077 } 078 079}