Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oobut committed Apr 15, 2018
1 parent 93549bd commit 357faa7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 64 deletions.
Expand Up @@ -293,100 +293,100 @@ public DialogPlusBuilder setContentWidth(int width) {
/**
* Create the dialog using this builder
*/
public DialogPlus create() {
@NonNull public DialogPlus create() {
getHolder().setBackgroundResource(getContentBackgroundResource());
return new DialogPlus(this);
}

View getFooterView() {
@Nullable public View getFooterView() {
return Utils.getView(context, footerViewResourceId, footerView);
}

@Nullable View getHeaderView() {
@Nullable public View getHeaderView() {
return Utils.getView(context, headerViewResourceId, headerView);
}

Holder getHolder() {
@NonNull public Holder getHolder() {
if (holder == null) {
holder = new ListHolder();
}
return holder;
}

Context getContext() {
@NonNull public Context getContext() {
return context;
}

BaseAdapter getAdapter() {
public BaseAdapter getAdapter() {
return adapter;
}

Animation getInAnimation() {
public Animation getInAnimation() {
int res = (inAnimation == INVALID) ? Utils.getAnimationResource(this.gravity, true) : inAnimation;
return AnimationUtils.loadAnimation(context, res);
}

Animation getOutAnimation() {
public Animation getOutAnimation() {
int res = (outAnimation == INVALID) ? Utils.getAnimationResource(this.gravity, false) : outAnimation;
return AnimationUtils.loadAnimation(context, res);
}

FrameLayout.LayoutParams getContentParams() {
public FrameLayout.LayoutParams getContentParams() {
if (expanded) {
params.height = getDefaultContentHeight();
}
return params;
}

boolean isExpanded() {
public boolean isExpanded() {
return expanded;
}

FrameLayout.LayoutParams getOutmostLayoutParams() {
public FrameLayout.LayoutParams getOutmostLayoutParams() {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
);
params.setMargins(outMostMargin[0], outMostMargin[1], outMostMargin[2], outMostMargin[3]);
return params;
}

boolean isCancelable() {
public boolean isCancelable() {
return isCancelable;
}

OnItemClickListener getOnItemClickListener() {
public OnItemClickListener getOnItemClickListener() {
return onItemClickListener;
}

OnClickListener getOnClickListener() {
public OnClickListener getOnClickListener() {
return onClickListener;
}

OnDismissListener getOnDismissListener() {
public OnDismissListener getOnDismissListener() {
return onDismissListener;
}

OnCancelListener getOnCancelListener() {
public OnCancelListener getOnCancelListener() {
return onCancelListener;
}

OnBackPressListener getOnBackPressListener() {
public OnBackPressListener getOnBackPressListener() {
return onBackPressListener;
}

int[] getContentMargin() {
public int[] getContentMargin() {
int minimumMargin = context.getResources().getDimensionPixelSize(R.dimen.dialogplus_default_center_margin);
for (int i = 0; i < margin.length; i++) {
margin[i] = getMargin(this.gravity, margin[i], minimumMargin);
}
return margin;
}

int[] getContentPadding() {
public int[] getContentPadding() {
return padding;
}

int getDefaultContentHeight() {
public int getDefaultContentHeight() {
Activity activity = (Activity) context;
Display display = activity.getWindowManager().getDefaultDisplay();
int displayHeight = display.getHeight() - Utils.getStatusBarHeight(activity);
Expand All @@ -396,11 +396,11 @@ int getDefaultContentHeight() {
return defaultContentHeight;
}

int getOverlayBackgroundResource() {
public int getOverlayBackgroundResource() {
return overlayBackgroundResource;
}

int getContentBackgroundResource() {
public int getContentBackgroundResource() {
return contentBackgroundResource;
}

Expand All @@ -421,11 +421,11 @@ private int getMargin(int gravity, int margin, int minimumMargin) {
}
}

boolean isFixedHeader() {
public boolean isFixedHeader() {
return fixedHeader;
}

boolean isFixedFooter() {
public boolean isFixedFooter() {
return fixedFooter;
}
}
Expand Up @@ -19,35 +19,6 @@ class DialogPlusBuilderTest {

private val context = Robolectric.setupActivity(Activity::class.java)

@Test fun constructorShouldNotAcceptNull() {
try {
DialogPlus.newDialog(null)
fail()
} catch (e: Exception) {
assertThat(e).hasMessage("Context may not be null")
}

val builder = DialogPlus.newDialog(context)

assertThat(builder).isNotNull()
}

@Test fun getContextShouldNotReturnNull() {
val builder = DialogPlus.newDialog(context)

assertThat(builder.context).isNotNull()
}

@Test fun setAdapterShouldNotAcceptNull() {
try {
DialogPlus.newDialog(context).adapter = null
fail()
} catch (e: Exception) {
assertThat(e).hasMessage("Adapter may not be null")
}

}

@Test fun testAdapter() {
val adapter = ArrayAdapter(
context, android.R.layout.simple_list_item_1, arrayOf("234")
Expand Down Expand Up @@ -102,9 +73,6 @@ class DialogPlusBuilderTest {
val viewHolder = ViewHolder(LinearLayout(context))
builder.setContentHolder(viewHolder)
assertThat(builder.holder).isEqualTo(viewHolder)

//should accept null
builder.setContentHolder(null)
}

@Test fun testSetCancelable() {
Expand Down Expand Up @@ -319,7 +287,7 @@ class DialogPlusBuilderTest {
assertThat(builder.onCancelListener).isNull()

val listener = OnCancelListener { }
builder.onCancelListener = listener
builder.setOnCancelListener(listener)
assertThat(builder.onCancelListener).isNotNull()
assertThat(builder.onCancelListener).isEqualTo(listener)
}
Expand Down
Expand Up @@ -81,12 +81,12 @@ class GridHolderTest {
view.performItemClick(null, 0, 0)

//set listener
holder.setOnItemClickListener { item, view, position ->
holder.setOnItemClickListener { item, passedView, position ->
assertThat(item.toString()).isEqualTo("test")
assertThat(position).isEqualTo(0)
assertThat(view).isNull()
assertThat(view).isEqualTo(passedView)
}
view.performItemClick(null, 0, 0)
view.performItemClick(view, 0, 0)
}

}
Expand Up @@ -114,9 +114,9 @@ class ListHolderTest {
holder.setOnItemClickListener { item, view, position ->
assertThat(item.toString()).isEqualTo("test")
assertThat(position).isEqualTo(0)
assertThat(view).isNull()
assertThat(view).isEqualTo(listView)
}
listView.performItemClick(null, 0, 0)
listView.performItemClick(listView, 0, 0)
}

@Test fun doNotCountHeaderForPositionCalculation() {
Expand All @@ -135,9 +135,9 @@ class ListHolderTest {
holder.setOnItemClickListener { item, view, position ->
assertThat(item.toString()).isEqualTo("test")
assertThat(position).isEqualTo(0)
assertThat(view).isNull()
assertThat(view).isEqualTo(listView)
}
listView.performItemClick(null, 1, 0)
listView.performItemClick(listView, 1, 0)
}

}

0 comments on commit 357faa7

Please sign in to comment.