Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Error Prone #712

Merged
merged 56 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ca3791b
Add Error Prone compiler
alexander-yevsyukov May 22, 2018
a31f735
Change `Nullable`, address some ret. vals
alexander-yevsyukov May 22, 2018
cdd6f28
Handle ignored return values
alexander-yevsyukov May 22, 2018
6a287f4
Handle checking return values
alexander-yevsyukov May 23, 2018
3c8ba11
Handle checking return values
alexander-yevsyukov May 23, 2018
9243298
Extract variable
alexander-yevsyukov May 23, 2018
a963623
Use `Nullable` from the Checker framework
alexander-yevsyukov May 24, 2018
d519c98
Fix using generic param as qualifier
alexander-yevsyukov May 24, 2018
a3c5013
Handle return values
alexander-yevsyukov May 24, 2018
9b3849c
Handle ignored return values
alexander-yevsyukov May 26, 2018
1692180
Handle ignored return values
alexander-yevsyukov May 26, 2018
0980153
Handle ignored return values
alexander-yevsyukov May 27, 2018
86c9ae0
Handle ignored return values
alexander-yevsyukov May 27, 2018
95e2f77
Handle ignored return values
alexander-yevsyukov May 27, 2018
4721160
Fix tests
alexander-yevsyukov May 27, 2018
6b27e92
Fix test
alexander-yevsyukov May 27, 2018
9eb65ce
Fix test
alexander-yevsyukov May 28, 2018
735dd14
Fix tests
alexander-yevsyukov May 28, 2018
e50ddd3
Fix tests
alexander-yevsyukov May 28, 2018
1805508
Merge remote-tracking branch 'remotes/origin/master' into error-prone
alexander-yevsyukov May 28, 2018
f50ab3f
Merge remote-tracking branch 'remotes/origin/master' into error-prone
alexander-yevsyukov May 28, 2018
474130f
Improve code layout
alexander-yevsyukov May 28, 2018
8fdda34
Optimize imports
alexander-yevsyukov May 28, 2018
116d7df
Optimize imports
alexander-yevsyukov May 28, 2018
ea04d7a
Improve code layout
alexander-yevsyukov May 30, 2018
dc646e0
Fix EOF
alexander-yevsyukov May 30, 2018
8a9ec74
Extract aggregate reading operation as a method object
alexander-yevsyukov May 30, 2018
2d153ea
Improve code layout
alexander-yevsyukov May 30, 2018
352edf0
Remove redundant `inheritDoc`
alexander-yevsyukov May 30, 2018
203a3ad
Remove unused methods
alexander-yevsyukov May 30, 2018
505821b
Fix Javadoc layout
alexander-yevsyukov May 30, 2018
ec2cab9
Improve code layout
alexander-yevsyukov May 30, 2018
425fae2
Fix code layout
alexander-yevsyukov May 30, 2018
8917a70
Allow several types of nullable annotations
alexander-yevsyukov May 30, 2018
dc9e982
Simplify work with streams
alexander-yevsyukov May 30, 2018
a243fa3
Simplify var type
alexander-yevsyukov May 30, 2018
860c0c2
Fix code layout
alexander-yevsyukov May 30, 2018
08d16b4
Improve code layout
alexander-yevsyukov May 30, 2018
621c4eb
Improve code layout
alexander-yevsyukov May 30, 2018
8b881d8
Improve code layout
alexander-yevsyukov May 30, 2018
dbb62a9
Align generic params
alexander-yevsyukov May 30, 2018
d4039d8
Improve code layout
alexander-yevsyukov May 30, 2018
5ba1a15
Add static import
alexander-yevsyukov May 30, 2018
b9f1c0f
Use streams
alexander-yevsyukov May 30, 2018
febd39e
Fix code layout
alexander-yevsyukov May 30, 2018
1bd2d02
Merge remote-tracking branch 'remotes/origin/master' into error-prone
alexander-yevsyukov May 31, 2018
1c4823d
Resolve Error Prone errors
alexander-yevsyukov May 31, 2018
6b59984
Remove some `final`s for local vars
alexander-yevsyukov May 31, 2018
6064a57
Simplify a stream op.
alexander-yevsyukov May 31, 2018
1dbaead
Extract method
alexander-yevsyukov May 31, 2018
70072bf
Remove redundant formatting calls
alexander-yevsyukov May 31, 2018
ed402e3
Use statically imported methods for streams
alexander-yevsyukov May 31, 2018
2bf51b3
Extract variables
alexander-yevsyukov May 31, 2018
c260016
Merge remote-tracking branch 'remotes/origin/master' into error-prone
alexander-yevsyukov May 31, 2018
ae3b3bf
Remove `final` var qualifier
alexander-yevsyukov May 31, 2018
e812167
Improve code layout
alexander-yevsyukov May 31, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 27 additions & 31 deletions client/src/test/java/io/spine/client/ActorRequestFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,42 +95,38 @@ void passNullToleranceCheck() {
.testInstanceMethods(factory(), NullPointerTester.Visibility.PUBLIC);
}

