Skip to content

Commit

Permalink
#38: Removed code duplication. Introduced new asserts.
Browse files Browse the repository at this point in the history
  • Loading branch information
redcatbear committed Mar 5, 2019
1 parent 4dc9fb1 commit 4ab6c77
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.exasol.adapter.capabilities;

import static com.exasol.adapter.capabilities.CapabilityAssertions.*;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -31,7 +29,7 @@ void buildWithMainCapabilities() {
final MainCapability[] expectedCapabilities = { MainCapability.AGGREGATE_GROUP_BY_COLUMN,
MainCapability.AGGREGATE_GROUP_BY_EXPRESSION };
final Capabilities capabilities = this.builder.addMain(expectedCapabilities).build();
assertAll(() -> assertThat(capabilities.getMainCapabilities(), containsInAnyOrder(expectedCapabilities)), //
assertAll(() -> assertCapabilitesContainAllOf(capabilities, expectedCapabilities), //
() -> assertEmptyLiteralCapabilities(capabilities), //
() -> assertEmptyPredicateCapabilities(capabilities), //
() -> assertEmptyScalarFunctionCapabilities(capabilities), //
Expand All @@ -43,7 +41,7 @@ void buildWithLiteralCapabilities() {
final LiteralCapability[] expectedCapabilities = { LiteralCapability.BOOL, LiteralCapability.DATE };
final Capabilities capabilities = this.builder.addLiteral(expectedCapabilities).build();
assertAll(() -> assertEmptyMainCapabilities(capabilities), //
() -> assertThat(capabilities.getLiteralCapabilities(), containsInAnyOrder(expectedCapabilities)), //
() -> assertCapabilitesContainAllOf(capabilities, expectedCapabilities), //
() -> assertEmptyPredicateCapabilities(capabilities), //
() -> assertEmptyScalarFunctionCapabilities(capabilities), //
() -> assertEmptyAggregateFunctionCapatilities(capabilities));
Expand All @@ -55,7 +53,7 @@ void buildWithPredicateCapabilities() {
final Capabilities capabilities = this.builder.addPredicate(expectedCapabilities).build();
assertAll(() -> assertEmptyMainCapabilities(capabilities), //
() -> assertEmptyLiteralCapabilities(capabilities), //
() -> assertThat(capabilities.getPredicateCapabilities(), containsInAnyOrder(expectedCapabilities)), //
() -> assertCapabilitesContainAllOf(capabilities, expectedCapabilities), //
() -> assertEmptyScalarFunctionCapabilities(capabilities), //
() -> assertEmptyAggregateFunctionCapatilities(capabilities));
}
Expand All @@ -68,8 +66,7 @@ void buildWithScalarFunctionCapabilities() {
assertAll(() -> assertEmptyMainCapabilities(capabilities), //
() -> assertEmptyLiteralCapabilities(capabilities), //
() -> assertEmptyPredicateCapabilities(capabilities), //
() -> assertThat(capabilities.getScalarFunctionCapabilities(),
containsInAnyOrder(expectedCapabilities)), //
() -> assertCapabilitesContainAllOf(capabilities, expectedCapabilities), //
() -> assertEmptyAggregateFunctionCapatilities(capabilities));
}

Expand All @@ -82,7 +79,6 @@ void buildWithAggregateFunctionCapabilities() {
() -> assertEmptyLiteralCapabilities(capabilities), //
() -> assertEmptyPredicateCapabilities(capabilities), //
() -> assertEmptyScalarFunctionCapabilities(capabilities), //
() -> assertThat(capabilities.getAggregateFunctionCapabilities(),
containsInAnyOrder(expectedCapabilities)));
() -> assertCapabilitesContainAllOf(capabilities, expectedCapabilities));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.exasol.adapter.capabilities;

import static org.hamcrest.collection.IsEmptyIterable.emptyIterableOf;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertThat;

public final class CapabilityAssertions {
Expand All @@ -27,4 +28,30 @@ public static void assertEmptyScalarFunctionCapabilities(final Capabilities capa
public static void assertEmptyAggregateFunctionCapatilities(final Capabilities capabilities) {
assertThat(capabilities.getAggregateFunctionCapabilities(), emptyIterableOf(AggregateFunctionCapability.class));
}

public static void assertCapabilitesContainAllOf(final Capabilities capabilities,
final MainCapability... expectedCapabilities) {
assertThat(capabilities.getMainCapabilities(), containsInAnyOrder(expectedCapabilities));
}

public static void assertCapabilitesContainAllOf(final Capabilities capabilities,
final LiteralCapability... expectedCapabilities) {
assertThat(capabilities.getLiteralCapabilities(), containsInAnyOrder(expectedCapabilities));
}

public static void assertCapabilitesContainAllOf(final Capabilities capabilities,
final PredicateCapability... expectedCapabilities) {
assertThat(capabilities.getPredicateCapabilities(), containsInAnyOrder(expectedCapabilities));
}

public static void assertCapabilitesContainAllOf(final Capabilities capabilities,
final ScalarFunctionCapability... expectedCapabilities) {
assertThat(capabilities.getScalarFunctionCapabilities(), containsInAnyOrder(expectedCapabilities));
}

public static void assertCapabilitesContainAllOf(final Capabilities capabilities,
final AggregateFunctionCapability... expectedCapabilities) {
assertThat(capabilities.getAggregateFunctionCapabilities(), containsInAnyOrder(expectedCapabilities));
}

}

0 comments on commit 4ab6c77

Please sign in to comment.