Skip to content

Commit

Permalink
Merge pull request #11 from pedrovgs/acceptance-testing-for-lynx
Browse files Browse the repository at this point in the history
Add more acceptance tests for Lynx and enable support for acceptance tests execution in Travis-CI
  • Loading branch information
pedrovgs committed Mar 1, 2015
2 parents b7e6e07 + e6cb24c commit 50fc6e0
Show file tree
Hide file tree
Showing 15 changed files with 345 additions and 22 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ android:
- build-tools-21.1.2
- android-21
- extra-android-support
- sys-img-armeabi-v7a-android-19
- sys-img-armeabi-v7a-android-17

before_script:
- echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a
- echo no | android create avd --force -n test -t android-17 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &

script:
./gradlew checkstyle build
./gradlew checkstyle build connectedCheck
7 changes: 7 additions & 0 deletions lynx/src/main/java/com/github/pedrovgs/lynx/LynxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public class LynxActivity extends Activity {

private static final String LYNX_CONFIG_EXTRA = "extra_lynx_config";

/**
* Generates an Intent to start LynxActivity with a default LynxConfig object as configuration.
*/
public static Intent getIntent(Context context) {
return getIntent(context, new LynxConfig());
}

/**
* Generates an Intent to start LynxActivity with a LynxConfig configuration passed as parameter.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public int getSamplingRate() {
: that.textSizeInPx != null) {
return false;
}

if (filterTraceLevel != that.filterTraceLevel) return false;
return true;
}

Expand Down
9 changes: 7 additions & 2 deletions lynx/src/main/java/com/github/pedrovgs/lynx/LynxView.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,16 @@ public void setLynxConfig(LynxConfig lynxConfig) {
this.lynxConfig = (LynxConfig) lynxConfig.clone();
updateFilterText();
updateAdapter();
updateSpinner();
presenter.setLynxConfig(lynxConfig);
}
}

private void updateSpinner() {
TraceLevel filterTraceLevel = lynxConfig.getFilterTraceLevel();
sp_filter.setSelection(filterTraceLevel.ordinal());
}

/**
* Returns the current LynxConfig object used.
*/
Expand Down Expand Up @@ -326,8 +332,7 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
presenter.updateFilterTraceLevel((TraceLevel) parent.getItemAtPosition(position));
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
@Override public void onNothingSelected(AdapterView<?> parent) {

}
});
Expand Down
6 changes: 2 additions & 4 deletions lynx/src/main/java/com/github/pedrovgs/lynx/model/Lynx.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ private synchronized boolean traceMatchesFilter(String logcatTrace) {
TraceLevel levelFilter = lynxConfig.getFilterTraceLevel();
String filter = lynxConfig.getFilter().toLowerCase();
String logcatTraceLowercase = logcatTrace.toLowerCase();
return logcatTraceLowercase.contains(filter) && containsTraceLevel(logcatTrace,
levelFilter);
return logcatTraceLowercase.contains(filter) && containsTraceLevel(logcatTrace, levelFilter);
}

