Joann - Joda Annotation

Allows for trivial setting of Joda time in unit tests

Лицензия

Лицензия

Группа

Группа

com.elevenware
Идентификатор

Идентификатор

joann
Последняя версия

Последняя версия

1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

Joann - Joda Annotation
Allows for trivial setting of Joda time in unit tests
Ссылка на сайт

Ссылка на сайт

https://github.com/georgecodes/joann
Система контроля версий

Система контроля версий

http://github.com/georgecodes/joann

Скачать joann

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.elevenware/joann/ -->
<dependency>
    <groupId>com.elevenware</groupId>
    <artifactId>joann</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.elevenware/joann/
implementation 'com.elevenware:joann:1.0'
// https://jarcasting.com/artifacts/com.elevenware/joann/
implementation ("com.elevenware:joann:1.0")
'com.elevenware:joann:jar:1.0'
<dependency org="com.elevenware" name="joann" rev="1.0">
  <artifact name="joann" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.elevenware', module='joann', version='1.0')
)
libraryDependencies += "com.elevenware" % "joann" % "1.0"
[com.elevenware/joann "1.0"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.10
xmlunit : xmlunit jar 1.2
joda-time : joda-time jar 1.6.2

runtime (1)

Идентификатор библиотеки Тип Версия
org.codehaus.groovy : groovy-all jar 1.8.1

test (1)

Идентификатор библиотеки Тип Версия
org.spockframework : spock-core jar 0.6-groovy-1.7

Модули Проекта

Данный проект не имеет модулей.

#JoAnn

Build Status

JoAnn - Joda Annotation - makes the use of Joda time in your tests easier, and gets boilerplate out of the way.

Writing some tests recently, as is often the case, I found myself reaching for Joda Time. This library, as most Java devs know, is less painful to deal with than the date utilities that the JDK ships with. The other neat thing about it is, you can set the system time - well, Joda's view of it - to whatever you want. Very handy for testing code that might at some point create dates.

Anyways, a typical way of using Joda time in a test looks something like this

class TestSomething {

    @Test
    void testthings() {
        DateTimeUtils.setCurrentMillisFixed(1385554748577L)
        // do some things
    }

    @After
    void reset() {
        DateTimeutils.setCurrentMillisSystem()
    }
}

A few things wrong here. First, it's tedious having to work in milliseconds. Second it's not especially legible, and thirdly you have to remember to reset the time to the real time in a teardown method in case your test fails.

So I came up with JoAnn, which makes things a bit simpler. JoAnn is so called because it's a Joda Annotation. It looks a bit like this

@Test
@Joda(1385554748577L)
void testthings() {
    // do some things
}

That's (almost) it. No time fiddling bleeding into your tests, no need to remember to tear it down. Just the annotation. Oh, and a way of getting it invoked. You can use either a JUnit runner, or a JUnit rule, it makes no difference. I've provided both

With a rule

class MyTests {
    @Rule public JodaRule rule = new JodaRule()
}

With a runner

@RunWith(JodaAwareJUnit4Runner)
class MyTests {

}

It gets even less tedious.

You don't have to use milliseconds to set the time. Set a timestamp instead, and JoAnn will assume you meant an ISO8601 format

@Test
@Joda(timestamp = "2013-11-29T10:13:22.192Z")
void testTheThings() {}

Or there are a few more out of the box:

@Test
@Joda(timestamp = "2013-12-25", format = Format.YYYYMMDD)
void testMoreStuff() {}

@Test
@Joda(timestamp = "2012-11-19 13:03:22", format = Format.YYYYMMDD_HHMMSS)
void keepOnTesting() {}

Want to see the code? It's on GitHub

Want to use it in a Maven project? It's now in Maven central.

<dependencies>
    <dependency>
        <groupId>com.elevenware</groupId>
        <artifactId>joann</artifactId>
        <version>1.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Enjoy.

Версии библиотеки

Версия
1.0