@Nested
@DisplayName("in Builder")
class BuilderTest {
@Test
@DisplayName("require actor in Builder")
void requireActorInBuilder() {
assertThrows(NullPointerException.class, () -> builder().setZoneOffset(zoneOffset)
.build());
}

@Test
@DisplayName("require actor")
void requireActor() {
assertThrows(NullPointerException.class, () -> builder().setZoneOffset(zoneOffset)
.build());
}
@Test
@DisplayName("return values set in Builder")
void returnValuesSetInBuilder() {
final ActorRequestFactory.Builder builder = builder()
.setActor(actor)
.setZoneOffset(zoneOffset);
assertNotNull(builder.getActor());
assertNotNull(builder.getZoneOffset());
assertNull(builder.getTenantId());
}

@Test
@DisplayName("return set values")
void returnSetValues() {
final ActorRequestFactory.Builder builder = builder()
.setActor(actor)
.setZoneOffset(zoneOffset);
assertNotNull(builder.getActor());
assertNotNull(builder.getZoneOffset());
assertNull(builder.getTenantId());
}
@Test
@DisplayName("be single tenant by default")
void beSingleTenant() {
assertNull(factory().getTenantId());
}

@SuppressWarnings("unused") // Used via reflection by JUnit.
@Nested
@DisplayName("when created")
class WhenCreatedTest {

@Test
@DisplayName("be single tenant")
void beSingleTenant() {
assertNull(factory().getTenantId());
}
@DisplayName("when created, store")
class Store {

@Test
@DisplayName("store given user")
void storeUser() {
@DisplayName("given user")
void givenUser() {
final int currentOffset = ZoneOffsets.getDefault()
.getAmountSeconds();
final ActorRequestFactory aFactory = builder()
Expand All @@ -143,8 +139,8 @@ void storeUser() {
}

@Test
@DisplayName("store given user and timezone")
void storeUserAndTimezone() {
@DisplayName("given user and timezone")
void givenUserAndTimezone() {
assertEquals(actor, factory().getActor());
assertEquals(zoneOffset, factory().getZoneOffset());
}
Expand Down
75 changes: 39 additions & 36 deletions client/src/test/java/io/spine/client/ColumnFiltersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import static io.spine.client.ColumnFilter.Operator.GREATER_THAN;
import static io.spine.client.ColumnFilter.Operator.LESS_OR_EQUAL;
import static io.spine.client.ColumnFilter.Operator.LESS_THAN;
import static io.spine.client.ColumnFilters.all;
import static io.spine.client.ColumnFilters.either;
import static io.spine.client.ColumnFilters.eq;
import static io.spine.client.ColumnFilters.ge;
import static io.spine.client.ColumnFilters.gt;
Expand Down Expand Up @@ -87,42 +85,42 @@ void passNullToleranceCheck() {
}

@Nested
@DisplayName("when creating column filter")
class CreateFilterTest {
@DisplayName("create column filter of type")
class CreateFilterOfType {

@Test
@DisplayName("successfully create `equals` filter")
void createEquals() {
@DisplayName("`equals`")
void equals() {
checkCreatesInstance(eq(COLUMN_NAME, COLUMN_VALUE), EQUAL);
}

@Test
@DisplayName("successfully create `greater than` filter")
void createGreaterThan() {
@DisplayName("`greater than`")
void greaterThan() {
checkCreatesInstance(gt(COLUMN_NAME, COLUMN_VALUE), GREATER_THAN);
}

@Test
@DisplayName("successfully create `greater than or equals` filter")
void createGreaterOrEqual() {
@DisplayName("`greater than or equals`")
void greaterOrEqual() {
checkCreatesInstance(ge(COLUMN_NAME, COLUMN_VALUE), GREATER_OR_EQUAL);
}

@Test
@DisplayName("successfully create `less than` filter")
void createLessThan() {
@DisplayName("`less than`")
void lessThan() {
checkCreatesInstance(lt(COLUMN_NAME, COLUMN_VALUE), LESS_THAN);
}

@Test
@DisplayName("successfully create `less than or equals` filter")
void createLessOrEqual() {
@DisplayName("`less than or equals`")
void lessOrEqual() {
checkCreatesInstance(le(COLUMN_NAME, COLUMN_VALUE), LESS_OR_EQUAL);
}

@Test
@DisplayName("successfully create `equals` filter for enumerated types")
void createEqualsForEnum() {
@DisplayName("`equals` for enumerated types")
void equalsForEnum() {
final ColumnFilter filter = eq(ENUM_COLUMN_NAME, ENUM_COLUMN_VALUE);
assertEquals(ENUM_COLUMN_NAME, filter.getColumnName());
assertEquals(toAny(ENUM_COLUMN_VALUE), filter.getValue());
Expand All @@ -138,27 +136,27 @@ private void checkCreatesInstance(ColumnFilter filter,
}

@Nested
@DisplayName("when creating composite column filter")
class CreateCompositeFilterTest {
@DisplayName("create composite column filter of type")
class CreateCompositeFilterOfType {

@Test
@DisplayName("successfully create `all` grouping")
void createAll() {
@DisplayName("`all`")
void all() {
final ColumnFilter[] filters = {
le(COLUMN_NAME, COLUMN_VALUE),
ge(COLUMN_NAME, COLUMN_VALUE)
};
checkCreatesInstance(all(filters[0], filters[1]), ALL, filters);
checkCreatesInstance(ColumnFilters.all(filters[0], filters[1]), ALL, filters);
}

@Test
@DisplayName("successfully create `either` grouping")
void createEither() {
@DisplayName("`either`")
void either() {
final ColumnFilter[] filters = {
lt(COLUMN_NAME, COLUMN_VALUE),
gt(COLUMN_NAME, COLUMN_VALUE)
};
checkCreatesInstance(either(filters[0], filters[1]), EITHER, filters);
checkCreatesInstance(ColumnFilters.either(filters[0], filters[1]), EITHER, filters);
}

private void checkCreatesInstance(CompositeColumnFilter filter,
Expand All @@ -170,12 +168,12 @@ private void checkCreatesInstance(CompositeColumnFilter filter,
}

@Nested
@DisplayName("when creating ordering filter")
class CreateOrderingFilterTest {
@DisplayName("create ordering filter")
class CreateOrderingFilter {

@Test
@DisplayName("successfully create ordering filter for numbers")
void createForNumber() {
@DisplayName("for numbers")
void forNumbers() {
final double number = 3.14;
final ColumnFilter filter = le("doubleColumn", number);
assertNotNull(filter);
Expand All @@ -185,33 +183,38 @@ void createForNumber() {
}

@Test
@DisplayName("successfully create ordering filter for strings")
void createForString() {
@DisplayName("for strings")
void forStrings() {
final String theString = "abc";
final ColumnFilter filter = gt("stringColumn", theString);
assertNotNull(filter);
assertEquals(GREATER_THAN, filter.getOperator());
final StringValue value = AnyPacker.unpack(filter.getValue());
assertEquals(theString, value.getValue());
}
}

@Nested
@DisplayName("fail to create ordering filter")
class FailToCreateOrderingFilter {

@Test
@DisplayName("fail to create ordering filter for enumerated types")
void failForEnum() {
@DisplayName("for enumerated types")
void forEnums() {
assertThrows(IllegalArgumentException.class,
() -> ge(ENUM_COLUMN_NAME, ENUM_COLUMN_VALUE));
}

@Test
@DisplayName("fail to create ordering filter for non primitive number types")
void failForNonPrimitiveNumber() {
@DisplayName("for non primitive number types")
void forNonPrimitiveNumbers() {
final AtomicInteger number = new AtomicInteger(42);
assertThrows(IllegalArgumentException.class, () -> ge("atomicColumn", number));
}

@Test
@DisplayName("fail to create ordering filter for not supported types")
void failForNotSupportedType() {
@DisplayName("for not supported types")
void forUnsupportedTypes() {
final Comparable<?> value = Calendar.getInstance(); // Comparable but not supported
assertThrows(IllegalArgumentException.class, () -> le("invalidColumn", value));
}
Expand Down
29 changes: 17 additions & 12 deletions client/src/test/java/io/spine/client/CommandFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ void createCommandContext() {
}

@Nested
@DisplayName("on command instance creation")
class CreateCommandTest {
@DisplayName("create command")
class CreateCommand {

@Test
@DisplayName("assign current time to command")
void createWithTimestamp() {
@DisplayName("with current time")
void withTimestamp() {
// We are creating a range of +/- second between the call to make sure the timestamp
// would fit into this range. The purpose of this test is to make sure it works with
// this precision and to add coverage.
Expand All @@ -89,8 +89,8 @@ void createWithTimestamp() {
}

@Test
@DisplayName("assign given entity version to command")
void createWithEntityVersion() {
@DisplayName("with given entity version")
void withEntityVersion() {
final Command command = factory().command()
.create(StringValue.getDefaultInstance(), 2);

Expand All @@ -99,8 +99,8 @@ void createWithEntityVersion() {
}

@Test
@DisplayName("assign own tenant ID to command")
void createWithTenantID() {
@DisplayName("with own tenant ID")
void withOwnTenantID() {
final TenantId tenantId = TenantId.newBuilder()
.setValue(getClass().getSimpleName())
.build();
Expand All @@ -116,18 +116,23 @@ void createWithTenantID() {
.getActorContext()
.getTenantId());
}
}

@Nested
@DisplayName("throw ValidationException when creating command")
class NotAccept {

@Test
@DisplayName("throw ValidationException if supplied with invalid Message")
void failForInvalidMessage() {
@DisplayName("from invalid Message")
void invalidMessage() {
final RequiredFieldCommand invalidCommand = RequiredFieldCommand.getDefaultInstance();
assertThrows(ValidationException.class, () -> factory().command()
.create(invalidCommand));
}

@Test
@DisplayName("throw ValidationException if supplied with invalid Message with version")
void failForInvalidMessageWithVersion() {
@DisplayName("from invalid Message with version")
void invalidMessageWithVersion() {
final RequiredFieldCommand invalidCommand = RequiredFieldCommand.getDefaultInstance();
assertThrows(ValidationException.class, () -> factory().command()
.create(invalidCommand, 42));
Expand Down
Loading