it.tidalwave.bluebill.mobile.android.observation.ObservationActivityTestHelper Maven / Gradle / Ivy
The newest version!
/***********************************************************************************************************************
*
* blueBill Mobile - Android - open source birding
* Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* 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.
*
***********************************************************************************************************************
*
* WWW: http://bluebill.tidalwave.it/mobile
* SCM: https://java.net/hg/bluebill-mobile~android-src
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.observation;
import android.widget.ExpandableListView;
import android.widget.TextView;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import it.tidalwave.bluebill.mobile.android.ActivityTestHelper;
import it.tidalwave.bluebill.mobile.android.R;
import android.app.ExpandableListActivity;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.ExpandableListAdapter;
import com.jayway.android.robotium.solo.Solo;
import static android.test.ActivityInstrumentationTestCase2.*;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
public class ObservationActivityTestHelper extends ActivityTestHelper
{
public ObservationActivityTestHelper (final @Nonnull ActivityInstrumentationTestCase2 instrumentationTestCase,
final @Nonnull Solo solo)
{
super(instrumentationTestCase, solo);
}
public void waitForActivity()
throws InterruptedException
{
testHelper.waitForActivity(ObservationsActivity.class);
}
public void clickOnAddObservationButton()
throws InterruptedException
{
testHelper.clickOnImageButtonById(R.id.btAdd);
}
public void changeObservationDate (final @Nonnegative int index, final int year, final int month, final int day)
{
testHelper.popContextMenuOnListView(getExpandableListView(), index, R.id.editDate);
// TODO: change the spinners - enterText doesn't work with a spinner
// solo.enterText(0, Integer.toString(year));
// solo.enterText(1, Integer.toString(month));
// solo.enterText(2, Integer.toString(day));
}
public void assertObservationCount (final @Nonnegative int count)
{
assertEquals(count, getExpandableListAdapter().getGroupCount());
}
public void assertObservationItemCount (final @Nonnegative int observationIndex,
final @Nonnegative int count)
{
final ExpandableListAdapter adapter = getExpandableListAdapter();
assertEquals(count, adapter.getChildrenCount(observationIndex));
}
public void assertHeaderText (final @Nonnull String text)
{
final TextView textView = (TextView)solo.getCurrentActivity().findViewById(R.id.tvFooter);
assertEquals(text, textView.getText().toString());
}
public void assertThatLastNodeIsExpandedOthersAreCollapsed()
{
final ExpandableListView listView = getExpandableListView();
final int groupCount = getExpandableListAdapter().getGroupCount();
if (groupCount > 0)
{
for (int i = 0; i < groupCount - 1; i++)
{
assertFalse("Should be collapsed, but it's expanded: #" + i, listView.isGroupExpanded(i));
}
assertTrue("Should be expanded, but it's collapsed: last one", listView.isGroupExpanded(groupCount - 1));
}
}
@Nonnull
private ExpandableListView getExpandableListView()
{
return ((ExpandableListActivity) solo.getCurrentActivity()).getExpandableListView();
}
@Nonnull
private ExpandableListAdapter getExpandableListAdapter()
{
return ((ExpandableListActivity)solo.getCurrentActivity()).getExpandableListAdapter();
}
}