Created
August 27, 2013 14:57
-
-
Save soeirosantos/6354674 to your computer and use it in GitHub Desktop.
Groovy Module Extension
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
package br.com.soeirosantos | |
import java.text.SimpleDateFormat | |
class CustomMethods { | |
static isNotBlank(String self) { | |
!self.trim().isEmpty() | |
} | |
static toShortFormat(Date self) { | |
self.format("dd/MM/yyyy") | |
} | |
static toHeaderFormat(Date self, String city) { | |
def dateFormat = new SimpleDateFormat("dd 'de' MMMMM 'de' yyyy", new Locale("pt") ).format(self) | |
"$city, $dateFormat." | |
} | |
static toString(ArrayList self) { | |
self.join(", ") | |
} | |
} |
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
moduleName=util-module | |
moduleVersion=1.0 | |
extensionClasses=br.com.soeirosantos.CustomMethods |
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
package br.com.soeirosantos | |
import org.junit.Test; | |
class UtilTest { | |
@Test | |
public void test() { | |
assert "foo".isNotBlank() | |
assert ! " ".isNotBlank() | |
def dt = new Date(1377614221138) | |
assert "27/08/2013" == dt.toShortFormat() | |
assert "Niterói, 27 de Agosto de 2013." == dt.toHeaderFormat("Niterói") | |
assert "1, 2, 3, 4, 5" == [1, 2, 3, 4, 5].toString() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment