Skip to content

Commit

Permalink
PostPreference TestMock
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdel committed Jan 6, 2018
1 parent 8f5fc6b commit ebc8361
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ public Call<DiscountPreferencesResponse> putDiscountPreferences(int id, Discount

@Override
public Call<DiscountPreferencesPostResponse> postDiscountPreferences(DiscountPreferencesRequest discountPreferencesPostRequest, String auth) {
return null;
DiscountPreferencesRequest discountPreferencesRequest=new DiscountPreferencesRequest();
discountPreferencesRequest.setPrice("40");
discountPreferencesRequest.setCategory("shoes");
discountPreferencesRequest.setTags("tag");
DiscountPreferencesPostResponse discountPreferencesPostResponse=new DiscountPreferencesPostResponse();
discountPreferencesPostResponse.setCategory("shoes");
discountPreferencesPostResponse.setPrice("40");
discountPreferencesPostResponse.setId(1);
discountPreferencesPostResponse.setTags("tag");
return delegate.returningResponse(discountPreferencesPostResponse).postDiscountPreferences(discountPreferencesRequest,auth);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.junit.Test;

import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesPostResponse;
import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesRequest;
import eu.jnksoftware.discountfinderandroid.models.discountPreferences.DiscountPreferencesResponse;
import eu.jnksoftware.discountfinderandroid.models.token.User;
Expand Down Expand Up @@ -77,5 +78,21 @@ public void testPutPreferences() throws Exception{
Assert.assertEquals("tag",putPreferenceResponse.body().getTags());
}

@Test
public void testPostPreferences() throws Exception{
DiscountPreferencesRequest discountPreferencesRequest=new DiscountPreferencesRequest();
discountPreferencesRequest.setPrice("140");
discountPreferencesRequest.setCategory("shoes");
discountPreferencesRequest.setTags("tag");
BehaviorDelegate<IuserService>delegate=mockRetrofit.create(IuserService.class);
IuserService mockService=new MockUserService(delegate);
Call<DiscountPreferencesPostResponse> postPreference=mockService.postDiscountPreferences(discountPreferencesRequest,"auth");
retrofit2.Response<DiscountPreferencesPostResponse> postPreferenceResponse=postPreference.execute();
Assert.assertEquals("shoes",postPreferenceResponse.body().getCategory());
Assert.assertEquals("1",postPreferenceResponse.body().getId().toString());
Assert.assertEquals("40",postPreferenceResponse.body().getPrice());
Assert.assertEquals("tag",postPreferenceResponse.body().getTags());
}


}

0 comments on commit ebc8361

Please sign in to comment.