private boolean containsTraceLevel(String logcatTrace, TraceLevel levelFilter) {
Expand All @@ -146,8 +145,7 @@ private boolean containsTraceLevel(String logcatTrace, TraceLevel levelFilter) {
}

private boolean hasTraceLevelEqualOrHigher(String logcatTrace, TraceLevel levelFilter) {
TraceLevel level =
TraceLevel.getTraceLevel(logcatTrace.charAt(Trace.TRACE_LEVEL_INDEX));
TraceLevel level = TraceLevel.getTraceLevel(logcatTrace.charAt(Trace.TRACE_LEVEL_INDEX));
return level.ordinal() >= levelFilter.ordinal();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public void updateFilter(String filter) {

public void updateFilterTraceLevel(TraceLevel level) {
if (isInitialized) {
clearView();
LynxConfig lynxConfig = lynx.getConfig();
lynxConfig.setFilterTraceLevel(level);
lynx.setConfig(lynxConfig);
clearView();
restartLynx();
}
}
Expand Down
1 change: 1 addition & 0 deletions lynx/src/main/res/layout/single_line_spinner_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/DropDown"
android:id="@+id/tv_spinner_trace_level"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
Expand Down
10 changes: 10 additions & 0 deletions lynx/src/test/java/com/github/pedrovgs/lynx/LynxActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ public void shouldConfigureLynxViewWithTheDefaultLynxConfigObjectIfThereIsNoOthe
assertEquals(defaultLynxConfig, lynxConfig);
}

@Test public void shouldConfigureLynxViewWithTheDefaultLynxConfigIfUsesGetIntentMethod() {
Intent intent = LynxActivity.getIntent(Robolectric.application);

LynxActivity lynxActivity =
Robolectric.buildActivity(LynxActivity.class).withIntent(intent).create().resume().get();

LynxView lynxView = (LynxView) lynxActivity.findViewById(R.id.lynx_view);
assertEquals(new LynxConfig(), lynxView.getLynxConfig());
}

@Test public void shouldPassLynxConfigurationToLynxView() {
LynxConfig lynxConfig =
new LynxConfig().setMaxNumberOfTracesToShow(ANY_MAX_NUMBER_OF_TRACES).setFilter(ANY_FILTER);
Expand Down
16 changes: 14 additions & 2 deletions lynx/src/test/java/com/github/pedrovgs/lynx/LynxViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
@Config(emulateSdk = 18) @RunWith(RobolectricTestRunner.class) public class LynxViewTest {

private static final String ANY_TRACE_MESSAGE = "02-07 17:45:33.014 D/ Any trace message";
private static final String SHARE_INTENT_TYPE = "text/plain";
public static final int ANY_TEXT_SIZE = 300;
private static final int ANY_TEXT_SIZE = 300;

private LynxView lynxView;
private Activity activity;
Expand Down Expand Up @@ -180,6 +179,15 @@
verify(presenter, never()).setLynxConfig(defaultConfig);
}

@Test public void shouldChangeSpinnerItemOnConfigChanges() {
LynxConfig newLynxConfig = new LynxConfig().setFilterTraceLevel(TraceLevel.WTF);

lynxView.setLynxConfig(newLynxConfig);

Spinner spinner = getTraceLevelFilterSpinner();
assertEquals(TraceLevel.WTF, spinner.getSelectedItem());
}

private void assertTracesRendered(List<Trace> traces, ListView tracesListView) {
for (int i = 0; i < traces.size(); i++) {
Trace trace = traces.get(i);
Expand All @@ -199,4 +207,8 @@ private List<Trace> givenAnyListOfTraces(int tracesCount) {
private ListView getLvTraces() {
return (ListView) lynxView.findViewById(R.id.lv_traces);
}

private Spinner getTraceLevelFilterSpinner() {
return (Spinner) lynxView.findViewById(R.id.sp_filter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2015 Pedro Vicente Gomez Sanchez.
*
* 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.github.pedrovgs.sample;

import android.test.ActivityInstrumentationTestCase2;
import com.github.pedrovgs.lynx.LynxActivity;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withSpinnerText;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

/**
* @author Pedro Vicente Gómez Sánchez.
*/
public class LynxActivityDefaultValues extends ActivityInstrumentationTestCase2<LynxActivity> {

private static final String VERBOSE_TRACE_LEVEL = "VERBOSE";

public LynxActivityDefaultValues() {
super(LynxActivity.class);
}

@Override protected void setUp() throws Exception {
super.setUp();
getActivity();
}

public void testDoesNotUseFilterByDefault() {
onView(withId(R.id.et_filter)).check(matches(withText("")));
}

public void testUsesVerboseTraceLevelFilterByDefault() {
onView(withId(R.id.sp_filter)).check(matches(withSpinnerText(VERBOSE_TRACE_LEVEL)));
}
}
Loading

0 comments on commit 50fc6e0

Please sign in to comment.