### Question:
Transformations { @MainThread public static <X, Y> LiveData<Y> map( @NonNull LiveData<X> source, @NonNull final Function<X, Y> mapFunction) { final MediatorLiveData<Y> result = new MediatorLiveData<>(); result.addSource(source, new Observer<X>() { @Override public void onChanged(@Nullable X x) { result.setValue(mapFunction.apply(x)); } }); return result; } private  Transformations(); @MainThread static LiveData<Y> map(
            @NonNull LiveData<X> source,
            @NonNull final Function<X, Y> mapFunction); @MainThread static LiveData<Y> switchMap(
            @NonNull LiveData<X> source,
            @NonNull final Function<X, LiveData<Y>> switchMapFunction);  }### Answer:
@Test public void testMap() { LiveData<String> source = new MutableLiveData<>(); LiveData<Integer> mapped = Transformations.map(source, new Function<String, Integer>() { @Override public Integer apply(String input) { return input.length(); } }); Observer<Integer> observer = mock(Observer.class); mapped.observe(mOwner, observer); source.setValue("four"); verify(observer).onChanged(4); }
@Test public void noObsoleteValueTest() { MutableLiveData<Integer> numbers = new MutableLiveData<>(); LiveData<Integer> squared = Transformations.map(numbers, new Function<Integer, Integer>() { @Override public Integer apply(Integer input) { return input * input; } }); Observer observer = mock(Observer.class); squared.setValue(1); squared.observeForever(observer); verify(observer).onChanged(1); squared.removeObserver(observer); reset(observer); numbers.setValue(2); squared.observeForever(observer); verify(observer, only()).onChanged(4); }