Example: Using an optional id from a command-line parameter

In this example, we create a component that receives a unique ID via the command line, but if the ID is not specified it will generate one itself. Where the tests are performed on the build server, the ID of the build is used to identify test data.
import com.foreach.cuke.ctf.CtfEvaluationContext;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
 
@Component
public class CalculatedProperties
{
	private static final Logger LOG = LoggerFactory.getLogger( CalculatedProperties.class );
 
	@Autowired
	private CtfEvaluationContext context;
 
	@Value("${buildName:}")
	private String buildName;
 
	@PostConstruct
	public void createProperties() {
		String differentiator = context.lookupString( "buildId.differentiator" );
		String buildNumber = StringUtils.isBlank( buildName ) ? context.getId().getToday() : buildName;
 
		String buildId = "build_" + differentiator + "_" + buildNumber;
 
		// Binnen de Cucumber scenarios kan gebruik gemaakt worden van ${buildId}
		context.getProperties().put( "buildId", buildId );
		LOG.info( "Current buildId value is {}", buildId );
	}
}