Skip to content

Commit

Permalink
Merge branch 'TestingCalls' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosdel committed Jan 7, 2018
2 parents 6d296d1 + ebc8361 commit 4389591
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,38 @@ public Call<User> login(String username, String password) {

@Override
public Call<User> register(String firstName, String lastName, String eMail, String password) {
return null;
User user=new User();
user.setTokenType("Bearer");
user.setRefreshToken("refresh");
user.setAccessToken("access");
user.setExpiresIn(5000);
return delegate.returningResponse(user).register(firstName,lastName,eMail,password);
}



@Override
public Call<DiscountPreferencesResponse> putDiscountPreferences(int id, DiscountPreferencesRequest discountPreferencesRequest, String auth) {
return null;
DiscountPreferencesResponse discountPreferencesResponse=new DiscountPreferencesResponse();
discountPreferencesResponse.setCategory(1);
discountPreferencesResponse.setId(1);
discountPreferencesResponse.setPrice(40);
discountPreferencesResponse.setTags("tag");
return delegate.returningResponse(discountPreferencesResponse).putDiscountPreferences(id,discountPreferencesRequest,auth);
}

@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,9 @@

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;
import eu.jnksoftware.discountfinderandroid.services.IuserService;
import eu.jnksoftware.discountfinderandroid.services.MockUserService;
Expand Down Expand Up @@ -48,6 +51,48 @@ public void testLogin() throws Exception{
Assert.assertEquals("5100",userResponse.body().getRefreshToken());
Assert.assertEquals("5100",userResponse.body().getExpiresIn().toString());
}
@Test
public void testRegister() throws Exception{
BehaviorDelegate<IuserService>delegate=mockRetrofit.create(IuserService.class);
IuserService mockService=new MockUserService(delegate);
Call<User> doregister=mockService.register("nikos","delis","[email protected]","123455");
retrofit2.Response<User> registerResponse=doregister.execute();
Assert.assertEquals("access",registerResponse.body().getAccessToken());
Assert.assertEquals("refresh",registerResponse.body().getRefreshToken());
Assert.assertEquals("Bearer",registerResponse.body().getTokenType());
Assert.assertEquals("5000",registerResponse.body().getExpiresIn().toString());
}
@Test
public void testPutPreferences() 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<DiscountPreferencesResponse> putPreference=mockService.putDiscountPreferences(1,discountPreferencesRequest,"auth");
retrofit2.Response<DiscountPreferencesResponse> putPreferenceResponse=putPreference.execute();
Assert.assertEquals("1",putPreferenceResponse.body().getCategory().toString());
Assert.assertEquals("1",putPreferenceResponse.body().getId().toString());

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 4389591

Please sign in to comment.