私はここで私が間違っていることを理解できないようです:
これは私がテストしている方法です:
public List<Mo> filterDuplicatesByName(List<Mo> dbMos) {
List<String> names = Lists.newArrayList();
for(Mo mo : dbMos) {
try {
String name = mo.getName();
if(names.contains(name)) {
dbMos.remove(mo);
} else {
names.add(name);
}
} catch (DataLayerException ex) {
dbMos.remove(mo);
}
}
return dbMos;
}
そして、これは私のテストクラスです:
package com.rondavu.wt.service.recommendations;
import com.google.common.collect.Lists;
import com.rondavu.data.api.Mo;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
public class RecommendationsUtilsTest {
Mockery context = new Mockery();
RecommendationsUtils recommendationsUtils = new RecommendationsUtils();
final Mo mo = context.mock(Mo.class);
@Test
public void testFilterDuplicatesByName_oneMo() throws DataLayerException {
List<Mo> input = Lists.newArrayList(mo);
List<Mo> expected = Lists.newArrayList(mo);
context.checking(new Expectations() {{
oneOf (mo).getName(); will(returnValue("Mo 1"));
}});
List<Mo> actual = recommendationsUtils.filterDuplicatesByName(input);
context.assertIsSatisfied();
assertEquals(expected, actual);
}
}
テストを実行すると、次の出力が得られます。
unexpected invocation: mo.getName()
no expectations specified: did you...
- forget to start an expectation with a cardinality clause?
- call a mocked method to specify the parameter of an expectation?
what happened before this: nothing!
[stack trace]
私はjMockにかなり慣れていません。また、Javaは一般的に私の最強の言語ではありませんが、oneOf (mo).getName()
その呼び出しを期待するようになると思いました。私はここで何が間違っているのですか?