<commit_before>/*
 * JMockit Expectations
 * Copyright (c) 2006-2010 <NAME>
 * All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package mockit;

import java.util.*;

import org.junit.*;

import org.hamcrest.*;
import org.hamcrest.core.*;

public final class ExpectationsWithArgMatchersTest
{
   @SuppressWarnings({"UnusedDeclaration"})
   static class Collaborator
   {
      void setValue(int value) {}
      void setValue(double value) {}
      void setValue(float value) {}

      List<?> complexOperation(Object input1, Object... otherInputs)
      {
         return input1 == null ? Collections.emptyList() : Arrays.asList(otherInputs);
      }

      final void simpleOperation(int a, String b, Date c) {}
   }

   @Mocked private Collaborator mock;

   @Test(expected = AssertionError.class)
   public void replayWithUnexpectedMethodArgument()
   {
      new Expectations()
      {
         {
            mock.simpleOperation(2, "test", null);
         }
      };

      mock.simpleOperation(2, "other", null);
   }

   @Test(expected = AssertionError.class)
   public void replayWithUnexpectedNullArgument()
   {
      new Expectations()
      {
         {
            mock.simpleOperation(2, "test", null);
         }
      };

      mock.simpleOperation(2, null, null);
   }

   @Test(expected = AssertionError.class)
   public void replayWithUnexpectedMethodArgumentUsingMatcher()
   {
      new Expectations()
      {
         {
            mock.setValue(withEqual(-1));
         }
      };

      mock.setValue(1);
   }

   @Test(expected = AssertionError.class)
   public void expectInvocationWithDifferentThanExpectedProxyArgument()
   {
      new Expectations()
      {
         Runnable mock2;

         {
            mock.complexOperation(mock2);
         }
      };

      mock.complexOperation(null);
   }

   @Test
   public void expectInvocationWithAnyArgument()
   {
      new Expectations()
      {
         {
            mock.setValue(withAny(5));
         }
      };

      mock.setValue(3);
   }

   @Test
   public void expectInvocationWithEqualArgument()
   {
      new Expectations()
      {
         {
            mock.setValue(withEqual(3));
         }
      };

      mock.setValue(3);
   }

   @Test
   public void expectInvocationWithEqualDoubleArgument()
   {
      new Expectations()
      {
         {
            mock.setValue(withEqual(3.0, 0.01)); repeats(3);
         }
      };

      mock.setValue(3.0);
      mock.setValue(3.01);
      mock.setValue(2.99);
   }

   @Test
   public void expectInvocationWithEqualFloatArgument()
   {
      new Expectations()
      {
         {
            mock.setValue(withEqual(3.0F, 0.01)); repeats(3);
         }
      };

      mock.setValue(3.0F);
      mock.setValue(3.01F);
      mock.setValue(2.99F);
   }

   @Test(expected = AssertionError.class)
   public void expectInvocationWithEqualFloatArgumentButWithDifferentReplayValue()
   {
      new Expectations()
      {
         {
            mock.setValue(withEqual(3.0F, 0.01));
         }
      };

      mock.setValue(3.02F);
   }

   @Test
   public void expectInvocationWithNotEqualArgument()<commit_msg>Replaced uses of "returns(obj)" with assignments to "result"; fixed warnings.<commit_after>/*
 * JMockit Expectations
 * Copyright (c) 2006-2010 <NAME>
 * All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package mockit;

import java.util.*;

import org.junit.*;

import org.hamcrest.*;
import org.hamcrest.core.*;

public final class ExpectationsWithArgMatchersTest
{
   @SuppressWarnings({"UnusedDeclaration"})
   static class Collaborator
   {
      void setValue(int value) {}
      void setValue(double value) {}
      void setValue(float value) {}

      List<?> complexOperation(Object input1, Object... otherInputs)
      {
         return input1 == null ? Collections.emptyList() : Arrays.asList(otherInputs);
      }

      final void simpleOperation(int a, String b, Date c) {}
   }

   @Mocked private Collaborator mock;

   @Test(expected = AssertionError.class)
   public void replayWithUnexpectedMethodArgument()
   {
      new Expectations()
      {
         {
            mock.simpleOperation(2, "test", null);
         }
      };

      mock.simpleOperation(2, "other", null);
   }

   @Test(expected = AssertionError.class)
   public void replayWithUnexpectedNullArgument()
   {
      new Expectations()
      {
         {
            mock.simpleOperation(2, "test", null);
         }
      };

      mock.simpleOperation(2, null, null);
   }

   @Test(expected = AssertionError.class)
   public void replayWithUnexpectedMethodArgumentUsingMatcher()
   {
      new Expectations()
      {
         {
            mock.setValue(withEqual(-1));
         }
      };

      mock.setValue(1);
   }

   @Test(expected = AssertionError.class)
   public void expectInvocationWithDifferentThanExpectedProxyArgument()
   {
      new Expectations()
      {
         Runnable mock2;

         {
            mock.complexOperation(mock2);
         }
      };

      mock.complexOperation(null);
   }

   @Test
   public void expectInvocationWithAnyArgument()
   {
      new Expectations()
      {
         {
            mock.setValue(anyInt);
         }
      };

      mock.setValue(3);
   }

   @Test
   public void expectInvocationWithEqualArgument()
   {
      new Expectations()
      {
         {
            mock.setValue(withEqual(3));
         }
      };

      mock.setValue(3);
   }

   @Test
   public void expectInvocationWithEqualDoubleArgument()
   {
      new Expectations()
      {
         {
            mock.setValue(withEqual(3.0, 0.01)); times = 3;
         }
      };

      mock.setValue(3.0);
      mock.setValue(3.01);
      mock.setValue(2.99);
   }

   @Test
   public void expectInvocationWithEqualFloatArgument()
   {
      new Expectations()
      {
         {
            mock.setValue(withEqual(3.0F, 0.01)); times = 3;
         }
      };

      mock.setValue(3.0F);
      mock.setValue(3.01F);
      mock.setValue(2.99F);
   }

   @Test(expected = AssertionError.class)
   public void expectInvocationWithEqualFloatArgumentButWithDifferentReplayValue()
   {
      new Expectations()
      {
         {
            mock.setValue(withEqual(3.0F, 0.01));
         }
      };

      mock.setValue(3.02F);
   }

   @Test
   public void expectInvocationWithNotEqualArgument()
{'fraction_non_alphanumeric': 0.0966903073286052, 'fraction_numerical': 0.013593380614657211, 'mean_word_length': 2.429671665991082, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1212322', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2352, 'n_words': 652}