ElementaryOperator extends Operator<Self> { @SuppressWarnings("unchecked") protected Contract getContract(final Schema globalSchema) { final Class<? extends Stub> stubClass = this.getStubClass(); if (stubClass == null) throw new IllegalStateException("no implementing stub found"); final Class<? extends Contract> contractClass = ContractUtil .getContractClass(stubClass); if (contractClass == null) throw new IllegalStateException("no associated contract found"); try { if (contractClass == ReduceContract.class) { int[] keyIndices = this.getKeyIndices(globalSchema, this.getKeyExpressions(0)); ReduceContract.Builder builder = ReduceContract.builder((Class<? extends ReduceStub>) stubClass); builder.name(this.toString()); PactBuilderUtil.addKeys(builder, this.getKeyClasses(globalSchema, keyIndices), keyIndices); return builder.build(); } else if (contractClass == CoGroupContract.class) { int[] keyIndices1 = this.getKeyIndices(globalSchema, this.getKeyExpressions(0)); int[] keyIndices2 = this.getKeyIndices(globalSchema, this.getKeyExpressions(1)); Class<? extends Key>[] keyTypes = this.getCommonKeyClasses(globalSchema, keyIndices1, keyIndices2); CoGroupContract.Builder builder = CoGroupContract.builder((Class<? extends CoGroupStub>) stubClass, keyTypes[0], keyIndices1[0], keyIndices2[0]); builder.name(this.toString()); PactBuilderUtil.addKeysExceptFirst(builder, keyTypes, keyIndices1, keyIndices2); return builder.build(); } else if (contractClass == MatchContract.class) { int[] keyIndices1 = this.getKeyIndices(globalSchema, this.getKeyExpressions(0)); int[] keyIndices2 = this.getKeyIndices(globalSchema, this.getKeyExpressions(1)); Class<? extends Key>[] keyTypes = this.getCommonKeyClasses(globalSchema, keyIndices1, keyIndices2); MatchContract.Builder builder = MatchContract.builder((Class<? extends MatchStub>) stubClass, keyTypes[0], keyIndices1[0], keyIndices2[0]); builder.name(this.toString()); PactBuilderUtil.addKeysExceptFirst(builder, keyTypes, keyIndices1, keyIndices2); return builder.build(); } else if(contractClass == MapContract.class) return MapContract.builder((Class<? extends MapStub>) stubClass). name(this.toString()).build(); else if(contractClass == CrossContract.class) return CrossContract.builder((Class<? extends CrossStub>) stubClass). name(this.toString()).build(); else throw new UnsupportedOperationException("Unknown contract type"); } catch (final Exception e) { throw new IllegalStateException("Cannot create contract from stub " + stubClass, e); } } ElementaryOperator();  ElementaryOperator(final int minInputs, final int maxInputs);  ElementaryOperator(final int inputs); EvaluationExpression getResultProjection(); @Property @Name(preposition = "into") void setResultProjection(final EvaluationExpression resultProjection); Self withResultProjection(final EvaluationExpression resultProjection); @SuppressWarnings("unchecked") List<? extends EvaluationExpression> getKeyExpressions(
			final int inputIndex); @Property(hidden = true) void setKeyExpressions(final int inputIndex,
			final List<? extends EvaluationExpression> keyExpressions); void setKeyExpressions(final int index,
			final EvaluationExpression... keyExpressions); Self withKeyExpression(final int index,
			final EvaluationExpression... keyExpressions); Self withKeyExpressions(final int index,
			final List<? extends EvaluationExpression> keyExpressions); @Override PactModule asPactModule(final EvaluationContext context); @Override ElementarySopremoModule asElementaryOperators(final EvaluationContext context); List<List<? extends EvaluationExpression>> getAllKeyExpressions(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override String toString();  }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test(expected = IllegalStateException.class) @PrepareForTest(ContractUtil.class) public void getContractShouldFailIfContractNotInstancable() { PowerMockito.mockStatic(ContractUtil.class); Mockito.when(ContractUtil.getContractClass(OperatorWithOneStub.Implementation.class)).thenReturn( (Class) UninstanceableContract.class); new OperatorWithOneStub().getContract(SCHEMA); }
@Test(expected = IllegalStateException.class) public void getContractShouldFailIfNoStub() { new OperatorWithNoStubs().getContract(SCHEMA); }
@Test(expected = IllegalStateException.class) public void getContractShouldFailIfOnlyInstanceStub() { new OperatorWithInstanceStub().getContract(SCHEMA); }
@Test(expected = IllegalStateException.class) public void getContractShouldFailIfOnlyUnknownStub() { new OperatorWithUnknownStub().getContract(SCHEMA); }
@SuppressWarnings("unchecked") @Test public void getContractShouldReturnTheMatchingContractToTheFirstStub() { final ObjectSchema schema = new ObjectSchema("someField"); final Contract contract = new OperatorWithTwoStubs().getContract(schema); assertEquals(ReduceContract.class, contract.getClass()); assertTrue(Arrays.asList(OperatorWithTwoStubs.Implementation1.class, OperatorWithTwoStubs.Implementation2.class).contains(contract.getUserCodeClass())); }
@Test public void getContractShouldReturnTheMatchingContractToTheOnlyStub() { final Contract contract = new OperatorWithOneStub().getContract(SCHEMA); assertEquals(MapContract.class, contract.getClass()); assertEquals(OperatorWithOneStub.Implementation.class, contract.getUserCodeClass()); }