/*
 *  Copyright (C) 2017 Bilibili
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.bilibili.boxing_impl.view;

import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.ViewAssertion;
import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.view.WindowManager;

import com.bilibili.boxing.model.entity.BaseMedia;
import com.bilibili.boxing.model.entity.impl.ImageMedia;
import com.bilibili.boxing_impl.R;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.List;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

/**
 * @author ChenSL
 */
@RunWith(AndroidJUnit4.class)
public class PickerFragmentTest {
    @Rule
    public ActivityTestRule<TestBlankActivity> mRule = new ActivityTestRule<>(TestBlankActivity.class);

    @Before
    public void setup() throws Throwable {
        // espresso need the screen on
        final Activity activity = mRule.getActivity();
        mRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                KeyguardManager km = (KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE);
                KeyguardManager.KeyguardLock lock = km.newKeyguardLock(Context.KEYGUARD_SERVICE);
                lock.disableKeyguard();

                //turn the screen on
                activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
            }
        });
    }

    @Test
    public void showMedia() {
        List<BaseMedia> medias = new ArrayList<>();
        medias.add(new ImageMedia("1", "TEST1"));
        medias.add(new ImageMedia("2", "TEST2"));
        medias.add(new ImageMedia("3", "TEST3"));

        ViewInteraction container = onView(withId(R.id.container));
        container.check(new ViewAssertion() {
            @Override
            public void check(View view, NoMatchingViewException noViewFoundException) {
                assertNotNull(view);
                assertTrue(view.getVisibility() == View.VISIBLE);
            }
        });
        ViewInteraction empty = onView(withId(R.id.empty_txt));
        empty.check(new ViewAssertion() {
            @Override
            public void check(View view, NoMatchingViewException noViewFoundException) {
                assertNotNull(view);
                assertTrue(view.getVisibility() == View.GONE);
            }
        });

    }

}
@@ -1077,116 +1077,8 @@
 r;%0A%0A
-import com.bilibili.boxing.model.entity.BaseMedia;%0Aimport com.bilibili.boxing.model.entity.impl.ImageMedia;%0A
 impo
@@ -1218,60 +1218,8 @@
 h;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 impo
@@ -2655,211 +2655,8 @@
 ) %7B%0A
-        List%3CBaseMedia%3E medias = new ArrayList%3C%3E();%0A        medias.add(new ImageMedia(%221%22, %22TEST1%22));%0A        medias.add(new ImageMedia(%222%22, %22TEST2%22));%0A        medias.add(new ImageMedia(%223%22, %22TEST3%22));%0A%0A
     
@@ -3263,71 +3263,8 @@
 w);%0A
-                assertTrue(view.getVisibility() == View.GONE);%0A
     

remove useless androidtest code