This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface BlogService { | |
@GET("/blogs") | |
fun blogs() : Observable<List<Blog>> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlogRepository(val blogService : BlogService) { | |
fun blogs() : Observable<List<Blog>> { | |
return blogService.blogs() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |