How to use matches method of org.easymock.EasyMock class

Best Easymock code snippet using org.easymock.EasyMock.matches

Source:RecommenderJobTest.java Github

copy

Full Screen

...167 */168 private static VectorOrPrefWritable vectorOfVectorOrPrefWritableMatches(final Vector.Element... elements) {169 EasyMock.reportMatcher(new IArgumentMatcher() {170 @Override171 public boolean matches(Object argument) {172 if (argument instanceof VectorOrPrefWritable) {173 Vector v = ((VectorOrPrefWritable) argument).getVector();174 return MathHelper.consistsOf(v, elements);175 }176 return false;177 }178 @Override179 public void appendTo(StringBuffer buffer) {}180 });181 return null;182 }183 /**184 * tests {@link UserVectorSplitterMapper}185 */186 @Test187 public void testUserVectorSplitterMapper() throws Exception {188 Mapper<VarLongWritable,VectorWritable, VarIntWritable,VectorOrPrefWritable>.Context context =189 EasyMock.createMock(Mapper.Context.class);190 context.write(EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatches(123L, 0.5f));191 context.write(EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f));192 EasyMock.replay(context);193 UserVectorSplitterMapper mapper = new UserVectorSplitterMapper();194 setField(mapper, "maxPrefsPerUserConsidered", 10);195 RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);196 vector.set(34, 0.5);197 vector.set(56, 0.7);198 mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context);199 EasyMock.verify(context);200 }201 /**202 * verifies a preference in a {@link VectorOrPrefWritable}203 */204 private static VectorOrPrefWritable prefOfVectorOrPrefWritableMatches(final long userID, final float prefValue) {205 EasyMock.reportMatcher(new IArgumentMatcher() {206 @Override207 public boolean matches(Object argument) {208 if (argument instanceof VectorOrPrefWritable) {209 VectorOrPrefWritable pref = (VectorOrPrefWritable) argument;210 return pref.getUserID() == userID && pref.getValue() == prefValue;211 }212 return false;213 }214 @Override215 public void appendTo(StringBuffer buffer) {}216 });217 return null;218 }219 /**220 * tests {@link UserVectorSplitterMapper} in the special case that some userIDs shall be excluded221 */222 @Test223 public void testUserVectorSplitterMapperUserExclusion() throws Exception {224 Mapper<VarLongWritable,VectorWritable, VarIntWritable,VectorOrPrefWritable>.Context context =225 EasyMock.createMock(Mapper.Context.class);226 context.write(EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatches(123L, 0.5f));227 context.write(EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f));228 EasyMock.replay(context);229 FastIDSet usersToRecommendFor = new FastIDSet();230 usersToRecommendFor.add(123L);231 UserVectorSplitterMapper mapper = new UserVectorSplitterMapper();232 setField(mapper, "maxPrefsPerUserConsidered", 10);233 setField(mapper, "usersToRecommendFor", usersToRecommendFor);234 RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);235 vector.set(34, 0.5);236 vector.set(56, 0.7);237 mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context);238 mapper.map(new VarLongWritable(456L), new VectorWritable(vector), context);239 EasyMock.verify(context);240 }241 /**242 * tests {@link UserVectorSplitterMapper} in the special case that the number of preferences to be considered243 * is less than the number of available preferences244 */245 @Test246 public void testUserVectorSplitterMapperOnlySomePrefsConsidered() throws Exception {247 Mapper<VarLongWritable,VectorWritable, VarIntWritable,VectorOrPrefWritable>.Context context =248 EasyMock.createMock(Mapper.Context.class);249 context.write(EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatchesNaN(123L));250 context.write(EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f));251 EasyMock.replay(context);252 UserVectorSplitterMapper mapper = new UserVectorSplitterMapper();253 setField(mapper, "maxPrefsPerUserConsidered", 1);254 RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);255 vector.set(34, 0.5);256 vector.set(56, 0.7);257 mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context);258 EasyMock.verify(context);259 }260 /**261 * verifies that a preference value is NaN in a {@link VectorOrPrefWritable}262 */263 private static VectorOrPrefWritable prefOfVectorOrPrefWritableMatchesNaN(final long userID) {264 EasyMock.reportMatcher(new IArgumentMatcher() {265 @Override266 public boolean matches(Object argument) {267 if (argument instanceof VectorOrPrefWritable) {268 VectorOrPrefWritable pref = (VectorOrPrefWritable) argument;269 return pref.getUserID() == userID && Float.isNaN(pref.getValue());270 }271 return false;272 }273 @Override274 public void appendTo(StringBuffer buffer) {}275 });276 return null;277 }278 /**279 * tests {@link ToVectorAndPrefReducer}280 */281 @Test282 public void testToVectorAndPrefReducer() throws Exception {283 Reducer<VarIntWritable,VectorOrPrefWritable,VarIntWritable,VectorAndPrefsWritable>.Context context =284 EasyMock.createMock(Reducer.Context.class);285 context.write(EasyMock.eq(new VarIntWritable(1)), vectorAndPrefsWritableMatches(Arrays.asList(123L, 456L),286 Arrays.asList(1.0f, 2.0f), MathHelper.elem(3, 0.5), MathHelper.elem(7, 0.8)));287 EasyMock.replay(context);288 Vector similarityColumn = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);289 similarityColumn.set(3, 0.5);290 similarityColumn.set(7, 0.8);291 VectorOrPrefWritable itemPref1 = new VectorOrPrefWritable(123L, 1.0f);292 VectorOrPrefWritable itemPref2 = new VectorOrPrefWritable(456L, 2.0f);293 VectorOrPrefWritable similarities = new VectorOrPrefWritable(similarityColumn);294 new ToVectorAndPrefReducer().reduce(new VarIntWritable(1), Arrays.asList(itemPref1, itemPref2, similarities),295 context);296 EasyMock.verify(context);297 }298 /**299 * verifies a {@link VectorAndPrefsWritable}300 */301 private static VectorAndPrefsWritable vectorAndPrefsWritableMatches(final List<Long> userIDs,302 final List<Float> prefValues, final Vector.Element... elements) {303 EasyMock.reportMatcher(new IArgumentMatcher() {304 @Override305 public boolean matches(Object argument) {306 if (argument instanceof VectorAndPrefsWritable) {307 VectorAndPrefsWritable vectorAndPrefs = (VectorAndPrefsWritable) argument;308 if (!vectorAndPrefs.getUserIDs().equals(userIDs)) {309 return false;310 }311 if (!vectorAndPrefs.getValues().equals(prefValues)) {312 return false;313 }314 return MathHelper.consistsOf(vectorAndPrefs.getVector(), elements);315 }316 return false;317 }318 @Override319 public void appendTo(StringBuffer buffer) {}320 });321 return null;322 }323 /**324 * tests {@link ToVectorAndPrefReducer} in the error case that two similarity column vectors a supplied for the same325 * item (which should never happen)326 */327 @Test328 public void testToVectorAndPrefReducerExceptionOn2Vectors() throws Exception {329 Reducer<VarIntWritable,VectorOrPrefWritable,VarIntWritable,VectorAndPrefsWritable>.Context context =330 EasyMock.createMock(Reducer.Context.class);331 EasyMock.replay(context);332 Vector similarityColumn1 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);333 Vector similarityColumn2 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);334 VectorOrPrefWritable similarities1 = new VectorOrPrefWritable(similarityColumn1);335 VectorOrPrefWritable similarities2 = new VectorOrPrefWritable(similarityColumn2);336 try {337 new ToVectorAndPrefReducer().reduce(new VarIntWritable(1), Arrays.asList(similarities1, similarities2), context);338 fail();339 } catch (IllegalStateException e) {340 // good341 }342 EasyMock.verify(context);343 }344 /**345 * tests {@link org.apache.mahout.cf.taste.hadoop.item.ItemFilterMapper}346 */347 @Test348 public void testItemFilterMapper() throws Exception {349 Mapper<LongWritable,Text,VarLongWritable,VarLongWritable>.Context context =350 EasyMock.createMock(Mapper.Context.class);351 context.write(new VarLongWritable(34L), new VarLongWritable(12L));352 context.write(new VarLongWritable(78L), new VarLongWritable(56L));353 EasyMock.replay(context);354 ItemFilterMapper mapper = new ItemFilterMapper();355 mapper.map(null, new Text("12,34"), context);356 mapper.map(null, new Text("56,78"), context);357 EasyMock.verify(context);358 }359 /**360 * tests {@link org.apache.mahout.cf.taste.hadoop.item.ItemFilterAsVectorAndPrefsReducer}361 */362 @Test363 public void testItemFilterAsVectorAndPrefsReducer() throws Exception {364 Reducer<VarLongWritable,VarLongWritable,VarIntWritable,VectorAndPrefsWritable>.Context context =365 EasyMock.createMock(Reducer.Context.class);366 int itemIDIndex = TasteHadoopUtils.idToIndex(123L);367 context.write(EasyMock.eq(new VarIntWritable(itemIDIndex)), vectorAndPrefsForFilteringMatches(123L, 456L, 789L));368 EasyMock.replay(context);369 new ItemFilterAsVectorAndPrefsReducer().reduce(new VarLongWritable(123L), Arrays.asList(new VarLongWritable(456L),370 new VarLongWritable(789L)), context);371 EasyMock.verify(context);372 }373 static VectorAndPrefsWritable vectorAndPrefsForFilteringMatches(final long itemID, final long... userIDs) {374 EasyMock.reportMatcher(new IArgumentMatcher() {375 @Override376 public boolean matches(Object argument) {377 if (argument instanceof VectorAndPrefsWritable) {378 VectorAndPrefsWritable vectorAndPrefs = (VectorAndPrefsWritable) argument;379 Vector vector = vectorAndPrefs.getVector();380 if (vector.getNumNondefaultElements() != 1) {381 return false;382 }383 if (!Double.isNaN(vector.get(TasteHadoopUtils.idToIndex(itemID)))) {384 return false;385 }386 if (userIDs.length != vectorAndPrefs.getUserIDs().size()) {387 return false;388 }389 for (long userID : userIDs) {390 if (!vectorAndPrefs.getUserIDs().contains(userID)) {391 return false;392 }393 }394 return true;395 }396 return false;397 }398 @Override399 public void appendTo(StringBuffer buffer) {}400 });401 return null;402 }403 /**404 * tests {@link PartialMultiplyMapper}405 */406 @Test407 public void testPartialMultiplyMapper() throws Exception {408 Vector similarityColumn = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);409 similarityColumn.set(3, 0.5);410 similarityColumn.set(7, 0.8);411 Mapper<VarIntWritable,VectorAndPrefsWritable,VarLongWritable,PrefAndSimilarityColumnWritable>.Context context =412 EasyMock.createMock(Mapper.Context.class);413 PrefAndSimilarityColumnWritable one = new PrefAndSimilarityColumnWritable();414 PrefAndSimilarityColumnWritable two = new PrefAndSimilarityColumnWritable();415 one.set(1.0f, similarityColumn);416 two.set(3.0f, similarityColumn);417 context.write(EasyMock.eq(new VarLongWritable(123L)), EasyMock.eq(one));418 context.write(EasyMock.eq(new VarLongWritable(456L)), EasyMock.eq(two));419 EasyMock.replay(context);420 VectorAndPrefsWritable vectorAndPrefs = new VectorAndPrefsWritable(similarityColumn, Arrays.asList(123L, 456L),421 Arrays.asList(1.0f, 3.0f));422 new PartialMultiplyMapper().map(new VarIntWritable(1), vectorAndPrefs, context);423 EasyMock.verify(context);424 }425 /**426 * tests {@link AggregateAndRecommendReducer}427 */428 @Test429 public void testAggregateAndRecommendReducer() throws Exception {430 Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context =431 EasyMock.createMock(Reducer.Context.class);432 context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new GenericRecommendedItem(1L, 2.8f),433 new GenericRecommendedItem(2L, 2.0f)));434 EasyMock.replay(context);435 RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);436 similarityColumnOne.set(1, 0.1);437 similarityColumnOne.set(2, 0.5);438 RandomAccessSparseVector similarityColumnTwo = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);439 similarityColumnTwo.set(1, 0.9);440 similarityColumnTwo.set(2, 0.5);441 List<PrefAndSimilarityColumnWritable> values = Arrays.asList(442 new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne),443 new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo));444 OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap();445 indexItemIDMap.put(1, 1L);446 indexItemIDMap.put(2, 2L);447 AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer();448 setField(reducer, "indexItemIDMap", indexItemIDMap);449 setField(reducer, "recommendationsPerUser", 3);450 reducer.reduce(new VarLongWritable(123L), values, context);451 EasyMock.verify(context);452 }453 /**454 * tests {@link AggregateAndRecommendReducer}455 */456 @Test457 public void testAggregateAndRecommendReducerExcludeRecommendationsBasedOnOneItem() throws Exception {458 Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context =459 EasyMock.createMock(Reducer.Context.class);460 context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new GenericRecommendedItem(1L, 2.8f)));461 EasyMock.replay(context);462 RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);463 similarityColumnOne.set(1, 0.1);464 RandomAccessSparseVector similarityColumnTwo = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);465 similarityColumnTwo.set(1, 0.9);466 similarityColumnTwo.set(2, 0.5);467 List<PrefAndSimilarityColumnWritable> values = Arrays.asList(468 new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne),469 new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo));470 OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap();471 indexItemIDMap.put(1, 1L);472 indexItemIDMap.put(2, 2L);473 AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer();474 setField(reducer, "indexItemIDMap", indexItemIDMap);475 setField(reducer, "recommendationsPerUser", 3);476 reducer.reduce(new VarLongWritable(123L), values, context);477 EasyMock.verify(context);478 }479 /**480 * tests {@link AggregateAndRecommendReducer} with a limit on the recommendations per user481 */482 @Test483 public void testAggregateAndRecommendReducerLimitNumberOfRecommendations() throws Exception {484 Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context =485 EasyMock.createMock(Reducer.Context.class);486 context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new GenericRecommendedItem(1L, 2.8f)));487 EasyMock.replay(context);488 RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);489 similarityColumnOne.set(1, 0.1);490 similarityColumnOne.set(2, 0.5);491 RandomAccessSparseVector similarityColumnTwo = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);492 similarityColumnTwo.set(1, 0.9);493 similarityColumnTwo.set(2, 0.5);494 List<PrefAndSimilarityColumnWritable> values = Arrays.asList(495 new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne),496 new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo));497 OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap();498 indexItemIDMap.put(1, 1L);499 indexItemIDMap.put(2, 2L);500 AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer();501 setField(reducer, "indexItemIDMap", indexItemIDMap);502 setField(reducer, "recommendationsPerUser", 1);503 reducer.reduce(new VarLongWritable(123L), values, context);504 EasyMock.verify(context);505 }506 /**507 * verifies a {@link RecommendedItemsWritable}508 */509 static RecommendedItemsWritable recommendationsMatch(final RecommendedItem... items) {510 EasyMock.reportMatcher(new IArgumentMatcher() {511 @Override512 public boolean matches(Object argument) {513 if (argument instanceof RecommendedItemsWritable) {514 RecommendedItemsWritable recommendedItemsWritable = (RecommendedItemsWritable) argument;515 List<RecommendedItem> expectedItems = new LinkedList<RecommendedItem>(Arrays.asList(items));516 return expectedItems.equals(recommendedItemsWritable.getRecommendedItems());517 }518 return false;519 }520 @Override521 public void appendTo(StringBuffer buffer) {}522 });523 return null;524 }525 /**526 * small integration test that runs the full job...

Full Screen

Full Screen

Source:ArgumentMatchersUnitTest.java Github

copy

Full Screen

...9import static org.easymock.EasyMock.gt;10import static org.easymock.EasyMock.isA;11import static org.easymock.EasyMock.isNull;12import static org.easymock.EasyMock.lt;13import static org.easymock.EasyMock.matches;14import static org.easymock.EasyMock.mock;15import static org.easymock.EasyMock.not;16import static org.easymock.EasyMock.notNull;17import static org.easymock.EasyMock.replay;18import static org.easymock.EasyMock.same;19import static org.easymock.EasyMock.startsWith;20import static org.easymock.EasyMock.verify;21import static org.junit.Assert.assertEquals;22import static org.junit.Assert.assertFalse;23import static org.junit.Assert.assertTrue;24import java.util.Collections;25import java.util.List;26import org.easymock.EasyMock;27import org.easymock.IArgumentMatcher;28import org.junit.Test;29public class ArgumentMatchersUnitTest {30 private IUserService userService = mock(IUserService.class);31 //====================== equals32 @Test33 public void givenUserService_whenAddNewUser_thenOK() { 34 expect(userService.addUser(eq(new User()))).andReturn(true);35 replay(userService);36 boolean result = userService.addUser(new User());37 verify(userService);38 assertTrue(result);39 } 40 41 //================ same42 @Test43 public void givenUserService_whenAddSpecificUser_thenOK() {44 User user = new User();45 46 expect(userService.addUser(same(user))).andReturn(true);47 replay(userService);48 boolean result = userService.addUser(user);49 verify(userService);50 assertTrue(result);51 } 52 53 //============= anyX54 @Test55 public void givenUserService_whenSearchForUserByEmail_thenFound() { 56 expect(userService.findByEmail(anyString())).andReturn(Collections.emptyList());57 replay(userService);58 List<User> result = userService.findByEmail("test@example.com");59 verify(userService);60 assertEquals(0,result.size());61 } 62 63 //================= isA64 @Test65 public void givenUserService_whenAddUser_thenOK() { 66 expect(userService.addUser(isA(User.class))).andReturn(true);67 replay(userService);68 boolean result = userService.addUser(new User());69 verify(userService);70 assertTrue(result);71 } 72 73 //=================== null, not null74 @Test75 public void givenUserService_whenAddNull_thenFail() { 76 expect(userService.addUser(isNull())).andReturn(false);77 replay(userService);78 boolean result = userService.addUser(null);79 verify(userService);80 assertFalse(result);81 } 82 83 @Test84 public void givenUserService_whenAddNotNull_thenOK() { 85 expect(userService.addUser(notNull())).andReturn(true);86 replay(userService);87 boolean result = userService.addUser(new User());88 verify(userService);89 assertTrue(result);90 } 91 92 // number less,great93 @Test94 public void givenUserService_whenSearchForUserByAgeLessThan_thenFound() { 95 expect(userService.findByAge(lt(100.0))).andReturn(Collections.emptyList());96 replay(userService);97 List<User> result = userService.findByAge(20); 98 verify(userService);99 assertEquals(0,result.size());100 } 101 102 @Test103 public void givenUserService_whenSearchForUserByAgeGreaterThan_thenFound() { 104 expect(userService.findByAge(geq(10.0))).andReturn(Collections.emptyList());105 replay(userService);106 List<User> result = userService.findByAge(20); 107 verify(userService);108 assertEquals(0,result.size());109 } 110 111 //=============== string 112 //=============== start113 @Test114 public void givenUserService_whenSearchForUserByEmailStartsWith_thenFound() { 115 expect(userService.findByEmail(startsWith("test"))).andReturn(Collections.emptyList());116 replay(userService);117 List<User> result = userService.findByEmail("test@example.com");118 verify(userService);119 assertEquals(0,result.size());120 }121 122 //==================end123 @Test124 public void givenUserService_whenSearchForUserByEmailEndsWith_thenFound() { 125 expect(userService.findByEmail(endsWith(".com"))).andReturn(Collections.emptyList());126 replay(userService);127 List<User> result = userService.findByEmail("test@example.com");128 verify(userService);129 assertEquals(0,result.size());130 }131 132 //=================contain133 @Test134 public void givenUserService_whenSearchForUserByEmailContains_thenFound() { 135 expect(userService.findByEmail(contains("@"))).andReturn(Collections.emptyList());136 replay(userService);137 List<User> result = userService.findByEmail("test@example.com");138 verify(userService);139 assertEquals(0,result.size());140 }141 142 //==================matches143 @Test144 public void givenUserService_whenSearchForUserByEmailMatches_thenFound() { 145 expect(userService.findByEmail(matches(".+\\@.+\\..+"))).andReturn(Collections.emptyList());146 replay(userService);147 List<User> result = userService.findByEmail("test@example.com");148 verify(userService);149 assertEquals(0,result.size());150 }151 152 //================== combine and, or, not153 @Test154 public void givenUserService_whenSearchForUserByAgeRange_thenFound() { 155 expect(userService.findByAge(and(gt(10.0),lt(100.0)))).andReturn(Collections.emptyList());156 replay(userService);157 List<User> result = userService.findByAge(20); 158 verify(userService);159 assertEquals(0,result.size());160 } 161 162 @Test163 public void givenUserService_whenSearchForUserByEmailNotEndsWith_thenFound() { 164 expect(userService.findByEmail(not(endsWith(".com")))).andReturn(Collections.emptyList());165 replay(userService);166 List<User> result = userService.findByEmail("test@example.org");167 verify(userService);168 assertEquals(0,result.size());169 } 170 171 //================ custom matcher172 173 @Test174 public void givenUserService_whenSearchForUserByEmailCharCount_thenFound() { 175 expect(userService.findByEmail(minCharCount(5))).andReturn(Collections.emptyList());176 replay(userService);177 List<User> result = userService.findByEmail("test@example.com");178 verify(userService);179 assertEquals(0,result.size());180 }181 182 public static String minCharCount(int value){183 EasyMock.reportMatcher(new IArgumentMatcher() {184 @Override185 public boolean matches(Object argument) {186 return argument instanceof String 187 && ((String) argument).length() >= value;188 }189 190 @Override191 public void appendTo(StringBuffer buffer) {192 buffer.append("charCount(\"" + value + "\")");193 }194 }); 195 return null;196 }197}...

Full Screen

Full Screen

Source:MaybePruneRowsMapperTest.java Github

copy

Full Screen

1/**2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17package org.apache.mahout.cf.taste.hadoop;18import org.apache.hadoop.io.IntWritable;19import org.apache.hadoop.mapreduce.Counter;20import org.apache.hadoop.mapreduce.Mapper;21import org.apache.mahout.cf.taste.impl.TasteTestCase;22import org.apache.mahout.math.RandomAccessSparseVector;23import org.apache.mahout.math.VarLongWritable;24import org.apache.mahout.math.Vector;25import org.apache.mahout.math.VectorWritable;26import org.apache.mahout.math.hadoop.DistributedRowMatrix;27import org.apache.mahout.math.hadoop.MathHelper;28import org.easymock.classextension.EasyMock;29import org.junit.Test;30public class MaybePruneRowsMapperTest extends TasteTestCase {31 @Test32 public void testPruning() throws Exception {33 Vector v1 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);34 v1.set(1, 1);35 v1.set(3, 1);36 Vector v2 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);37 v2.set(1, 1);38 v2.set(7, 1);39 Vector v3 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);40 v3.set(1, 1);41 v3.set(5, 1);42 v3.set(9, 1);43 MaybePruneRowsMapper mapper = new MaybePruneRowsMapper();44 setField(mapper, "maxCooccurrences", 2);45 Mapper<VarLongWritable,VectorWritable, IntWritable, DistributedRowMatrix.MatrixEntryWritable>.Context ctx =46 EasyMock.createMock(Mapper.Context.class);47 Counter usedElementsCounter = EasyMock.createMock(Counter.class);48 Counter neglectedElementsCounter = EasyMock.createMock(Counter.class);49 ctx.write(EasyMock.eq(new IntWritable(1)), MathHelper.matrixEntryMatches(1, 123, 1));50 ctx.write(EasyMock.eq(new IntWritable(3)), MathHelper.matrixEntryMatches(3, 123, 1));51 EasyMock.expect(ctx.getCounter(MaybePruneRowsMapper.Elements.USED)).andReturn(usedElementsCounter);52 usedElementsCounter.increment(2);53 EasyMock.expect(ctx.getCounter(MaybePruneRowsMapper.Elements.NEGLECTED)).andReturn(neglectedElementsCounter);54 neglectedElementsCounter.increment(0);55 ctx.write(EasyMock.eq(new IntWritable(1)), MathHelper.matrixEntryMatches(1, 456, 1));56 ctx.write(EasyMock.eq(new IntWritable(7)), MathHelper.matrixEntryMatches(7, 456, 1));57 EasyMock.expect(ctx.getCounter(MaybePruneRowsMapper.Elements.USED)).andReturn(usedElementsCounter);58 usedElementsCounter.increment(2);59 EasyMock.expect(ctx.getCounter(MaybePruneRowsMapper.Elements.NEGLECTED)).andReturn(neglectedElementsCounter);60 neglectedElementsCounter.increment(0);61 ctx.write(EasyMock.eq(new IntWritable(5)), MathHelper.matrixEntryMatches(5, 789, 1));62 ctx.write(EasyMock.eq(new IntWritable(9)), MathHelper.matrixEntryMatches(9, 789, 1));63 EasyMock.expect(ctx.getCounter(MaybePruneRowsMapper.Elements.USED)).andReturn(usedElementsCounter);64 usedElementsCounter.increment(2);65 EasyMock.expect(ctx.getCounter(MaybePruneRowsMapper.Elements.NEGLECTED)).andReturn(neglectedElementsCounter);66 neglectedElementsCounter.increment(1);67 EasyMock.replay(ctx, usedElementsCounter, neglectedElementsCounter);68 mapper.map(new VarLongWritable(123L), new VectorWritable(v1), ctx);69 mapper.map(new VarLongWritable(456L), new VectorWritable(v2), ctx);70 mapper.map(new VarLongWritable(789L), new VectorWritable(v3), ctx);71 EasyMock.verify(ctx, usedElementsCounter, neglectedElementsCounter);72 }73}...

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.IArgumentMatcher;3import org.easymock.classextension.EasyMock;4import org.easymock.classextension.IMocksControl;5import org.junit.Assert;6import org.junit.Test;7public class Test1 {8 public void test1() {9 IMocksControl control = EasyMock.createControl();10 I1 i1 = control.createMock(I1.class);11 i1.m1("a");12 control.replay();13 i1.m1("a");14 control.verify();15 }16 public void test2() {17 IMocksControl control = EasyMock.createControl();18 I1 i1 = control.createMock(I1.class);19 i1.m1("a");20 control.replay();21 i1.m1("b");22 control.verify();23 }24 public void test3() {25 IMocksControl control = EasyMock.createControl();26 I1 i1 = control.createMock(I1.class);27 i1.m1("a");28 control.replay();29 i1.m1(null);30 control.verify();31 }32 public void test4() {33 IMocksControl control = EasyMock.createControl();34 I1 i1 = control.createMock(I1.class);35 i1.m1("a");36 control.replay();37 i1.m1("a");38 i1.m1("a");39 control.verify();40 }41 public void test5() {42 IMocksControl control = EasyMock.createControl();43 I1 i1 = control.createMock(I1.class);44 i1.m1("a");45 control.replay();46 i1.m1("a");47 i1.m1("b");48 control.verify();49 }50 public void test6() {51 IMocksControl control = EasyMock.createControl();52 I1 i1 = control.createMock(I1.class);53 i1.m1("a");54 control.replay();55 i1.m1("a");56 i1.m1(null);57 control.verify();58 }59 public void test7() {60 IMocksControl control = EasyMock.createControl();61 I1 i1 = control.createMock(I1.class);62 i1.m1("

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.IMocksControl;3public class 1 {4 public static void main(String[] args) {5 IMocksControl control = EasyMock.createControl();6 Interface mock = control.createMock(Interface.class);7 mock.method(EasyMock.matches("hello"));8 control.replay();9 mock.method("hello");10 control.verify();11 }12}13org.easymock.MockControl$UnexpectedMethodCallError: Unexpected method call Interface.method("hello"):14 Interface.method("hello"): expected: 1, actual: 015 at org.easymock.MockControl.reportUnexpectedMethodCall(MockControl.java:158)16 at org.easymock.MockControl.reportUnexpectedMethodCall(MockControl.java:163)17 at org.easymock.MockControl.verify(MockControl.java:137)18 at 1.main(1.java:23)19Related posts: EasyMock – How to use andReturn() method of org.easymock.EasyMock class? EasyMock – How to use andThrow() method of org.easymock.EasyMock class? EasyMock – How to use anyObject() method of org.easymock.EasyMock class? EasyMock – How to use anyLong() method of org.easymock.EasyMock class? EasyMock – How to use anyInt() method of org.easymock.EasyMock class? EasyMock – How to use anyBoolean() method of org.easymock.EasyMock class? EasyMock – How to use anyDouble() method of org.easymock.EasyMock class? EasyMock – How to use anyFloat() method of org.easymock.EasyMock class? EasyMock – How to use anyShort() method of org.easymock.EasyMock class? EasyMock – How to use anyByte() method of org.easymock.EasyMock class? EasyMock – How to use anyString() method of org.easymock.EasyMock class? EasyMock – How to use anyChar() method of org.easymock.EasyMock class? EasyMock – How to use createStrictControl() method of org.easymock.EasyMock class? EasyMock –

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1import org.easymock.EasyMock;2import org.easymock.EasyMockSupport;3import org.junit.Test;4public class Test1 extends EasyMockSupport {5 public void test() {6 List mockedList = createMock(List.class);7 mockedList.add(EasyMock.matches("a.*"));8 replayAll();9 mockedList.add("abc");10 verifyAll();11 }12}13java.lang.AssertionError: Unexpected method call List.add("abc"):14 List.add("abc"): expected: 1, actual: 015 at org.easymock.internal.MocksControl.reportUnexpected(MocksControl.java:261)16 at org.easymock.internal.MocksControl.reportUnexpected(MocksControl.java:265)17 at org.easymock.internal.MocksControl.reportUnexpected(MocksControl.java:265)18 at org.easymock.internal.MocksControl.reportUnexpected(MocksControl.java:265)19 at org.easymock.internal.MocksControl.verify(MocksControl.java:238)

Full Screen

Full Screen

matches

Using AI Code Generation

copy

Full Screen

1package org.easymock;2import static org.easymock.EasyMock.*;3import java.util.List;4import org.junit.Test;5public class EasyMockTest {6 public void test() {7 List list = createMock(List.class);8 expect(list.get(0)).andReturn("first");9 expect(list.get(1)).andReturn("second");10 expect(list.get(2)).andReturn("third");11 expect(list.get(3)).andReturn("fourth");12 expect(list.get(4)).andReturn("fifth");13 expect(list.get(5)).andReturn("sixth");14 expect(list.get(6)).andReturn("seventh");15 expect(list.get(7)).andReturn("eighth");16 expect(list.get(8)).andReturn("ninth");17 expect(list.get(9)).andReturn("tenth");18 replay(list);19 System.out.println(list.get(0));20 System.out.println(list.get(1));21 System.out.println(list.get(2));22 System.out.println(list.get(3));23 System.out.println(list.get(4));24 System.out.println(list.get(5));25 System.out.println(list.get(6));26 System.out.println(list.get(7));27 System.out.println(list.get(8));28 System.out.println(list.get(9));29 verify(list);30 }31}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful