@InteractAs

Offers an alternative to InteractionService 's imperative approach to switch the InteractionContext for a given block of JUnit test code.

Example:

@Test
@InteractAs(
    userName = "sven",
    localeName = "en",
    frozenDateTime = "2010-01-01 13:02:04 -03")
void test() {
    // ...
}

It can also be applied to a class, meaning it will apply to all tests within that class.

API

InteractAs.java
@interface InteractAs {
  String userName() default // unspecified
"";     (1)
  String localeName() default // unspecified
"";     (2)
  String frozenDateTime() default // unspecified
"";     (3)
}
1 userName

If empty, defaults to the system user (with elevated privileges).

2 localeName

The Locale language tag. Eg. "en", "fr", "de", …​ If empty, defaults to current system locale.

3 frozenDateTime

If empty, defaults to current system time.

Members

userName

If empty, defaults to the system user (with elevated privileges).

localeName

The Locale language tag. Eg. "en", "fr", "de", …​ If empty, defaults to current system locale.

frozenDateTime

If empty, defaults to current system time.

Format: _"yyyy-MM-dd HH:mm:ss[.SSS][' '][XXX][x]"_Examples:

  • "2022-01-31 14:04:33.017 -03:30" (full form)

  • "2022-01-31 14:04:33 -03" (no millis, no offset minutes)

  • "2022-01-31 14:04:33 Z" (no millis, no offset = UTC)