<commit_before>/*
 * Copyright (c) 2006-2011 <NAME>
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit;

import java.net.*;
import java.util.ArrayList;
import java.util.*;

import static java.util.Arrays.*;
import static org.junit.Assert.*;
import org.junit.*;

public final class InputTest
{
   static class Collaborator
   {
      int getInt() { return 1; }
      short getShort() { return 56; }
      int getAnotherInt(String s) { return s.hashCode(); }
      String getString() { return ""; }
      List<Integer> getListOfIntegers() { return null; }
      List<Boolean> getListOfBooleans() { return null; }
      static Map<String, List<Long>> getMapFromStringToListOfLongs() { return null; }
      Socket getSocket() { return null; }
      void throwSocketException() throws SocketException, IllegalAccessException {}
      <E> List<E> genericMethod() { return null; }
   }

   @Mocked Collaborator mock;

   @Test
   public void specifyDefaultReturnValues()
   {
      new Expectations()
      {
         @Input final int someIntValue = 123;
         @Input String uniqueId = "Abc5"; // fields not required to be final
         @Input final List<Integer> userIds = asList(4, 56, 278);
         @Input final List<Boolean> flags = asList(true, false, true);
         @Input final Map<String, List<Long>> complexData = new HashMap<String, List<Long>>() {{
            put("empty", new ArrayList<Long>());
            put("one", asList(1L));
            put("two", asList(10L, 20L));
         }};
         @Input Socket aSocket; // created with public no-args constructor and automatically assigned
      };

      assertEquals(123, mock.getInt());
      assertEquals(0, mock.getShort());
      assertEquals(123, mock.getAnotherInt("a"));
      assertEquals("Abc5", mock.getString());
      assertEquals(asList(4, 56, 278), mock.getListOfIntegers());
      assertEquals(asList(true, false, true), mock.getListOfBooleans());
      assertNotNull(mock.getSocket());

      Map<String, List<Long>> data = Collaborator.getMapFromStringToListOfLongs();
      assertTrue(data.get("empty").isEmpty());
      assertTrue(data.get("one").contains(1L));
      assertEquals(2, data.get("two").size());
      assertEquals(10L, (long) data.get("two").get(0));
      assertEquals(20L, (long) data.get("two").get(1));

      assertEquals("Abc5", mock.getString());
      assertEquals(123, mock.getInt());
      assertEquals(123, mock.getAnotherInt("b"));
   }

   @Test
   public void specifyUniqueReturnValueForMethodWithGenericReturnType()
   {
      new Expectations()
      {
         @Input final List<String> names = asList("a", "b");
      };

      List<String> names = mock.genericMethod();

      assertEquals(asList("a", "b"), names);
   }<commit_msg>Added a few verifications to existing test.<commit_after>/*
 * Copyright (c) 2006-2011 <NAME>
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit;

import java.net.*;
import java.util.ArrayList;
import java.util.*;

import static java.util.Arrays.*;
import static org.junit.Assert.*;
import org.junit.*;

public final class InputTest
{
   static class Collaborator
   {
      int getInt() { return 1; }
      short getShort() { return 56; }
      int getAnotherInt(String s) { return s.hashCode(); }
      String getString() { return ""; }
      private String getAnotherString() { return ""; }
      List<Integer> getListOfIntegers() { return null; }
      List<Boolean> getListOfBooleans() { return null; }
      static Map<String, List<Long>> getMapFromStringToListOfLongs() { return null; }
      Socket getSocket() { return null; }
      void throwSocketException() throws SocketException, IllegalAccessException {}
      <E> List<E> genericMethod() { return null; }
   }

   @Mocked Collaborator mock;

   @Test
   public void specifyDefaultReturnValues()
   {
      new NonStrictExpectations()
      {
         @Input final int someIntValue = 123;
         @Input String uniqueId = "Abc5"; // fields not required to be final
         @Input final List<Integer> userIds = asList(4, 56, 278);
         @Input final List<Boolean> flags = asList(true, false, true);
         @Input final Map<String, List<Long>> complexData = new HashMap<String, List<Long>>() {{
            put("empty", new ArrayList<Long>());
            put("one", asList(1L));
            put("two", asList(10L, 20L));
         }};
         @Input Socket aSocket; // created with public no-args constructor and automatically assigned

         {
            mock.getAnotherInt("c"); result = 45;
            mock.getAnotherString(); result = null;
         }
      };

      assertEquals(123, mock.getInt());
      assertEquals(0, mock.getShort());
      assertEquals(123, mock.getAnotherInt("a"));
      assertEquals(45, mock.getAnotherInt("c"));
      assertEquals("Abc5", mock.getString());
      assertNull(mock.getAnotherString());
      assertEquals(asList(4, 56, 278), mock.getListOfIntegers());
      assertEquals(asList(true, false, true), mock.getListOfBooleans());
      assertNotNull(mock.getSocket());

      Map<String, List<Long>> data = Collaborator.getMapFromStringToListOfLongs();
      assertTrue(data.get("empty").isEmpty());
      assertTrue(data.get("one").contains(1L));
      assertEquals(2, data.get("two").size());
      assertEquals(10L, (long) data.get("two").get(0));
      assertEquals(20L, (long) data.get("two").get(1));

      assertEquals("Abc5", mock.getString());
      assertEquals(123, mock.getInt());
      assertEquals(123, mock.getAnotherInt("b"));
      assertNull(mock.getAnotherString());
   }

   @Test
   public void specifyUniqueReturnValueForMethodWithGenericReturnType()
   {
      new Expectations()
      {
         @Input final List<String> names = asList("a", "b");
      };

      List<String> names = mock.genericMethod();

      assertEquals(asList("a", "b"), names);
   }
{'fraction_non_alphanumeric': 0.1434108527131783, 'fraction_numerical': 0.019211324570273004, 'mean_word_length': 3.182522903453136, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, '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': '2990794', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1689, 'n_words': 430}