it.tidalwave.bluebill.mobile.android.splash.SplashTest Maven / Gradle / Ivy
The newest version!
/***********************************************************************************************************************
*
* blueBill Mobile - open source birdwatching
* ==========================================
*
* Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
* http://bluebill.tidalwave.it/mobile/
*
***********************************************************************************************************************
*
* 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.
*
***********************************************************************************************************************
*
* $Id: SplashTest.java,v c9aee682bc72 2010/08/06 15:21:23 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.splash;
import android.app.Instrumentation;
import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.ProgressBar;
import org.openide.util.Lookup;
import it.tidalwave.bluebill.mobile.taxonomy.TaxonomyPreferences;
import it.tidalwave.bluebill.mobile.taxonomy.TaxonomyPreferencesSupport;
import it.tidalwave.bluebill.mobile.android.R;
import android.test.suitebuilder.annotation.MediumTest;
import it.tidalwave.netbeans.util.Locator;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
public class SplashTest extends ActivityInstrumentationTestCase2
{
private Intent startIntent;
public SplashTest()
{
super("it.tidalwave.bluebill.mobile.android", SplashActivity.class);
}
@Override
protected void setUp()
throws Exception
{
super.setUp();
startIntent = new Intent(Intent.ACTION_MAIN);
Locator.find(TaxonomyPreferences.class).resetTaxonomy();
}
@MediumTest
public void testPreconditions()
{
// startActivity(startIntent, null, null);
// final SplashActivity activity = getActivity();
// assertNotNull(activity);
// final ProgressBar progressBar = (ProgressBar)activity.findViewById(R.id.progressBar);
// assertNotNull(progressBar);
}
@MediumTest
public void testLifeCycleCreate()
throws InterruptedException
{
final TaxonomyPreferencesSupport taxonomyPreferences = (TaxonomyPreferencesSupport)Lookup.getDefault().lookup(TaxonomyPreferences.class);
final int previousLoadCount = taxonomyPreferences.taxonomyLoadCount;
final Instrumentation instrumentation = getInstrumentation();
final SplashActivity activity = getActivity();
// after onCreate()
// instrumentation.callActivityOnStart(activity);
// instrumentation.callActivityOnResume(activity);
final ProgressBar progressBar = (ProgressBar)activity.findViewById(R.id.progressBar);
assertNotNull("Can't find progressBar", progressBar);
System.err.println("**** Waiting for initialization thread to start...");
Thread.sleep(50);
int progress = progressBar.getProgress();
while (!activity.initializationCompleted)
{
Thread.sleep(SplashActivity.PROGRESS_BAR_ADVANCE_DELAY + 100);
final int newProgress = progressBar.getProgress();
System.err.println("**** Progress: " + newProgress);
// assertTrue("got " + newProgress + " previous " + progress, progress != newProgress);
progress = newProgress;
}
System.err.println("**** Detected initializationCompleted=true");
// final Intent intent = getStartedActivityIntent();
// assertNotNull(intent);
// System.err.println("New intent: " + intent);
// assertTrue(isFinishCalled());
assertEquals(previousLoadCount + 1, taxonomyPreferences.taxonomyLoadCount);
taxonomyPreferences.getTaxonomy();
assertEquals("Taxonomy was loaded again", previousLoadCount + 1, taxonomyPreferences.taxonomyLoadCount);
}
}