<commit_before>package com.gentics.mesh.mock;

import static com.gentics.mesh.example.AbstractExamples.TIMESTAMP_NEW;
import static com.gentics.mesh.example.AbstractExamples.TIMESTAMP_OLD;
import static com.gentics.mesh.example.ExampleUuids.GROUP_CLIENT_UUID;
import static com.gentics.mesh.example.ExampleUuids.LANGUAGE_UUID;
import static com.gentics.mesh.example.ExampleUuids.MICROSCHEMA_UUID;
import static com.gentics.mesh.example.ExampleUuids.NODE_DELOREAN_UUID;
import static com.gentics.mesh.example.ExampleUuids.PROJECT_DEMO2_UUID;
import static com.gentics.mesh.example.ExampleUuids.PROJECT_DEMO_UUID;
import static com.gentics.mesh.example.ExampleUuids.ROLE_CLIENT_UUID;
import static com.gentics.mesh.example.ExampleUuids.SCHEMA_VEHICLE_UUID;
import static com.gentics.mesh.example.ExampleUuids.TAGFAMILY_FUELS_UUID;
import static com.gentics.mesh.example.ExampleUuids.TAG_BLUE_UUID;
import static com.gentics.mesh.example.ExampleUuids.USER_EDITOR_UUID;
import static com.gentics.mesh.example.ExampleUuids.UUID_1;
import static com.gentics.mesh.example.ExampleUuids.UUID_2;
import static com.gentics.mesh.example.ExampleUuids.UUID_3;
import static com.gentics.mesh.example.ExampleUuids.UUID_4;
import static com.gentics.mesh.example.ExampleUuids.UUID_5;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.mockito.Mockito;

import com.gentics.mesh.core.data.Group;
import com.gentics.mesh.core.data.Language;
import com.gentics.mesh.core.data.NodeGraphFieldContainer;
import com.gentics.mesh.core.data.Project;
import com.gentics.mesh.core.data.Role;
import com.gentics.mesh.core.data.Tag;
import com.gentics.mesh.core.data.TagFamily;
import com.gentics.mesh.core.data.User;
import com.gentics.mesh.core.data.node.Micronode;
import com.gentics.mesh.core.data.node.Node;
import com.gentics.mesh.core.data.node.field.BooleanGraphField;
import com.gentics.mesh.core.data.node.field.DateGraphField;
import com.gentics.mesh.core.data.node.field.HtmlGraphField;
import com.gentics.mesh.core.data.node.field.NumberGraphField;
import com.gentics.mesh.core.data.node.field.StringGraphField;
import com.gentics.mesh.core.data.node.field.list.BooleanGraphFieldList;
import com.gentics.mesh.core.data.node.field.list.DateGraphFieldList;
import com.gentics.mesh.core.data.node.field.list.HtmlGraphFieldList;
import com.gentics.mesh.core.data.node.field.list.NodeGraphFieldList;
import com.gentics.mesh.core.data.node.field.list.NumberGraphFieldList;
import com.gentics.mesh.core.data.node.field.list.StringGraphFieldList;
import com.gentics.mesh.core.data.node.field.nesting.MicronodeGraphField;
import com.gentics.mesh.core.data.node.field.nesting.NodeGraphField;
import com.gentics.mesh.core.data.relationship.GraphPermission;
import com.gentics.mesh.core.data.schema.Microschema;
import com.gentics.mesh.core.data.schema.MicroschemaVersion;
import com.gentics.mesh.core.data.schema.Schema;
import com.gentics.mesh.core.data.schema.SchemaVersion;
import com.gentics.mesh.core.data.search.UpdateDocumentEntry;
import com.gentics.mesh.core.data.search.context.impl.GenericEntryContextImpl;
import com.gentics.mesh.core.rest.microschema.MicroschemaVersionModel;
import com.gentics.mesh.core.rest.microschema.impl.MicroschemaModelImpl;
import com.gentics.mesh.core.rest.schema.SchemaVersionModel;
import com.gentics.mesh.core.rest.schema.impl.BooleanFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.DateFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.HtmlFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.ListFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.MicronodeFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.NodeFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.NumberFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.SchemaModelImpl;
import com.gentics.mesh.core.rest.schema.impl.StringFieldSchemaImpl;
import com.gentics.mesh.madl.traversal.TraversalResult;

