All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.teamscale.commons.commit.CommitDescriptorTestUtils Maven / Gradle / Ivy

There is a newer version: 2024.9.0-rc3
Show newest version
/*
 * Copyright (c) CQSE GmbH
 *
 * Licensed 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 com.teamscale.commons.commit;

import static java.util.Arrays.asList;

import java.util.ArrayList;
import java.util.List;

import org.conqat.engine.index.shared.CommitDescriptor;
import org.conqat.engine.index.shared.ParentedCommitDescriptor;

/**
 * Class providing static imports of methods to create commit descriptors with shorthand methods.
 * Should be used to increase readability of tests.
 */
public class CommitDescriptorTestUtils {

	/** The name of the master branch. */
	public static final String MASTER_BRANCH_NAME = "master";

	/** The default name for commits on a branch. */
	public static final String OTHER_BRANCH_NAME = "branch";

	private static final String TRUNK_BRANCH_NAME = "trunk";

	/**
	 * Creates a {@link CommitDescriptor} with branch name {@code master} and given timestamp.
	 */
	public static CommitDescriptor masterCommit(long timestamp) {
		return new CommitDescriptor(MASTER_BRANCH_NAME, timestamp);
	}

	/**
	 * Creates a {@link CommitDescriptor} with branch name {@code branch} and given timestamp.
	 */
	public static CommitDescriptor branchCommit(long timestamp) {
		return new CommitDescriptor(OTHER_BRANCH_NAME, timestamp);
	}

	/**
	 * Creates a {@link CommitDescriptor} for given timestamp with branch as {@link #TRUNK_BRANCH_NAME}
	 */
	public static CommitDescriptor trunkCommit(long timestamp) {
		return new CommitDescriptor(TRUNK_BRANCH_NAME, timestamp);
	}

	/** Creates a merge {@link ParentedCommitDescriptor} with given parents. */
	public static ParentedCommitDescriptor mergeCommit(CommitDescriptor mergeCommit, CommitDescriptor firstParent,
			CommitDescriptor mergedParent, CommitDescriptor... additionalMergedParents) {
		List parentCommits = new ArrayList<>();
		parentCommits.add(firstParent);
		parentCommits.add(mergedParent);
		parentCommits.addAll(asList(additionalMergedParents));
		return new ParentedCommitDescriptor(mergeCommit, parentCommits);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy