/* * 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.xenei.junit.contract.exampleTests; import org.junit.After; import org.xenei.junit.contract.Contract; import org.xenei.junit.contract.ContractTest; import org.xenei.junit.contract.IProducer; /** * An example Contract test for A interface. * * Defining AT as a generic class with the type extending the type we are * testing (e.g. AT<T extends A>) ensures that there are no issues with * using derived classes in the tests. * * The use of the Listener interface in the before and after methods are to * track that the tests are run correctly and in the proper order. This would * not be used in a production test but are part of our testing of * junit-contracts. * * @param <T> * The class that we are testing must extend A. */ @Contract(A.class) public class AT<T extends A> { // the producer we will user private IProducer<T> producer; /** * Method to set the producerthat this test will use. * * @param producer * The producer to use. */ @Contract.Inject public final void setProducer(IProducer<T> producer) { this.producer = producer; } protected final IProducer<T> getProducer() { return producer; } /** * Clean up the producer for the next run */ @After public final void cleanupAT() { getProducer().cleanUp(); } /** * test the getAName() method. */ @ContractTest public void testGetAName() { Listener.add(getProducer().newInstance().getAName()); } }