Skip to content

Commit

Permalink
#8 #2 add example of blocks direct usage having another example with …
Browse files Browse the repository at this point in the history
…functions refactor
  • Loading branch information
ramabit committed Jan 21, 2016
1 parent ce5bc71 commit 6bd5e38
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
/**
* Created by inaka on 1/20/16.
*/
public class KillerMainTest extends AndroidTestCase {
public class KillerTaskBlocksTest extends AndroidTestCase {

@UiThreadTest
public void testLibrary(){
new Example();
public void testLibraryWithBlocks() {
new ExampleAllTogether();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.inaka.killertask;

import android.test.AndroidTestCase;
import android.test.UiThreadTest;


/**
* Created by inaka on 1/21/16.
*/
public class KillerTaskFunctionsTest extends AndroidTestCase {

@UiThreadTest
public void testLibraryFunctionsRefactor() {
new ExampleFunctionsRefactor();
}

}
28 changes: 28 additions & 0 deletions library/src/main/java/com/inaka/killertask/ExampleAllTogether.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.inaka.killertask

import android.util.Log
import java.util.concurrent.CountDownLatch

/**
* Created by inaka on 1/20/16.
*/
private class ExampleAllTogether {
val signal = CountDownLatch(1);

init {
KillerTask(
"test", {
result: String ->
Log.wtf("result", result)
signal.countDown()
}, {
e: Exception? ->
Log.wtf("result", e.toString())
e?.printStackTrace()
signal.countDown()
}).go()

signal.await()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.util.Log
import java.util.concurrent.CountDownLatch

/**
* Created by inaka on 1/20/16.
* Created by inaka on 1/21/16.
*/
private class Example {
private class ExampleFunctionsRefactor {
val signal = CountDownLatch(1);

val onSuccess: (String) -> Unit = {
Expand All @@ -30,5 +30,4 @@ private class Example {
fun doWork(): String {
return "test"
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.inaka.killertask

import android.util.Log
import org.junit.Test

/**
Expand All @@ -10,6 +9,19 @@ class KillerMainTest_KotlinVersion {
@Test
fun createKillerTask() {
KillerTask(doWork(), onSuccess, onFailed).go()

/*
That is the same as:
KillerTask("test", {
result: String ->
assert(result.equals("test"))
}, {
e: Exception? ->
e?.printStackTrace()
print(e?.message)
}).go()
*/
}

fun doWork(): String {
Expand All @@ -24,6 +36,7 @@ class KillerMainTest_KotlinVersion {
val onFailed: (Exception?) -> Unit = {
e: Exception? ->
e?.printStackTrace()
print(e?.message)
}

}

0 comments on commit 6bd5e38

Please sign in to comment.