diff --git a/library/src/androidTest/java/com/inaka/killertask/KillerTaskBlocksTest.java b/library/src/androidTest/java/com/inaka/killertask/BlocksInsideTest.java similarity index 69% rename from library/src/androidTest/java/com/inaka/killertask/KillerTaskBlocksTest.java rename to library/src/androidTest/java/com/inaka/killertask/BlocksInsideTest.java index 5bcc3c2..562e852 100644 --- a/library/src/androidTest/java/com/inaka/killertask/KillerTaskBlocksTest.java +++ b/library/src/androidTest/java/com/inaka/killertask/BlocksInsideTest.java @@ -7,11 +7,11 @@ /** * Created by inaka on 1/20/16. */ -public class KillerTaskBlocksTest extends AndroidTestCase { +public class BlocksInsideTest extends AndroidTestCase { @UiThreadTest public void testLibraryWithBlocks() { - new ExampleAllTogether(); + new ExampleBlocksInside(); } } diff --git a/library/src/androidTest/java/com/inaka/killertask/KillerTaskFunctionsTest.java b/library/src/androidTest/java/com/inaka/killertask/RefactorBlocksTest.java similarity index 68% rename from library/src/androidTest/java/com/inaka/killertask/KillerTaskFunctionsTest.java rename to library/src/androidTest/java/com/inaka/killertask/RefactorBlocksTest.java index d0d15f5..84cfdea 100644 --- a/library/src/androidTest/java/com/inaka/killertask/KillerTaskFunctionsTest.java +++ b/library/src/androidTest/java/com/inaka/killertask/RefactorBlocksTest.java @@ -7,11 +7,11 @@ /** * Created by inaka on 1/21/16. */ -public class KillerTaskFunctionsTest extends AndroidTestCase { +public class RefactorBlocksTest extends AndroidTestCase { @UiThreadTest public void testLibraryFunctionsRefactor() { - new ExampleFunctionsRefactor(); + new ExampleBlocksRefactor(); } } diff --git a/library/src/androidTest/java/com/inaka/killertask/VariableParametersTest.java b/library/src/androidTest/java/com/inaka/killertask/VariableParametersTest.java new file mode 100644 index 0000000..6fda73c --- /dev/null +++ b/library/src/androidTest/java/com/inaka/killertask/VariableParametersTest.java @@ -0,0 +1,16 @@ +package com.inaka.killertask; + +import android.test.AndroidTestCase; +import android.test.UiThreadTest; + +/** + * Created by inaka on 1/22/16. + */ +public class VariableParametersTest extends AndroidTestCase { + + @UiThreadTest + public void testLibraryWithBlocks() { + new ExampleVariableParametersTasks(); + } + +} diff --git a/library/src/main/java/com/inaka/killertask/ExampleAllTogether.kt b/library/src/main/java/com/inaka/killertask/ExampleBlocksInside.kt similarity index 94% rename from library/src/main/java/com/inaka/killertask/ExampleAllTogether.kt rename to library/src/main/java/com/inaka/killertask/ExampleBlocksInside.kt index 98081f6..4047869 100644 --- a/library/src/main/java/com/inaka/killertask/ExampleAllTogether.kt +++ b/library/src/main/java/com/inaka/killertask/ExampleBlocksInside.kt @@ -6,7 +6,7 @@ import java.util.concurrent.CountDownLatch /** * Created by inaka on 1/20/16. */ -private class ExampleAllTogether { +private class ExampleBlocksInside { val signal = CountDownLatch(1); init { diff --git a/library/src/main/java/com/inaka/killertask/ExampleFunctionsRefactor.kt b/library/src/main/java/com/inaka/killertask/ExampleBlocksRefactor.kt similarity index 96% rename from library/src/main/java/com/inaka/killertask/ExampleFunctionsRefactor.kt rename to library/src/main/java/com/inaka/killertask/ExampleBlocksRefactor.kt index 813970e..a5bd6a9 100644 --- a/library/src/main/java/com/inaka/killertask/ExampleFunctionsRefactor.kt +++ b/library/src/main/java/com/inaka/killertask/ExampleBlocksRefactor.kt @@ -9,7 +9,7 @@ import java.util.concurrent.CountDownLatch /** * Created by inaka on 1/21/16. */ -private class ExampleFunctionsRefactor { +private class ExampleBlocksRefactor { val signal = CountDownLatch(1); // onSuccess function diff --git a/library/src/main/java/com/inaka/killertask/ExampleVariableParametersTasks.kt b/library/src/main/java/com/inaka/killertask/ExampleVariableParametersTasks.kt new file mode 100644 index 0000000..db4d4bd --- /dev/null +++ b/library/src/main/java/com/inaka/killertask/ExampleVariableParametersTasks.kt @@ -0,0 +1,37 @@ +package com.inaka.killertask + +import android.util.Log +import java.util.concurrent.CountDownLatch +import java.util.concurrent.TimeUnit + +/** + * Created by inaka on 1/22/16. + */ +private class ExampleVariableParametersTasks { + + val signal = CountDownLatch(1); + + init { + // 1) + KillerTask({ Log.wtf("LOG", "KillerTask is awesome") }).go() // only main task + + // 2) + KillerTask( + { Log.wtf("LOG", "KillerTask is awesome") }, // main task + { Log.wtf("LOG", "Super awesome!")} // onSuccess + ).go() + + // 3) + KillerTask( + { // main task + Log.wtf("LOG", "KillerTask is awesome") + "super" // implicit return + }, + {}, // onSuccess is empty + { e: Exception? -> Log.wtf("LOG", e.toString()) } // onFailed + ).go() + + signal.await(5, TimeUnit.SECONDS) + } + +} \ No newline at end of file diff --git a/library/src/main/java/com/inaka/killertask/KillerTask.kt b/library/src/main/java/com/inaka/killertask/KillerTask.kt index dff5dda..9fff4ab 100644 --- a/library/src/main/java/com/inaka/killertask/KillerTask.kt +++ b/library/src/main/java/com/inaka/killertask/KillerTask.kt @@ -3,7 +3,7 @@ package com.inaka.killertask import android.os.AsyncTask import android.util.Log -class KillerTask(val task: () -> T, val onSuccess: (T) -> Any, val onFailed: (Exception?) -> Any) : AsyncTask() { +class KillerTask(val task: () -> T, val onSuccess: (T) -> Any = {}, val onFailed: (Exception?) -> Any = {}) : AsyncTask() { private var exception: Exception? = null