public final class TestMocks {

	private TestMocks() {

	}

	public static Project mockProject(User user) {
		Project project = mock(Project.class);
		when(project.getUuid()).thenReturn(PROJECT_DEMO2_UUID);
		when(project.getName()).thenReturn("dummyProject");
		when(project.getCreator()).thenReturn(user);
		when(project.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD);
		when(project.getEditor()).thenReturn(user);
		when(project.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW);
		when(project.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal());
		when(project.getElementVersion()).thenReturn(UUID_1);
		return project;
	}

	public static Language mockLanguage(String code) {
		Language language = mock(Language.class);
		when(language.getUuid()).thenReturn(LANGUAGE_UUID);
		when(language.getLanguageTag()).thenReturn("de");
		when(language.getElementVersion()).thenReturn(UUID_2);
		return language;
	}

	public static Node mockNodeBasic(String schemaType, User user) {
		Node node = mock(Node.class);
		when(node.getUuid()).thenReturn(NODE_DELOREAN_UUID);
		Schema schemaContainer = mockSchemaContainer(schemaType, user);
		when(node.getSchemaContainer()).thenReturn(schemaContainer);
		return node;
	}

	public static Micronode mockMicronode(String microschemaName, User user) {
		Micronode micronode = mock(Micronode.class);
		when(micronode.getUuid()).thenReturn(UUID_1);
		Microschema microschemaContainer = mockMicroschemaContainer(microschemaName, user);
		MicroschemaVersion latestVersion = microschemaContainer.getLatestVersion();
		when(micronode.getSchemaContainerVersion()).thenReturn(latestVersion);
		MicroschemaVersionModel microschema = microschemaContainer.getLatestVersion().getSchema();
		when(micronode.getSchemaContainerVersion().getSchema()).thenReturn(microschema);

		// longitude field
		NumberGraphField longitudeField = mock(NumberGraphField.class);
		when(longitudeField.getNumber()).thenReturn(16.373063840833);
		when(micronode.getNumber("longitude")).thenReturn(longitudeField);

		// latitude field
		NumberGraphField latitudeField = mock(NumberGraphField.class);
		when(latitudeField.getNumber()).thenReturn(16.373063840833);
		when(micronode.getNumber("latitude")).thenReturn(latitudeField);
		when(micronode.getElementVersion()).thenReturn(UUID_3);
		return micronode;
	}

	public static Role mockRole(String roleName, User creator) {
		Role role = mock(Role.class);
		when(role.getCreator()).thenReturn(creator);
		when(role.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD);
		when(role.getEditor()).thenReturn(creator);
		when(role.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW);
		when(role.getName()).thenReturn(roleName);
		when(role.getUuid()).thenReturn(ROLE_CLIENT_UUID);
		when(role.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal());
		when(role.getElementVersion()).thenReturn(UUID_4);
		return role;
	}

	public static Group mockGroup(String groupName, User creator) {
		Group group = mock(Group.class);
		when(group.getCreator()).thenReturn(creator);
		when(group.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD);
		when(group.getEditor()).thenReturn(creator);
		when(group.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW);
		when(group.getName()).thenReturn(groupName);
		when(group.getUuid()).thenReturn(GROUP_CLIENT_UUID);
		when(group.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal());
		when(group.getElementVersion()).thenReturn(UUID_5);
		return group;
	}

	public static User mockUser(String username, String firstname, String lastname) {
		return mockUser(username, firstname, lastname, null);
	}

