1/* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package androidx.work; 18 19import static org.hamcrest.CoreMatchers.is; 20import static org.hamcrest.MatcherAssert.assertThat; 21 22import org.junit.Before; 23import org.junit.Test; 24 25import java.util.Arrays; 26 27public class OverwritingInputMergerTest { 28 29 private OverwritingInputMerger mOverwritingInputMerger; 30 31 @Before 32 public void setUp() { 33 mOverwritingInputMerger = new OverwritingInputMerger(); 34 } 35 36 @Test 37 public void testMerge_singleArgument() { 38 String key = "key"; 39 String value = "value"; 40 41 Data input = new Data.Builder().putString(key, value).build(); 42 Data output = getOutputFor(input); 43 44 assertThat(output.size(), is(1)); 45 assertThat(output.getString(key, null), is(value)); 46 } 47 48 @Test 49 public void testMerge_multipleArguments() { 50 String key1 = "key1"; 51 String value1 = "value1"; 52 String value1a = "value1a"; 53 String key2 = "key2"; 54 String value2 = "value2"; 55 String key3 = "key3"; 56 String value3 = "value3"; 57 58 Data input1 = new Data.Builder() 59 .putString(key1, value1) 60 .putString(key2, value2) 61 .build(); 62 Data input2 = new Data.Builder() 63 .putString(key1, value1a) 64 .putString(key3, value3) 65 .build(); 66 67 Data output = getOutputFor(input1, input2); 68 69 assertThat(output.size(), is(3)); 70 assertThat(output.getString(key1, null), is(value1a)); 71 assertThat(output.getString(key2, null), is(value2)); 72 assertThat(output.getString(key3, null), is(value3)); 73 } 74 75 private Data getOutputFor(Data... inputs) { 76 return mOverwritingInputMerger.merge(Arrays.asList(inputs)); 77 } 78} 79