@Before public void setUp() { valueSet = SampleValueSet.newBuilder().setId("test-sample-value-set-id").build(); parent = new OutputTransformer.ScopeTable(); child = new OutputTransformer.ScopeTable(parent); MockitoAnnotations.initMocks(this); when(context.getFeatureConfig()).thenReturn(featureConfig); when(context.getMethodConfig()).thenReturn(config); when(context.getMethodModel()).thenReturn(model); when(context.getNamer()).thenReturn(namer); when(context.getTypeTable()).thenReturn(typeTable); when(model.getSimpleName()).thenReturn("methodSimpleName"); when(namer.getSampleResponseVarName(context)).thenReturn("sampleResponseVarName"); }
SampleValueSet valueSet = SampleValueSet.newBuilder() .setParameters( SampleParameters.newBuilder() .addAllDefaults(methodConfig.getSampleCodeInitFields()) .build()) .setId(id) .setDescription("value set imported from sample_code_init_fields") .setTitle("Sample Values") .build(); matchingValueSets = ImmutableList.of(ValueSetAndTags.newBuilder().values(valueSet).regionTag("").build());
SampleValueSet valueSetAlice = SampleValueSet.newBuilder() .setId("alice") .setParameters(SampleParameters.newBuilder().addDefaults("apple").build()) .build(); SampleValueSet valueSetBob = SampleValueSet.newBuilder() .setId("bob") .setParameters(SampleParameters.newBuilder().addDefaults("banana").build()) .build(); SampleValueSet valueSetAlison = SampleValueSet.newBuilder() .setId("alison") .setParameters(SampleParameters.newBuilder().addDefaults("apricot").build()) .build();
@Test public void valueSetsReferencedMultipleTimes() { final MethodConfigProto methodConfigProto = MethodConfigProto.newBuilder() .addSampleValueSets(SampleValueSet.newBuilder().setId("alice")) .addSampleValueSets(SampleValueSet.newBuilder().setId("bob")) .setSamples( SampleConfiguration.newBuilder() .addStandalone( SampleTypeConfiguration.newBuilder() .addValueSets("alice") .addCallingForms(".*")) .addStandalone( SampleTypeConfiguration.newBuilder() .addValueSets("bob") .addCallingForms(".*")) .addStandalone( SampleTypeConfiguration.newBuilder() .addValueSets("alice") .addCallingForms(".*"))) .build(); SampleSpec sampleSpec = new SampleSpec(methodConfigProto); assertThat(sampleSpec.getMatchingValueSets(CallingForm.Request, SampleType.STANDALONE)) .hasSize(3); } }
@Test(expected = IllegalArgumentException.class) public void storingDuplicateValueSets() { final MethodConfigProto methodConfigProto = MethodConfigProto.newBuilder() .addSampleValueSets(SampleValueSet.newBuilder().setId("alice")) .addSampleValueSets(SampleValueSet.newBuilder().setId("bob")) .addSampleValueSets(SampleValueSet.newBuilder().setId("alice")) .setSamples( SampleConfiguration.newBuilder() .addStandalone( SampleTypeConfiguration.newBuilder() .addValueSets("alice") .addCallingForms(".*")) .addStandalone( SampleTypeConfiguration.newBuilder() .addValueSets("bob") .addCallingForms(".*"))) .build(); SampleSpec sampleSpec = new SampleSpec(methodConfigProto); }