<commit_before>/*
 */

package com.googlecode.objectify.test;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.test.entity.Trivial;
import com.googlecode.objectify.test.util.TestBase;
import org.junit.jupiter.api.Test;

import static com.google.common.truth.Truth.assertThat;

/**
 * Tests of Key behavior
 *
 * @author <NAME> <<EMAIL>>
 */
class KeyTests extends TestBase {
	private static class NoEntity {
	}

	/** */
	@Test
	void kindOfClassWithoutEntityAnnotationIsClassSimpleName() throws Exception {
		final Key<NoEntity> key = Key.create(NoEntity.class, 123L);
		assertThat(key.getKind()).isEqualTo(NoEntity.class.getSimpleName());
	}

	/** */
	@Test
	void canRoundtripBothKindsOfUrlSafeStrings() throws Exception {
		final Key<Trivial> key = Key.create(Trivial.class, 123L);

		final String urlSafe = key.toUrlSafe();
		final Key<Trivial> urlSafeKey = Key.create(urlSafe);
		assertThat(urlSafeKey).isEqualTo(key);

		final String legacyUrlSafe = key.toLegacyUrlSafe();
		final Key<Trivial> legacyUrlSafeKey = Key.create(legacyUrlSafe);
		assertThat(legacyUrlSafeKey).isEqualTo(key);

		assertThat(urlSafe).isNotEqualTo(legacyUrlSafe);
	}

	/** */
	@Test
	void canRoundtripBothKindsOfUrlSafeStringsWithNamespace() throws Exception {
		final Key<Trivial> key = Key.create("namespace", Trivial.class, 123L);

		final String urlSafe = key.toUrlSafe();
		final Key<Trivial> urlSafeKey = Key.create(urlSafe);
		assertThat(urlSafeKey).isEqualTo(key);

		final String legacyUrlSafe = key.toLegacyUrlSafe();
		final Key<Trivial> legacyUrlSafeKey = Key.create(legacyUrlSafe);
		assertThat(legacyUrlSafeKey).isEqualTo(key);

		assertThat(urlSafe).isNotEqualTo(legacyUrlSafe);
	}
}<commit_msg>Add a test for issue #477<commit_after>/*
 */

package com.googlecode.objectify.test;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.test.entity.Trivial;
import com.googlecode.objectify.test.util.TestBase;
import org.junit.jupiter.api.Test;

import static com.google.common.truth.Truth.assertThat;
import static com.googlecode.objectify.ObjectifyService.factory;
import static com.googlecode.objectify.ObjectifyService.ofy;

/**
 * Tests of Key behavior
 *
 * @author <NAME> <<EMAIL>>
 */
class KeyTests extends TestBase {
	private static class NoEntity {
	}

	/** */
	@Test
	void kindOfClassWithoutEntityAnnotationIsClassSimpleName() throws Exception {
		final Key<NoEntity> key = Key.create(NoEntity.class, 123L);
		assertThat(key.getKind()).isEqualTo(NoEntity.class.getSimpleName());
	}

	/** */
	@Test
	void canRoundtripBothKindsOfUrlSafeStrings() throws Exception {
		final Key<Trivial> key = Key.create(Trivial.class, 123L);

		final String urlSafe = key.toUrlSafe();
		final Key<Trivial> urlSafeKey = Key.create(urlSafe);
		assertThat(urlSafeKey).isEqualTo(key);

		final String legacyUrlSafe = key.toLegacyUrlSafe();
		final Key<Trivial> legacyUrlSafeKey = Key.create(legacyUrlSafe);
		assertThat(legacyUrlSafeKey).isEqualTo(key);

		assertThat(urlSafe).isNotEqualTo(legacyUrlSafe);
	}

	/** */
	@Test
	void canRoundtripBothKindsOfUrlSafeStringsWithNamespace() throws Exception {
		final Key<Trivial> key = Key.create("namespace", Trivial.class, 123L);

		final String urlSafe = key.toUrlSafe();
		final Key<Trivial> urlSafeKey = Key.create(urlSafe);
		assertThat(urlSafeKey).isEqualTo(key);

		final String legacyUrlSafe = key.toLegacyUrlSafe();
		final Key<Trivial> legacyUrlSafeKey = Key.create(legacyUrlSafe);
		assertThat(legacyUrlSafeKey).isEqualTo(key);

		assertThat(urlSafe).isNotEqualTo(legacyUrlSafe);
	}

	@Test
	void urlsafeWorksForSavingAndLoading() throws Exception {
		factory().register(Trivial.class);

		final Trivial triv = new Trivial(123L, "foo", 5);
		final Key<Trivial> savedKey = ofy().save().entity(triv).now();

		final String urlSafe = savedKey.toUrlSafe();
		final Key<Trivial> reconstituted = Key.create(urlSafe);

		ofy().clear();
		final Trivial loaded = ofy().load().key(reconstituted).now();
		assertThat(loaded).isEqualTo(triv);
	}
}
{'fraction_non_alphanumeric': 0.1274632077824894, 'fraction_numerical': 0.006235969069593414, 'mean_word_length': 5.584564860426929, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '4438708', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1317, 'n_words': 240}