Skip to content

Commit

Permalink
Switched ZoneInfo.builder(). to ZoneInfo.of(). Fixes googleapis#698.
Browse files Browse the repository at this point in the history
  • Loading branch information
mderka committed Mar 1, 2016
1 parent fa081ac commit 4583a06
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ public ZoneInfo build() {
}

/**
* Returns a builder for {@code ZoneInfo} with an assigned {@code name}.
* Returns a ZoneInfo object with assigned {@code name}, {@code dnsName} and {@code description}.
*/
public static Builder builder(String name) {
return new BuilderImpl(name);
public static ZoneInfo of(String name, String dnsName, String description) {
return new BuilderImpl(name).dnsName(dnsName).description(description).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ public class DnsImplTest {
// Dns entities
private static final String ZONE_NAME = "some zone name";
private static final String DNS_NAME = "example.com.";
private static final String DESCRIPTION = "desc";
private static final String CHANGE_ID = "some change id";
private static final DnsRecord DNS_RECORD1 = DnsRecord.builder("Something", DnsRecord.Type.AAAA)
.build();
private static final DnsRecord DNS_RECORD2 = DnsRecord.builder("Different", DnsRecord.Type.AAAA)
.build();
private static final Integer MAX_SIZE = 20;
private static final String PAGE_TOKEN = "some token";
private static final ZoneInfo ZONE_INFO = ZoneInfo.builder(ZONE_NAME).build();
private static final ZoneInfo ZONE_INFO = ZoneInfo.of(ZONE_NAME, DNS_NAME, DESCRIPTION);
private static final ProjectInfo PROJECT_INFO = ProjectInfo.builder().build();
private static final ChangeRequest CHANGE_REQUEST_PARTIAL = ChangeRequest.builder()
.add(DNS_RECORD1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@

public class SerializationTest {

private static final ZoneInfo FULL_ZONE_INFO = Zone.builder("some zone name")
private static final ZoneInfo FULL_ZONE_INFO = Zone.of("some zone name", "www.example.com",
"some descriptions").toBuilder()
.creationTimeMillis(132L)
.description("some descriptions")
.dnsName("www.example.com")
.id("123333")
.nameServers(ImmutableList.of("server 1", "server 2"))
.nameServerSet("specificationstring")
.build();
private static final ZoneInfo PARTIAL_ZONE_INFO = Zone.builder("some zone name")
.build();
private static final ZoneInfo PARTIAL_ZONE_INFO = Zone.of("some zone name", "www.example.com",
"some descriptions").toBuilder().build();
private static final ProjectInfo PARTIAL_PROJECT_INFO = ProjectInfo.builder().id("13").build();
private static final ProjectInfo FULL_PROJECT_INFO = ProjectInfo.builder()
.id("342")
Expand Down Expand Up @@ -87,7 +86,6 @@ public class SerializationTest {
.startTimeMillis(132L)
.build();


@Test
public void testModelAndRequests() throws Exception {
Serializable[] objects = {FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,23 @@ public class ZoneInfoTest {
private static final String NS2 = "name server 2";
private static final String NS3 = "name server 3";
private static final List<String> NAME_SERVERS = ImmutableList.of(NS1, NS2, NS3);
private static final ZoneInfo INFO = ZoneInfo.builder(NAME)
private static final ZoneInfo INFO = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder()
.creationTimeMillis(CREATION_TIME_MILLIS)
.id(ID)
.dnsName(DNS_NAME)
.description(DESCRIPTION)
.nameServerSet(NAME_SERVER_SET)
.nameServers(NAME_SERVERS)
.build();

@Test
public void testDefaultBuilders() {
ZoneInfo zone = ZoneInfo.builder(NAME).build();
ZoneInfo zone = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION);
assertTrue(zone.nameServers().isEmpty());
assertEquals(NAME, zone.name());
assertNull(zone.id());
assertNull(zone.creationTimeMillis());
assertNull(zone.nameServerSet());
assertNull(zone.description());
assertNull(zone.dnsName());
assertEquals(DESCRIPTION, zone.description());
assertEquals(DNS_NAME, zone.dnsName());
}

@Test
Expand Down Expand Up @@ -109,42 +107,38 @@ public void testSameHashCodeOnEquals() {
@Test
public void testToBuilder() {
assertEquals(INFO, INFO.toBuilder().build());
ZoneInfo partial = ZoneInfo.builder(NAME).build();
ZoneInfo partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION);
assertEquals(partial, partial.toBuilder().build());
partial = ZoneInfo.builder(NAME).id(ID).build();
partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().id(ID).build();
assertEquals(partial, partial.toBuilder().build());
partial = ZoneInfo.builder(NAME).description(DESCRIPTION).build();
assertEquals(partial, partial.toBuilder().build());
partial = ZoneInfo.builder(NAME).dnsName(DNS_NAME).build();
assertEquals(partial, partial.toBuilder().build());
partial = ZoneInfo.builder(NAME).creationTimeMillis(CREATION_TIME_MILLIS).build();
partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder()
.creationTimeMillis(CREATION_TIME_MILLIS).build();
assertEquals(partial, partial.toBuilder().build());
List<String> nameServers = new LinkedList<>();
nameServers.add(NS1);
partial = ZoneInfo.builder(NAME).nameServers(nameServers).build();
partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().nameServers(nameServers).build();
assertEquals(partial, partial.toBuilder().build());
partial = ZoneInfo.builder(NAME).nameServerSet(NAME_SERVER_SET).build();
partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().nameServerSet(NAME_SERVER_SET)
.build();
assertEquals(partial, partial.toBuilder().build());
}

@Test
public void testToAndFromPb() {
assertEquals(INFO, ZoneInfo.fromPb(INFO.toPb()));
ZoneInfo partial = ZoneInfo.builder(NAME).build();
assertEquals(partial, ZoneInfo.fromPb(partial.toPb()));
partial = ZoneInfo.builder(NAME).id(ID).build();
assertEquals(partial, ZoneInfo.fromPb(partial.toPb()));
partial = ZoneInfo.builder(NAME).description(DESCRIPTION).build();
ZoneInfo partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION);
assertEquals(partial, ZoneInfo.fromPb(partial.toPb()));
partial = ZoneInfo.builder(NAME).dnsName(DNS_NAME).build();
partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().id(ID).build();
assertEquals(partial, ZoneInfo.fromPb(partial.toPb()));
partial = ZoneInfo.builder(NAME).creationTimeMillis(CREATION_TIME_MILLIS).build();
partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder()
.creationTimeMillis(CREATION_TIME_MILLIS).build();
assertEquals(partial, ZoneInfo.fromPb(partial.toPb()));
List<String> nameServers = new LinkedList<>();
nameServers.add(NS1);
partial = ZoneInfo.builder(NAME).nameServers(nameServers).build();
partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().nameServers(nameServers).build();
assertEquals(partial, ZoneInfo.fromPb(partial.toPb()));
partial = ZoneInfo.builder(NAME).nameServerSet(NAME_SERVER_SET).build();
partial = ZoneInfo.of(NAME, DNS_NAME, DESCRIPTION).toBuilder().nameServerSet(NAME_SERVER_SET)
.build();
assertEquals(partial, ZoneInfo.fromPb(partial.toPb()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public class ZoneTest {

private static final String ZONE_NAME = "dns-zone-name";
private static final String ZONE_ID = "123";
private static final ZoneInfo ZONE_INFO = Zone.builder(ZONE_NAME)
private static final ZoneInfo ZONE_INFO = Zone.of(ZONE_NAME, "example.com", "description")
.toBuilder()
.id(ZONE_ID)
.dnsName("example.com")
.creationTimeMillis(123478946464L)
.build();
private static final ZoneInfo NO_ID_INFO = ZoneInfo.builder(ZONE_NAME)
.dnsName("another-example.com")
private static final ZoneInfo NO_ID_INFO =
ZoneInfo.of(ZONE_NAME, "another-example.com", "description").toBuilder()
.creationTimeMillis(893123464L)
.build();
private static final Dns.ZoneOption ZONE_FIELD_OPTIONS =
Expand All @@ -71,7 +71,6 @@ public class ZoneTest {
private Zone zone;
private Zone zoneNoId;


@Before
public void setUp() throws Exception {
dns = createStrictMock(Dns.class);
Expand Down

0 comments on commit 4583a06

Please sign in to comment.