Skip to content

Commit 5be34a9

Browse files
committed
Addressed codacy issues in DNS. This includes
- removing static formatter from example - removing and unifying imports and full qualification - removing unused serializable import from Dns - replacing assert not true with assertFalse in ITDnsTest - removing unused method from LocalDnsHelperTest.
1 parent 59cdf37 commit 5be34a9

File tree

9 files changed

+51
-64
lines changed

9 files changed

+51
-64
lines changed

gcloud-java-dns/src/main/java/com/google/gcloud/dns/ChangeRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static ChangeRequest fromPb(Dns dns, String zoneName, Change pb) {
189189
static Function<Change, ChangeRequest> fromPbFunction(final Dns dns, final String zoneName) {
190190
return new Function<Change, ChangeRequest>() {
191191
@Override
192-
public ChangeRequest apply(com.google.api.services.dns.model.Change pb) {
192+
public ChangeRequest apply(Change pb) {
193193
return ChangeRequest.fromPb(dns, zoneName, pb);
194194
}
195195
};

gcloud-java-dns/src/main/java/com/google/gcloud/dns/Dns.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.gcloud.Service;
2424
import com.google.gcloud.dns.spi.DnsRpc;
2525

26-
import java.io.Serializable;
2726
import java.util.List;
2827

2928
/**

gcloud-java-dns/src/main/java/com/google/gcloud/dns/DnsImpl.java

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.gcloud.dns;
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
20-
import static com.google.gcloud.RetryHelper.RetryHelperException;
2120
import static com.google.gcloud.RetryHelper.runWithRetries;
2221

2322
import com.google.api.services.dns.model.Change;
@@ -121,8 +120,7 @@ private static Page<Zone> listZones(final DnsOptions serviceOptions,
121120
// this differs from the other list operations since zone is functional and requires dns service
122121
Function<ManagedZone, Zone> pbToZoneFunction = new Function<ManagedZone, Zone>() {
123122
@Override
124-
public Zone apply(
125-
com.google.api.services.dns.model.ManagedZone zonePb) {
123+
public Zone apply(ManagedZone zonePb) {
126124
return Zone.fromPb(serviceOptions.service(), zonePb);
127125
}
128126
};
@@ -142,7 +140,7 @@ public DnsRpc.ListResult<ManagedZone> call() {
142140
? ImmutableList.<Zone>of() : Iterables.transform(result.results(), pbToZoneFunction);
143141
return new PageImpl<>(new ZonePageFetcher(serviceOptions, cursor, optionsMap),
144142
cursor, zones);
145-
} catch (RetryHelperException e) {
143+
} catch (RetryHelper.RetryHelperException e) {
146144
throw DnsException.translateAndThrow(e);
147145
}
148146
}
@@ -169,10 +167,10 @@ public DnsRpc.ListResult<Change> call() {
169167
Iterable<ChangeRequest> changes = result.results() == null
170168
? ImmutableList.<ChangeRequest>of()
171169
: Iterables.transform(result.results(),
172-
ChangeRequest.fromPbFunction(serviceOptions.service(), zoneName));
170+
ChangeRequest.fromPbFunction(serviceOptions.service(), zoneName));
173171
return new PageImpl<>(new ChangeRequestPageFetcher(zoneName, serviceOptions, cursor,
174172
optionsMap), cursor, changes);
175-
} catch (RetryHelperException e) {
173+
} catch (RetryHelper.RetryHelperException e) {
176174
throw DnsException.translateAndThrow(e);
177175
}
178176
}
@@ -201,7 +199,7 @@ public DnsRpc.ListResult<ResourceRecordSet> call() {
201199
: Iterables.transform(result.results(), RecordSet.FROM_PB_FUNCTION);
202200
return new PageImpl<>(new DnsRecordPageFetcher(zoneName, serviceOptions, cursor, optionsMap),
203201
cursor, recordSets);
204-
} catch (RetryHelperException e) {
202+
} catch (RetryHelper.RetryHelperException e) {
205203
throw DnsException.translateAndThrow(e);
206204
}
207205
}
@@ -210,10 +208,10 @@ public DnsRpc.ListResult<ResourceRecordSet> call() {
210208
public Zone create(final ZoneInfo zoneInfo, Dns.ZoneOption... options) {
211209
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
212210
try {
213-
com.google.api.services.dns.model.ManagedZone answer = runWithRetries(
214-
new Callable<com.google.api.services.dns.model.ManagedZone>() {
211+
ManagedZone answer = runWithRetries(
212+
new Callable<ManagedZone>() {
215213
@Override
216-
public com.google.api.services.dns.model.ManagedZone call() {
214+
public ManagedZone call() {
217215
return dnsRpc.create(zoneInfo.toPb(), optionsMap);
218216
}
219217
}, options().retryParams(), EXCEPTION_HANDLER);
@@ -227,10 +225,10 @@ public com.google.api.services.dns.model.ManagedZone call() {
227225
public Zone getZone(final String zoneName, Dns.ZoneOption... options) {
228226
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
229227
try {
230-
com.google.api.services.dns.model.ManagedZone answer = runWithRetries(
231-
new Callable<com.google.api.services.dns.model.ManagedZone>() {
228+
ManagedZone answer = runWithRetries(
229+
new Callable<ManagedZone>() {
232230
@Override
233-
public com.google.api.services.dns.model.ManagedZone call() {
231+
public ManagedZone call() {
234232
return dnsRpc.getZone(zoneName, optionsMap);
235233
}
236234
}, options().retryParams(), EXCEPTION_HANDLER);
@@ -276,14 +274,13 @@ public ChangeRequest applyChangeRequest(final String zoneName,
276274
final ChangeRequestInfo changeRequest, ChangeRequestOption... options) {
277275
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
278276
try {
279-
com.google.api.services.dns.model.Change answer =
280-
runWithRetries(
281-
new Callable<com.google.api.services.dns.model.Change>() {
282-
@Override
283-
public com.google.api.services.dns.model.Change call() {
284-
return dnsRpc.applyChangeRequest(zoneName, changeRequest.toPb(), optionsMap);
285-
}
286-
}, options().retryParams(), EXCEPTION_HANDLER);
277+
Change answer = runWithRetries(
278+
new Callable<Change>() {
279+
@Override
280+
public Change call() {
281+
return dnsRpc.applyChangeRequest(zoneName, changeRequest.toPb(), optionsMap);
282+
}
283+
}, options().retryParams(), EXCEPTION_HANDLER);
287284
return answer == null ? null : ChangeRequest.fromPb(this, zoneName, answer); // not null
288285
} catch (RetryHelper.RetryHelperException ex) {
289286
throw DnsException.translateAndThrow(ex);
@@ -295,14 +292,13 @@ public ChangeRequest getChangeRequest(final String zoneName, final String change
295292
Dns.ChangeRequestOption... options) {
296293
final Map<DnsRpc.Option, ?> optionsMap = optionMap(options);
297294
try {
298-
com.google.api.services.dns.model.Change answer =
299-
runWithRetries(
300-
new Callable<com.google.api.services.dns.model.Change>() {
301-
@Override
302-
public com.google.api.services.dns.model.Change call() {
303-
return dnsRpc.getChangeRequest(zoneName, changeRequestId, optionsMap);
304-
}
305-
}, options().retryParams(), EXCEPTION_HANDLER);
295+
Change answer = runWithRetries(
296+
new Callable<Change>() {
297+
@Override
298+
public Change call() {
299+
return dnsRpc.getChangeRequest(zoneName, changeRequestId, optionsMap);
300+
}
301+
}, options().retryParams(), EXCEPTION_HANDLER);
306302
return answer == null ? null : ChangeRequest.fromPb(this, zoneName, answer);
307303
} catch (RetryHelper.RetryHelperException ex) {
308304
throw DnsException.translateAndThrow(ex);

gcloud-java-dns/src/main/java/com/google/gcloud/dns/RecordSet.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,16 @@ public boolean equals(Object obj) {
285285
return obj instanceof RecordSet && Objects.equals(this.toPb(), ((RecordSet) obj).toPb());
286286
}
287287

288-
com.google.api.services.dns.model.ResourceRecordSet toPb() {
289-
com.google.api.services.dns.model.ResourceRecordSet pb =
290-
new com.google.api.services.dns.model.ResourceRecordSet();
288+
ResourceRecordSet toPb() {
289+
ResourceRecordSet pb = new ResourceRecordSet();
291290
pb.setName(this.name());
292291
pb.setRrdatas(this.records());
293292
pb.setTtl(this.ttl());
294293
pb.setType(this.type().name());
295294
return pb;
296295
}
297296

298-
static RecordSet fromPb(com.google.api.services.dns.model.ResourceRecordSet pb) {
297+
static RecordSet fromPb(ResourceRecordSet pb) {
299298
Builder builder = builder(pb.getName(), Type.valueOf(pb.getType()));
300299
if (pb.getRrdatas() != null) {
301300
builder.records(pb.getRrdatas());

gcloud-java-dns/src/main/java/com/google/gcloud/dns/Zone.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ public int hashCode() {
205205
return Objects.hash(super.hashCode(), options);
206206
}
207207

208-
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
209-
in.defaultReadObject();
208+
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
209+
stream.defaultReadObject();
210210
this.dns = options.service();
211211
}
212212

gcloud-java-dns/src/test/java/com/google/gcloud/dns/RecordSetTest.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.gcloud.dns;
1818

19-
import static com.google.gcloud.dns.RecordSet.builder;
2019
import static org.junit.Assert.assertEquals;
2120
import static org.junit.Assert.assertNotEquals;
2221
import static org.junit.Assert.assertTrue;
@@ -33,13 +32,13 @@ public class RecordSetTest {
3332
private static final TimeUnit UNIT = TimeUnit.HOURS;
3433
private static final Integer UNIT_TTL = 1;
3534
private static final RecordSet.Type TYPE = RecordSet.Type.AAAA;
36-
private static final RecordSet recordSet = builder(NAME, TYPE)
35+
private static final RecordSet recordSet = RecordSet.builder(NAME, TYPE)
3736
.ttl(UNIT_TTL, UNIT)
3837
.build();
3938

4039
@Test
4140
public void testDefaultDnsRecord() {
42-
RecordSet recordSet = builder(NAME, TYPE).build();
41+
RecordSet recordSet = RecordSet.builder(NAME, TYPE).build();
4342
assertEquals(0, recordSet.records().size());
4443
assertEquals(TYPE, recordSet.type());
4544
assertEquals(NAME, recordSet.name());
@@ -66,15 +65,15 @@ public void testBuilder() {
6665
@Test
6766
public void testValidTtl() {
6867
try {
69-
builder(NAME, TYPE).ttl(-1, TimeUnit.SECONDS);
68+
RecordSet.builder(NAME, TYPE).ttl(-1, TimeUnit.SECONDS);
7069
fail("A negative value is not acceptable for ttl.");
7170
} catch (IllegalArgumentException e) {
7271
// expected
7372
}
74-
builder(NAME, TYPE).ttl(0, TimeUnit.SECONDS);
75-
builder(NAME, TYPE).ttl(Integer.MAX_VALUE, TimeUnit.SECONDS);
73+
RecordSet.builder(NAME, TYPE).ttl(0, TimeUnit.SECONDS);
74+
RecordSet.builder(NAME, TYPE).ttl(Integer.MAX_VALUE, TimeUnit.SECONDS);
7675
try {
77-
builder(NAME, TYPE).ttl(Integer.MAX_VALUE, TimeUnit.HOURS);
76+
RecordSet.builder(NAME, TYPE).ttl(Integer.MAX_VALUE, TimeUnit.HOURS);
7877
fail("This value is too large for int.");
7978
} catch (IllegalArgumentException e) {
8079
// expected
@@ -108,22 +107,22 @@ public void testSameHashCodeOnEquals() {
108107
@Test
109108
public void testToAndFromPb() {
110109
assertEquals(recordSet, RecordSet.fromPb(recordSet.toPb()));
111-
RecordSet partial = builder(NAME, TYPE).build();
110+
RecordSet partial = RecordSet.builder(NAME, TYPE).build();
112111
assertEquals(partial, RecordSet.fromPb(partial.toPb()));
113-
partial = builder(NAME, TYPE).addRecord("test").build();
112+
partial = RecordSet.builder(NAME, TYPE).addRecord("test").build();
114113
assertEquals(partial, RecordSet.fromPb(partial.toPb()));
115-
partial = builder(NAME, TYPE).ttl(15, TimeUnit.SECONDS).build();
114+
partial = RecordSet.builder(NAME, TYPE).ttl(15, TimeUnit.SECONDS).build();
116115
assertEquals(partial, RecordSet.fromPb(partial.toPb()));
117116
}
118117

119118
@Test
120119
public void testToBuilder() {
121120
assertEquals(recordSet, recordSet.toBuilder().build());
122-
RecordSet partial = builder(NAME, TYPE).build();
121+
RecordSet partial = RecordSet.builder(NAME, TYPE).build();
123122
assertEquals(partial, partial.toBuilder().build());
124-
partial = builder(NAME, TYPE).addRecord("test").build();
123+
partial = RecordSet.builder(NAME, TYPE).addRecord("test").build();
125124
assertEquals(partial, partial.toBuilder().build());
126-
partial = builder(NAME, TYPE).ttl(15, TimeUnit.SECONDS).build();
125+
partial = RecordSet.builder(NAME, TYPE).ttl(15, TimeUnit.SECONDS).build();
127126
assertEquals(partial, partial.toBuilder().build());
128127
}
129128

gcloud-java-dns/src/test/java/com/google/gcloud/dns/it/ITDnsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public class ITDnsTest {
8787
.build();
8888
private static final List<String> ZONE_NAMES = ImmutableList.of(ZONE_NAME1,
8989
ZONE_NAME_EMPTY_DESCRIPTION);
90+
91+
@Rule
92+
public Timeout globalTimeout = Timeout.seconds(300);
9093

9194
private static void clear() {
9295
for (String zoneName : ZONE_NAMES) {
@@ -161,9 +164,6 @@ private static void waitForChangeToComplete(String zoneName, String changeId) {
161164
}
162165
}
163166

164-
@Rule
165-
public Timeout globalTimeout = Timeout.seconds(300);
166-
167167
@Test
168168
public void testCreateValidZone() {
169169
try {
@@ -471,7 +471,7 @@ public void testListZones() {
471471
assertNull(zone.dnsName());
472472
assertNull(zone.description());
473473
assertNull(zone.nameServerSet());
474-
assertTrue(!zone.nameServers().isEmpty());
474+
assertFalse(zone.nameServers().isEmpty());
475475
assertNull(zone.generatedId());
476476
assertFalse(zoneIterator.hasNext());
477477
zoneIterator = DNS.listZones(Dns.ZoneListOption.dnsName(ZONE1.dnsName()),

gcloud-java-dns/src/test/java/com/google/gcloud/dns/testing/LocalDnsHelperTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@ private static void resetProjects() {
119119
}
120120
}
121121

122-
private static void assertEqChangesIgnoreStatus(Change expected, Change actual) {
123-
assertEquals(expected.getAdditions(), actual.getAdditions());
124-
assertEquals(expected.getDeletions(), actual.getDeletions());
125-
assertEquals(expected.getId(), actual.getId());
126-
assertEquals(expected.getStartTime(), actual.getStartTime());
127-
}
128-
129122
@Test
130123
public void testCreateZone() {
131124
ManagedZone created = RPC.create(ZONE1, EMPTY_RPC_OPTIONS);

gcloud-java-examples/src/main/java/com/google/gcloud/examples/dns/DnsExample.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
public class DnsExample {
6868

6969
private static final Map<String, DnsAction> ACTIONS = new HashMap<>();
70-
private static final DateFormat FORMATTER = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
7170

7271
private interface DnsAction {
7372
void run(Dns dns, String... args);
@@ -332,11 +331,12 @@ public void run(Dns dns, String... args) {
332331
}
333332
if (iterator.hasNext()) {
334333
System.out.printf("Change requests for zone %s:%n", zoneName);
334+
DateFormat formatter = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
335335
while (iterator.hasNext()) {
336336
ChangeRequest change = iterator.next();
337337
System.out.printf("%nID: %s%n", change.generatedId());
338338
System.out.printf("Status: %s%n", change.status());
339-
System.out.printf("Started: %s%n", FORMATTER.format(change.startTimeMillis()));
339+
System.out.printf("Started: %s%n", formatter.format(change.startTimeMillis()));
340340
System.out.printf("Deletions: %s%n", Joiner.on(", ").join(change.deletions()));
341341
System.out.printf("Additions: %s%n", Joiner.on(", ").join(change.additions()));
342342
}
@@ -441,7 +441,8 @@ private static void printZone(Zone zone) {
441441
System.out.printf("%nName: %s%n", zone.name());
442442
System.out.printf("ID: %s%n", zone.generatedId());
443443
System.out.printf("Description: %s%n", zone.description());
444-
System.out.printf("Created: %s%n", FORMATTER.format(new Date(zone.creationTimeMillis())));
444+
DateFormat formatter = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
445+
System.out.printf("Created: %s%n", formatter.format(new Date(zone.creationTimeMillis())));
445446
System.out.printf("Name servers: %s%n", Joiner.on(", ").join(zone.nameServers()));
446447
}
447448

0 commit comments

Comments
 (0)