<commit_before>// Copyright 2016 The Nomulus Authors. All Rights Reserved.
//
// 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 google.registry.tools;

import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;

import com.google.appengine.tools.remoteapi.RemoteApiException;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import com.googlecode.objectify.Key;
import google.registry.model.domain.LrpTokenEntity;
import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.DeterministicStringGenerator;
import google.registry.testing.DeterministicStringGenerator.Rule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeSleeper;
import google.registry.util.Retrier;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;

/** Unit tests for {@link CreateLrpTokensCommand}. */
public class CreateLrpTokensCommandTest extends CommandTestCase<CreateLrpTokensCommand> {

  DeterministicStringGenerator stringGenerator =
      new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
  File assigneeFile;
  String assigneeFilePath;

  @Before
  public void init() throws IOException {
    assigneeFile = tmpDir.newFile("lrp_assignees.txt");
    assigneeFilePath = assigneeFile.getPath();
    command.stringGenerator = stringGenerator;
    command.retrier =
        new Retrier(new FakeSleeper(new FakeClock(DateTime.parse("2000-01-01TZ"))), 3);
    createTld("tld");
  }

  @Test
  public void testSuccess_oneAssignee() throws Exception {
    runCommand("--assignee=domain.tld", "--tlds=tld");
    assertLrpTokens(
        createToken("<KEY>", "domain.tld", ImmutableSet.of("tld"), null, null));
    assertInStdout("domain.tld,LRP_abcdefghijklmnop");
  }

  @Test
  public void testSuccess_oneAssignee_retry() throws Exception {
    CreateLrpTokensCommand spyCommand = spy(command);
    RemoteApiException fakeException = new RemoteApiException("foo", "foo", "foo", new Exception());
    doThrow(fakeException)
        .doThrow(fakeException)
        .doCallRealMethod()
        .when(spyCommand)
        .saveTokens(any());
    runCommand("--assignee=domain.tld", "--tlds=tld");
    assertLrpTokens(
        createToken("<KEY>", "domain.tld", ImmutableSet.of("tld"), null, null));
    assertInStdout("domain.tld,LRP_abcdefghijklmnop");
  }<commit_msg>Fix Nomulus build error in JDK7<commit_after>// Copyright 2016 The Nomulus Authors. All Rights Reserved.
//
// 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 google.registry.tools;

import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;

import com.google.appengine.tools.remoteapi.RemoteApiException;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import com.googlecode.objectify.Key;
import google.registry.model.domain.LrpTokenEntity;
import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.DeterministicStringGenerator;
import google.registry.testing.DeterministicStringGenerator.Rule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeSleeper;
import google.registry.util.Retrier;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

/** Unit tests for {@link CreateLrpTokensCommand}. */
public class CreateLrpTokensCommandTest extends CommandTestCase<CreateLrpTokensCommand> {

  DeterministicStringGenerator stringGenerator =
      new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
  File assigneeFile;
  String assigneeFilePath;

  @Before
  public void init() throws IOException {
    assigneeFile = tmpDir.newFile("lrp_assignees.txt");
    assigneeFilePath = assigneeFile.getPath();
    command.stringGenerator = stringGenerator;
    command.retrier =
        new Retrier(new FakeSleeper(new FakeClock(DateTime.parse("2000-01-01TZ"))), 3);
    createTld("tld");
  }

  @Test
  public void testSuccess_oneAssignee() throws Exception {
    runCommand("--assignee=domain.tld", "--tlds=tld");
    assertLrpTokens(
        createToken("<KEY>", "domain.tld", ImmutableSet.of("tld"), null, null));
    assertInStdout("domain.tld,LRP_abcdefghijklmnop");
  }

  @Test
  public void testSuccess_oneAssignee_retry() throws Exception {
    CreateLrpTokensCommand spyCommand = spy(command);
    RemoteApiException fakeException = new RemoteApiException("foo", "foo", "foo", new Exception());
    doThrow(fakeException)
        .doThrow(fakeException)
        .doCallRealMethod()
        .when(spyCommand)
        .saveTokens(Mockito.<ImmutableSet<LrpTokenEntity>>any());
    runCommand("--assignee=domain.tld", "--tlds=tld");
    assertLrpTokens(
        createToken("<KEY>", "domain.tld", ImmutableSet.of("tld"), null, null));
    assertInStdout("domain.tld,LRP_abcdefghijklmnop");
  }
{'fraction_non_alphanumeric': 0.108708357685564, 'fraction_numerical': 0.005406195207481005, 'mean_word_length': 4.895779500430663, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5106443', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1996, 'n_words': 472}