	public static User mockUser(String username, String firstname, String lastname, User creator) {
		User user = mock(User.class);
		when(user.getUsername()).thenReturn(username);
		when(user.getFirstname()).thenReturn(firstname);
		when(user.getLastname()).thenReturn(lastname);
		when(user.getEmailAddress()).thenReturn(username + "@nowhere.tld");
		when(user.getUuid()).thenReturn(USER_EDITOR_UUID);
		when(user.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD);
		when(user.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW);
		if (creator != null) {
			when(user.getCreator()).thenReturn(creator);
			when(user.getEditor()).thenReturn(creator);
		}
		when(user.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal());
		when(user.getElementVersion()).thenReturn(UUID_1);
		return user;
	}
<commit_msg>Fix mock<commit_after>package com.gentics.mesh.mock;

import static com.gentics.mesh.example.AbstractExamples.TIMESTAMP_NEW;
import static com.gentics.mesh.example.AbstractExamples.TIMESTAMP_OLD;
import static com.gentics.mesh.example.ExampleUuids.GROUP_CLIENT_UUID;
import static com.gentics.mesh.example.ExampleUuids.LANGUAGE_UUID;
import static com.gentics.mesh.example.ExampleUuids.MICROSCHEMA_UUID;
import static com.gentics.mesh.example.ExampleUuids.NODE_DELOREAN_UUID;
import static com.gentics.mesh.example.ExampleUuids.PROJECT_DEMO2_UUID;
import static com.gentics.mesh.example.ExampleUuids.PROJECT_DEMO_UUID;
import static com.gentics.mesh.example.ExampleUuids.ROLE_CLIENT_UUID;
import static com.gentics.mesh.example.ExampleUuids.SCHEMA_VEHICLE_UUID;
import static com.gentics.mesh.example.ExampleUuids.TAGFAMILY_FUELS_UUID;
import static com.gentics.mesh.example.ExampleUuids.TAG_BLUE_UUID;
import static com.gentics.mesh.example.ExampleUuids.USER_EDITOR_UUID;
import static com.gentics.mesh.example.ExampleUuids.UUID_1;
import static com.gentics.mesh.example.ExampleUuids.UUID_2;
import static com.gentics.mesh.example.ExampleUuids.UUID_3;
import static com.gentics.mesh.example.ExampleUuids.UUID_4;
import static com.gentics.mesh.example.ExampleUuids.UUID_5;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.mockito.Mockito;

import com.gentics.mesh.core.data.Group;
import com.gentics.mesh.core.data.Language;
import com.gentics.mesh.core.data.NodeGraphFieldContainer;
import com.gentics.mesh.core.data.Project;
import com.gentics.mesh.core.data.Role;
import com.gentics.mesh.core.data.Tag;
import com.gentics.mesh.core.data.TagFamily;
import com.gentics.mesh.core.data.User;
import com.gentics.mesh.core.data.node.Micronode;
import com.gentics.mesh.core.data.node.Node;
import com.gentics.mesh.core.data.node.field.BooleanGraphField;
import com.gentics.mesh.core.data.node.field.DateGraphField;
import com.gentics.mesh.core.data.node.field.HtmlGraphField;
import com.gentics.mesh.core.data.node.field.NumberGraphField;
import com.gentics.mesh.core.data.node.field.StringGraphField;
import com.gentics.mesh.core.data.node.field.list.BooleanGraphFieldList;
import com.gentics.mesh.core.data.node.field.list.DateGraphFieldList;
import com.gentics.mesh.core.data.node.field.list.HtmlGraphFieldList;
import com.gentics.mesh.core.data.node.field.list.NodeGraphFieldList;
import com.gentics.mesh.core.data.node.field.list.NumberGraphFieldList;
import com.gentics.mesh.core.data.node.field.list.StringGraphFieldList;
import com.gentics.mesh.core.data.node.field.nesting.MicronodeGraphField;
import com.gentics.mesh.core.data.node.field.nesting.NodeGraphField;
import com.gentics.mesh.core.data.relationship.GraphPermission;
import com.gentics.mesh.core.data.schema.Microschema;
import com.gentics.mesh.core.data.schema.MicroschemaVersion;
import com.gentics.mesh.core.data.schema.Schema;
import com.gentics.mesh.core.data.schema.SchemaVersion;
import com.gentics.mesh.core.data.search.UpdateDocumentEntry;
import com.gentics.mesh.core.data.search.context.impl.GenericEntryContextImpl;
import com.gentics.mesh.core.rest.microschema.MicroschemaVersionModel;
import com.gentics.mesh.core.rest.microschema.impl.MicroschemaModelImpl;
import com.gentics.mesh.core.rest.schema.SchemaVersionModel;
import com.gentics.mesh.core.rest.schema.impl.BooleanFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.DateFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.HtmlFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.ListFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.MicronodeFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.NodeFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.NumberFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.SchemaModelImpl;
import com.gentics.mesh.core.rest.schema.impl.StringFieldSchemaImpl;
import com.gentics.mesh.madl.traversal.TraversalResult;

public final class TestMocks {

	private TestMocks() {

	}

