public final class Tests
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
assertHasPrivateParameterlessCtor(java.lang.Class<?> targetClass)
Asserts that if the passed class has private parameter-less constructor and invokes it
using Reflection.
|
static void |
assertInDelta(long expectedValue,
long actualValue,
long delta)
Asserts that the difference between expected value and actual value is not bigger
than the set delta.
|
static void |
assertMatchesMask(com.google.protobuf.Message message,
com.google.protobuf.FieldMask fieldMask)
Asserts that the passed message has a field that matches the passed field mask.
|
static void |
halt()
Reports that a calling method should never be called by throwing
AssertionError . |
static <T> T |
nullRef()
Returns
null . |
static void |
repeat(int count,
java.lang.Runnable action)
Repeats the passed action the
count number of times. |
public static void assertHasPrivateParameterlessCtor(java.lang.Class<?> targetClass)
Typically this method is used to add a constructor of a utility class into the covered code.
Example:
public class MyUtilityShould ... @Test public void have_private_utility_ctor() { assertHasPrivateParameterlessCtor(MyUtility.class)); }
public static <T> T nullRef()
null
.
Use it when it is needed to pass null
to a method in tests so that no
warnings suppression is needed.
Class<T>
to keep
the test API small and convenientpublic static void assertMatchesMask(com.google.protobuf.Message message, com.google.protobuf.FieldMask fieldMask)
If the passed mask contains repeated message fields, asserts whether that field repeats at least once, e.g. for a mask of
mask {
paths: friends
}
and messages
message Animal {
string kind = 1;
}
message User {
string name = 1;
repeated User friends = 2;
repeated Animal animals = 3;
}
the mask matches if a user has at least one friend.
However, a mask
mask {
paths: animals.kind
}
will never match against a user, since if a repeated field is a part of the mask,
it should always be the last part of its path.message
- the message to assertfieldMask
- which is matched against the message fieldjava.lang.AssertionError
- if the check failspublic static void assertInDelta(long expectedValue, long actualValue, long delta)
The assertion will be passed if the actual delta equals to the set one.
expectedValue
- expected valueactualValue
- actual valuedelta
- the maximum expected difference between the valuespublic static void repeat(int count, java.lang.Runnable action)
count
number of times.public static void halt() throws java.lang.AssertionError
AssertionError
.java.lang.AssertionError
- always