Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Fixes builder regression: pop() used to be nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrjr committed Aug 13, 2015
1 parent e94f3e0 commit e642e50
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ language: android

android:
components:
- build-tools-21.1.2
- android-21
- build-tools-22.0.1
- android-22
licenses:
- android-sdk-license-5be876d5

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Change Log
==========

Version 0.12 *(2015-08-13)*
------
* Fix: History.Builder#pop is nullable again, and adds History.Builder#isEmpty.

Version 0.11 *(2015-08-11)*
------
* Fix: No longer persists an empty list of states if the filter excludes everything.
Expand Down
1 change: 1 addition & 0 deletions flow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ android {
}

dependencies {
compile 'com.android.support:support-annotations:22.2.1'
testCompile 'junit:junit:4.10'
testCompile 'org.easytesting:fest-assert-core:2.0M10'
}
Expand Down
14 changes: 12 additions & 2 deletions flow/src/main/java/flow/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.util.SparseArray;
import android.view.View;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -217,11 +218,20 @@ public Builder addAll(Collection<Object> c) {
return this;
}

public Object peek() {
return history.peek().state;
@Nullable public Object peek() {
final Entry peek = history.peek();
return peek == null ? null : peek.state;
}

public boolean isEmpty() {
return peek() == null;
}

/** @throws IllegalStateException if empty */
public Object pop() {
if (isEmpty()) {
throw new IllegalStateException("Cannot pop from an empty builder");
}
Entry entry = history.pop();
entryMemory.put(entry.state, entry);
return entry.state;
Expand Down
23 changes: 23 additions & 0 deletions flow/src/test/java/flow/FlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static flow.Flow.TraversalCallback;
import static java.util.Arrays.asList;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.fest.assertions.api.Fail.fail;

public class FlowTest {
static class Uno {
Expand Down Expand Up @@ -287,4 +288,26 @@ public int hashCode() {

assertThat(flow.goBack()).isFalse();
}

@Test public void emptyBuilderPeekIsNullable() {
assertThat(History.emptyBuilder().peek()).isNull();
}

@Test public void emptyBuilderPopThrows() {
try {
History.emptyBuilder().pop();
fail("Should throw");
} catch (IllegalStateException e) {
// pass
}
}

@Test public void isEmpty() {
final History.Builder builder = History.emptyBuilder();
assertThat(builder.isEmpty()).isTrue();
builder.push("foo");
assertThat(builder.isEmpty()).isFalse();
builder.pop();
assertThat(builder.isEmpty()).isTrue();
}
}

0 comments on commit e642e50

Please sign in to comment.