builder.addField(fieldName, fieldType); } catch (Exception e) { throw new IllegalArgumentException(
@Test public void testBuilderGetters() { Partitioning partitioning = Partitioning.builder() .addField("a", FieldType.STRING) .addField("b", FieldType.INT) .addField("c", FieldType.LONG) .addStringField("d") .addIntField("e") .addLongField("f") .build(); Assert.assertEquals(FieldType.STRING, partitioning.getFieldType("a")); Assert.assertEquals(FieldType.INT, partitioning.getFieldType("b")); Assert.assertEquals(FieldType.LONG, partitioning.getFieldType("c")); Assert.assertEquals(FieldType.STRING, partitioning.getFieldType("d")); Assert.assertEquals(FieldType.INT, partitioning.getFieldType("e")); Assert.assertEquals(FieldType.LONG, partitioning.getFieldType("f")); Assert.assertNull(partitioning.getFieldType("x")); Assert.assertEquals(partitioning.getFields().keySet(), ImmutableSet.of("a", "b", "c", "d", "e", "f")); }
/** * Add field of type LONG. * * @param name the field name * * @throws java.lang.IllegalArgumentException if the field name is null, empty, or already exists. */ public Builder addLongField(String name) { return addField(name, FieldType.LONG); }
@Test(expected = IllegalArgumentException.class) public void testBuilderDuplicate() { Partitioning.builder() .addField("name", FieldType.STRING) .addIntField("age") .addStringField("name") .build(); }
/** * Add field of type STRING. * * @param name the field name * * @throws java.lang.IllegalArgumentException if the field name is null, empty, or already exists. */ public Builder addStringField(String name) { return addField(name, FieldType.STRING); }
@Test(expected = IllegalArgumentException.class) public void testBuilderNullName() { //noinspection ConstantConditions Partitioning.builder().addField(null, FieldType.STRING).build(); }
/** * Add field of type INT. * * @param name the field name * * @throws java.lang.IllegalArgumentException if the field name is null, empty, or already exists. */ public Builder addIntField(String name) { return addField(name, FieldType.INT); }
@Test(expected = IllegalArgumentException.class) public void testBuilderNullType() { //noinspection ConstantConditions Partitioning.builder().addField("x", null).build(); }