Skip to content

Commit

Permalink
New tests for mockito#1917
Browse files Browse the repository at this point in the history
  • Loading branch information
sectorpre committed Oct 20, 2023
1 parent eb70a9e commit e917be8
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.mockito.internal.configuration.injection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.HashMap;

import static org.junit.Assert.assertEquals;

@RunWith(MockitoJUnitRunner.class)
public class InjectionFourHashmapsWithDifferentTypeParameterTest {
public static class TwoListsTest {
private final HashMap<String, String> hashmap1;
private final HashMap<String, Integer> hashmap2;
private final HashMap<Float, Integer> hashmap3;
private final HashMap<Float, Float> hashmap4;

public TwoListsTest(
HashMap<String, String> hashmap1, HashMap<String, Integer> hashmap2, HashMap<Float, Integer> hashmap3, HashMap<Float, Float> hashmap4) {
this.hashmap1 = hashmap1;
this.hashmap2 = hashmap2;
this.hashmap3 = hashmap3;
this.hashmap4 = hashmap4;
}

public HashMap<String, String> getHashmap1() {
return hashmap1;
}

public HashMap<String, Integer> getHashmap2() {
return hashmap2;
}

public HashMap<Float, Integer> getHashmap3() {
return hashmap3;
}

public HashMap<Float, Float> getHashmap4() {
return hashmap4;
}
}

@Mock(strictness = Mock.Strictness.LENIENT)
HashMap<String, String> mockhashmap1;

@Mock(strictness = Mock.Strictness.LENIENT)
HashMap<String, Integer> mockhashmap2;

@Mock(strictness = Mock.Strictness.LENIENT)
HashMap<Float, Float> mockhashmap4;
@Mock(strictness = Mock.Strictness.LENIENT)
HashMap<Float, Integer> mockhashmap3;

@InjectMocks
TwoListsTest productionClass;
@Test
public void test() {
assertEquals("mockhashmap1", productionClass.getHashmap1().toString());
assertEquals("mockhashmap2", productionClass.getHashmap2().toString());
assertEquals("mockhashmap3", productionClass.getHashmap3().toString());
assertEquals("mockhashmap4", productionClass.getHashmap4().toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.mockito.internal.configuration.injection;

import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.List;

@RunWith(MockitoJUnitRunner.class)
public class InjectionTwoListsWithDifferentTypeParameterTest {
public static class TwoListsTest {
private final List<Integer> integerList;
private final List<String> stringList;

TwoListsTest(List<String> argumentStringList, List<Integer> argumentIntegerList) {
this.stringList = argumentStringList;
this.integerList = argumentIntegerList;
}

public List<Integer> getIntegerList() {
return integerList;
}

public List<String> getStringList() {
return stringList;
}
}
@InjectMocks
TwoListsTest productionClass;

@Mock(strictness = Mock.Strictness.LENIENT)
List<Integer> mockIntegerList;

@Mock(strictness = Mock.Strictness.LENIENT)
List<String> mockStringList;
@Test
public void test() {
System.out.println(productionClass.getIntegerList());
System.out.println(productionClass.getStringList());
assertEquals("mockIntegerList", productionClass.getIntegerList().toString());
assertEquals("mockStringList", productionClass.getStringList().toString());
}
}

0 comments on commit e917be8

Please sign in to comment.