From 893a69b3b6c99dd38ba31b87ae655ebbde712a3f Mon Sep 17 00:00:00 2001 From: ramabit Date: Fri, 22 Jan 2016 16:40:37 -0300 Subject: [PATCH 1/3] #16 only main task is strongly necessary --- ...TaskBlocksTest.java => BlocksInsideTest.java} | 2 +- ...unctionsTest.java => RefactorBlocksTest.java} | 2 +- .../com/inaka/killertask/TaskOnlyExample.java | 16 ++++++++++++++++ .../java/com/inaka/killertask/ExampleOnlyTask.kt | 15 +++++++++++++++ .../main/java/com/inaka/killertask/KillerTask.kt | 2 +- 5 files changed, 34 insertions(+), 3 deletions(-) rename library/src/androidTest/java/com/inaka/killertask/{KillerTaskBlocksTest.java => BlocksInsideTest.java} (80%) rename library/src/androidTest/java/com/inaka/killertask/{KillerTaskFunctionsTest.java => RefactorBlocksTest.java} (80%) create mode 100644 library/src/androidTest/java/com/inaka/killertask/TaskOnlyExample.java create mode 100644 library/src/main/java/com/inaka/killertask/ExampleOnlyTask.kt diff --git a/library/src/androidTest/java/com/inaka/killertask/KillerTaskBlocksTest.java b/library/src/androidTest/java/com/inaka/killertask/BlocksInsideTest.java similarity index 80% rename from library/src/androidTest/java/com/inaka/killertask/KillerTaskBlocksTest.java rename to library/src/androidTest/java/com/inaka/killertask/BlocksInsideTest.java index 5bcc3c2..69add0f 100644 --- a/library/src/androidTest/java/com/inaka/killertask/KillerTaskBlocksTest.java +++ b/library/src/androidTest/java/com/inaka/killertask/BlocksInsideTest.java @@ -7,7 +7,7 @@ /** * Created by inaka on 1/20/16. */ -public class KillerTaskBlocksTest extends AndroidTestCase { +public class BlocksInsideTest extends AndroidTestCase { @UiThreadTest public void testLibraryWithBlocks() { diff --git a/library/src/androidTest/java/com/inaka/killertask/KillerTaskFunctionsTest.java b/library/src/androidTest/java/com/inaka/killertask/RefactorBlocksTest.java similarity index 80% rename from library/src/androidTest/java/com/inaka/killertask/KillerTaskFunctionsTest.java rename to library/src/androidTest/java/com/inaka/killertask/RefactorBlocksTest.java index d0d15f5..e98745a 100644 --- a/library/src/androidTest/java/com/inaka/killertask/KillerTaskFunctionsTest.java +++ b/library/src/androidTest/java/com/inaka/killertask/RefactorBlocksTest.java @@ -7,7 +7,7 @@ /** * Created by inaka on 1/21/16. */ -public class KillerTaskFunctionsTest extends AndroidTestCase { +public class RefactorBlocksTest extends AndroidTestCase { @UiThreadTest public void testLibraryFunctionsRefactor() { diff --git a/library/src/androidTest/java/com/inaka/killertask/TaskOnlyExample.java b/library/src/androidTest/java/com/inaka/killertask/TaskOnlyExample.java new file mode 100644 index 0000000..00880c6 --- /dev/null +++ b/library/src/androidTest/java/com/inaka/killertask/TaskOnlyExample.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 TaskOnlyExample extends AndroidTestCase { + + @UiThreadTest + public void testLibraryWithBlocks() { + new ExampleOnlyTask(); + } + +} diff --git a/library/src/main/java/com/inaka/killertask/ExampleOnlyTask.kt b/library/src/main/java/com/inaka/killertask/ExampleOnlyTask.kt new file mode 100644 index 0000000..1f29930 --- /dev/null +++ b/library/src/main/java/com/inaka/killertask/ExampleOnlyTask.kt @@ -0,0 +1,15 @@ +package com.inaka.killertask + +import android.util.Log +import java.util.concurrent.CountDownLatch + +/** + * Created by inaka on 1/22/16. + */ +private class ExampleOnlyTask { + + init { + KillerTask({ Log.wtf("LOG", "KillerTask is awesome") }).go() + } + +} \ 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 From e1aced3284c149dbae5fd476766c418f9ad0c665 Mon Sep 17 00:00:00 2001 From: ramabit Date: Fri, 22 Jan 2016 16:55:42 -0300 Subject: [PATCH 2/3] #16 add several examples and tests --- ...ample.java => VariableParametersTest.java} | 4 +- .../com/inaka/killertask/ExampleOnlyTask.kt | 15 -------- .../ExampleVariableParametersTasks.kt | 37 +++++++++++++++++++ 3 files changed, 39 insertions(+), 17 deletions(-) rename library/src/androidTest/java/com/inaka/killertask/{TaskOnlyExample.java => VariableParametersTest.java} (66%) delete mode 100644 library/src/main/java/com/inaka/killertask/ExampleOnlyTask.kt create mode 100644 library/src/main/java/com/inaka/killertask/ExampleVariableParametersTasks.kt diff --git a/library/src/androidTest/java/com/inaka/killertask/TaskOnlyExample.java b/library/src/androidTest/java/com/inaka/killertask/VariableParametersTest.java similarity index 66% rename from library/src/androidTest/java/com/inaka/killertask/TaskOnlyExample.java rename to library/src/androidTest/java/com/inaka/killertask/VariableParametersTest.java index 00880c6..6fda73c 100644 --- a/library/src/androidTest/java/com/inaka/killertask/TaskOnlyExample.java +++ b/library/src/androidTest/java/com/inaka/killertask/VariableParametersTest.java @@ -6,11 +6,11 @@ /** * Created by inaka on 1/22/16. */ -public class TaskOnlyExample extends AndroidTestCase { +public class VariableParametersTest extends AndroidTestCase { @UiThreadTest public void testLibraryWithBlocks() { - new ExampleOnlyTask(); + new ExampleVariableParametersTasks(); } } diff --git a/library/src/main/java/com/inaka/killertask/ExampleOnlyTask.kt b/library/src/main/java/com/inaka/killertask/ExampleOnlyTask.kt deleted file mode 100644 index 1f29930..0000000 --- a/library/src/main/java/com/inaka/killertask/ExampleOnlyTask.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.inaka.killertask - -import android.util.Log -import java.util.concurrent.CountDownLatch - -/** - * Created by inaka on 1/22/16. - */ -private class ExampleOnlyTask { - - init { - KillerTask({ Log.wtf("LOG", "KillerTask is awesome") }).go() - } - -} \ No newline at end of file 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 From bb30ff7d18d83d1b9e0b1744988e6bf5df008019 Mon Sep 17 00:00:00 2001 From: ramabit Date: Fri, 22 Jan 2016 16:58:44 -0300 Subject: [PATCH 3/3] #16 refactor --- .../androidTest/java/com/inaka/killertask/BlocksInsideTest.java | 2 +- .../java/com/inaka/killertask/RefactorBlocksTest.java | 2 +- .../{ExampleAllTogether.kt => ExampleBlocksInside.kt} | 2 +- .../{ExampleFunctionsRefactor.kt => ExampleBlocksRefactor.kt} | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename library/src/main/java/com/inaka/killertask/{ExampleAllTogether.kt => ExampleBlocksInside.kt} (94%) rename library/src/main/java/com/inaka/killertask/{ExampleFunctionsRefactor.kt => ExampleBlocksRefactor.kt} (96%) diff --git a/library/src/androidTest/java/com/inaka/killertask/BlocksInsideTest.java b/library/src/androidTest/java/com/inaka/killertask/BlocksInsideTest.java index 69add0f..562e852 100644 --- a/library/src/androidTest/java/com/inaka/killertask/BlocksInsideTest.java +++ b/library/src/androidTest/java/com/inaka/killertask/BlocksInsideTest.java @@ -11,7 +11,7 @@ public class BlocksInsideTest extends AndroidTestCase { @UiThreadTest public void testLibraryWithBlocks() { - new ExampleAllTogether(); + new ExampleBlocksInside(); } } diff --git a/library/src/androidTest/java/com/inaka/killertask/RefactorBlocksTest.java b/library/src/androidTest/java/com/inaka/killertask/RefactorBlocksTest.java index e98745a..84cfdea 100644 --- a/library/src/androidTest/java/com/inaka/killertask/RefactorBlocksTest.java +++ b/library/src/androidTest/java/com/inaka/killertask/RefactorBlocksTest.java @@ -11,7 +11,7 @@ public class RefactorBlocksTest extends AndroidTestCase { @UiThreadTest public void testLibraryFunctionsRefactor() { - new ExampleFunctionsRefactor(); + new ExampleBlocksRefactor(); } } 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