Skip to content

Instantly share code, notes, and snippets.

@soeirosantos
Created August 27, 2013 14:57
Show Gist options
  • Save soeirosantos/6354674 to your computer and use it in GitHub Desktop.
Save soeirosantos/6354674 to your computer and use it in GitHub Desktop.
Groovy Module Extension
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(", ")
}
}
moduleName=util-module
moduleVersion=1.0
extensionClasses=br.com.soeirosantos.CustomMethods
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