1 package org.wikimedia.search.extra.superdetectnoop; 2 3 import static org.junit.Assert.assertEquals; 4 5 import java.util.ArrayList; 6 import java.util.HashMap; 7 import java.util.List; 8 import java.util.Map; 9 10 import org.junit.Test; 11 12 import com.google.common.collect.ImmutableList; 13 14 public class SetHandlerTest { 15 @Test 16 public void neverConvert() { 17 testCase(new SetHandler(0, 0, 0)); 18 } 19 20 @Test 21 public void alwaysConvert() { 22 testCase(new SetHandler(0, Integer.MAX_VALUE, 0)); 23 } 24 25 @SuppressWarnings("unchecked") 26 public void testCase(SetHandler handler) { 27 List<String> old = new ArrayList<>(); 28 old = (List<String>) handler.handle(old, map("add", "cat")).newValue(); 29 assertEquals(ImmutableList.of("cat"), old); 30 old = (List<String>) handler.handle(old, map("add", ImmutableList.of("badger"))).newValue(); 31 assertEquals(ImmutableList.of("cat", "badger"), old); 32 old = (List<String>) handler.handle(old, map("add", ImmutableList.of("clock"), "remove", ImmutableList.of("clock", "badger"))) 33 .newValue(); 34 assertEquals(ImmutableList.of("cat"), old); 35 old = (List<String>) handler.handle(old, map("add", ImmutableList.of("clock"), "remove", ImmutableList.of("cat", "blunder"))) 36 .newValue(); 37 assertEquals(ImmutableList.of("clock"), old); 38 old = (List<String>) handler.handle(old, map("add", ImmutableList.of("clock", "blunder", "other"), "remove", ImmutableList.of("clock"), "max_size", 1)) 39 .newValue(); 40 assertEquals(ImmutableList.of("blunder"), old); 41 } 42 43 private Map<String, Object> map(String key, Object value) { 44 Map<String, Object> map = new HashMap<>(); 45 map.put(key, value); 46 return map; 47 } 48 49 private Map<String, Object> map(String key, Object value, String key2, Object value2) { 50 Map<String, Object> map = map(key, value); 51 map.put(key2, value2); 52 return map; 53 } 54 55 private Map<String, Object> map(String key, Object value, String key2, Object value2, String key3, Object value3) { 56 Map<String, Object> map = map(key, value); 57 map.put(key2, value2); 58 map.put(key3, value3); 59 return map; 60 } 61 }