blob: 0d1947e0ab27989a683337ee83c4387b4ff15a28 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.zest.tutorials.composites.tutorial6;
import org.junit.Before;
import org.junit.Test;
import org.apache.zest.bootstrap.AssemblyException;
import org.apache.zest.bootstrap.ModuleAssembly;
import org.apache.zest.bootstrap.SingletonAssembler;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
public class HelloWorldTest
{
HelloWorld helloWorld;
@Before
public void setUp()
throws Exception
{
SingletonAssembler assembly = new SingletonAssembler()
{
@Override
public void assemble( ModuleAssembly module )
throws AssemblyException
{
module.transients( HelloWorldComposite.class );
}
};
helloWorld = assembly.module().newTransient(HelloWorldComposite.class );
}
@Test
public void givenHelloWorldWhenSetPropertiesAndSayThenReturnCorrectResult()
{
{
helloWorld.setPhrase( "Hello" );
helloWorld.setName( "World" );
String result = helloWorld.say();
assertThat( result, equalTo( "Simon says:Hello World" ) );
}
{
helloWorld.setPhrase( "Hey" );
helloWorld.setName( "Universe" );
String result = helloWorld.say();
assertThat( result, equalTo( "Simon says:Hey Universe" ) );
}
}
@Test
public void givenHelloWorldWhenSetInvalidPhraseThenThrowException()
{
try
{
helloWorld.setPhrase( null );
fail( "Should not be allowed to set phrase to null" );
}
catch( IllegalArgumentException e )
{
// Ok
}
try
{
helloWorld.setPhrase( "" );
fail( "Should not be allowed to set phrase to empty string" );
}
catch( IllegalArgumentException e )
{
// Ok
}
}
@Test
public void givenHelloWorldWhenSetInvalidNameThenThrowException()
{
try
{
helloWorld.setName( null );
fail( "Should not be allowed to set name to null" );
}
catch( IllegalArgumentException e )
{
// Ok
}
try
{
helloWorld.setName( "" );
fail( "Should not be allowed to set name to empty string" );
}
catch( IllegalArgumentException e )
{
// Ok
}
}
}