	public static Project mockProject(User user) {
		Project project = mock(Project.class);
		when(project.getUuid()).thenReturn(PROJECT_DEMO2_UUID);
		when(project.getName()).thenReturn("dummyProject");
		when(project.getCreator()).thenReturn(user);
		when(project.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD);
		when(project.getEditor()).thenReturn(user);
		when(project.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW);
		when(project.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal());
		when(project.getElementVersion()).thenReturn(UUID_1);
		return project;
	}

	public static Language mockLanguage(String code) {
		Language language = mock(Language.class);
		when(language.getUuid()).thenReturn(LANGUAGE_UUID);
		when(language.getLanguageTag()).thenReturn("de");
		when(language.getElementVersion()).thenReturn(UUID_2);
		return language;
	}

	public static Node mockNodeBasic(String schemaType, User user) {
		Node node = mock(Node.class);
		when(node.getUuid()).thenReturn(NODE_DELOREAN_UUID);
		Schema schemaContainer = mockSchemaContainer(schemaType, user);
		when(node.getSchemaContainer()).thenReturn(schemaContainer);
		return node;
	}

	public static Micronode mockMicronode(String microschemaName, User user) {
		Micronode micronode = mock(Micronode.class);
		when(micronode.getUuid()).thenReturn(UUID_1);
		Microschema microschemaContainer = mockMicroschemaContainer(microschemaName, user);
		MicroschemaVersion latestVersion = microschemaContainer.getLatestVersion();
		when(micronode.getSchemaContainerVersion()).thenReturn(latestVersion);
		MicroschemaVersionModel microschema = microschemaContainer.getLatestVersion().getSchema();
		when(micronode.getSchemaContainerVersion().getSchema()).thenReturn(microschema);

		// longitude field
		NumberGraphField longitudeField = mock(NumberGraphField.class);
		when(longitudeField.getNumber()).thenReturn(16.373063840833);
		when(micronode.getNumber("longitude")).thenReturn(longitudeField);

		// latitude field
		NumberGraphField latitudeField = mock(NumberGraphField.class);
		when(latitudeField.getNumber()).thenReturn(16.373063840833);
		when(micronode.getNumber("latitude")).thenReturn(latitudeField);
		when(micronode.getElementVersion()).thenReturn(UUID_3);
		return micronode;
	}

	public static Role mockRole(String roleName, User creator) {
		Role role = mock(Role.class);
		when(role.getCreator()).thenReturn(creator);
		when(role.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD);
		when(role.getEditor()).thenReturn(creator);
		when(role.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW);
		when(role.getName()).thenReturn(roleName);
		when(role.getUuid()).thenReturn(ROLE_CLIENT_UUID);
		when(role.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal());
		when(role.getElementVersion()).thenReturn(UUID_4);
		return role;
	}

	public static Group mockGroup(String groupName, User creator) {
		Group group = mock(Group.class);
		when(group.getCreator()).thenReturn(creator);
		when(group.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD);
		when(group.getEditor()).thenReturn(creator);
		when(group.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW);
		when(group.getName()).thenReturn(groupName);
		when(group.getUuid()).thenReturn(GROUP_CLIENT_UUID);
		when(group.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal());
		when(group.getElementVersion()).thenReturn(UUID_5);
		return group;
	}

	public static User mockUser(String username, String firstname, String lastname) {
		return mockUser(username, firstname, lastname, null);
	}

	public static User mockUser(String username, String firstname, String lastname, User creator) {
		User user = mock(User.class);
		when(user.toUser()).thenReturn(user);
		when(user.getUsername()).thenReturn(username);
		when(user.getFirstname()).thenReturn(firstname);
		when(user.getLastname()).thenReturn(lastname);
		when(user.getEmailAddress()).thenReturn(username + "@nowhere.tld");
		when(user.getUuid()).thenReturn(USER_EDITOR_UUID);
		when(user.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD);
		when(user.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW);
		if (creator != null) {
			when(user.getCreator()).thenReturn(creator);
			when(user.getEditor()).thenReturn(creator);
		}
		when(user.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal());
		when(user.getElementVersion()).thenReturn(UUID_1);
		return user;
	}

{'fraction_non_alphanumeric': 0.12347463998611995, 'fraction_numerical': 0.004858018622404719, 'mean_word_length': 7.03905160390516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4152870', 'n_tokens_mistral': 5775, 'n_tokens_neox': 5567, 'n_words': 680}