Skip to content

Instantly share code, notes, and snippets.

View ShaishavGandhi's full-sized avatar

Shaishav Gandhi ShaishavGandhi

View GitHub Profile
@ShaishavGandhi
ShaishavGandhi / sample.java
Last active May 29, 2018 04:00
Existing Native Content Ad API
AdLoader adLoader = new AdLoader.Builder(context, "ca-app-pub-3940256099942544/2247696110")
.forContentAd(new OnContentAdLoadedListener() {
@Override
public void onContentAdLoaded(NativeContentAd contentAd) {
// Show the content ad.
}
})
.withAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int errorCode) {
@Test fun testBlogsReturnsError() {
val testObserver = TestObserver<List<Blog>>()
val path = "/blogs"
// Mock a response with status 200 and sample JSON output
val mockReponse = MockReponse()
.setResponseCode(200)
.throttleBody(1024, 1, TimeUnit.SECONDS) // Simulate SocketTimeout
.setBody(getJson("json/blog/blogs.json"))
@Test fun testBlogsReturnsError() {
val testObserver = TestObserver<List<Blog>>()
val path = "/blogs"
// Mock a response with status 200 and sample JSON output
val mockReponse = MockReponse()
.setResponseCode(500) // Simulate a 500 HTTP Code
// Enqueue request
@Test fun testBlogsReturnsListOfBlogs() {
val testObserver = TestObserver<List<Blog>>()
val path = "/blogs"
// Mock a response with status 200 and sample JSON output
val mockReponse = MockReponse()
.setResponseCode(200)
.setBody(getJson("json/blog/blogs.json"))
@RunWith(JUnit4::class)
class BlogRepositoryUTest {
lateinit var blogRepository : BlogRepository
lateinit var mockServer : MockWebServer
lateinit var blogService : BlogService
@Before @Throws fun setUp() {
// Initialize mock webserver
mockServer = MockWebServer()
public interface BlogService {
@GET("/blogs")
fun blogs() : Observable<List<Blog>>
}
class BlogRepository(val blogService : BlogService) {
fun blogs() : Observable<List<Blog>> {
return blogService.blogs()
}
}
@RunWith(JUnit4::class)
class BlogPresenterUTest {
lateinit var blogRepository : BlogRepository
lateinit var blogView : BlogView
lateinit var blogPresenter : BlogPresenter
@Before @Throws fun setUp(){
RxAndroidPlugins.setInitMainThreadSchedulerHandler({ Schedulers.trampoline()})
MockitoAnnotations.initMocks(this)
class BlogPresenter(val blogRepository: BlogRepository, val view : BlogView) {
fun blogs() {
val disposable = blogRepository.blogs()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object : DisposableObserver<List<Blog>>() {
override fun onComplete() {
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleX"
android:valueTo="1.525"
android:valueType="floatType" />
<objectAnimator