netty5/codec-dns/src/test/java/io/netty/handler/codec/dns/DnsRecordTypeTest.java
田欧 9d62deeb6f Java 8 migration: Use diamond operator (#8749)
Motivation:

We can use the diamond operator these days.

Modification:

Use diamond operator whenever possible.

Result:

More modern code and less boiler-plate.
2019-01-22 16:07:26 +01:00

84 lines
2.5 KiB
Java

/*
* Copyright 2014 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.handler.codec.dns;
import org.junit.Test;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import static org.junit.Assert.*;
public class DnsRecordTypeTest {
private static List<DnsRecordType> allTypes() throws Exception {
List<DnsRecordType> result = new ArrayList<>();
for (Field field : DnsRecordType.class.getFields()) {
if ((field.getModifiers() & Modifier.STATIC) != 0 && field.getType() == DnsRecordType.class) {
result.add((DnsRecordType) field.get(null));
}
}
assertFalse(result.isEmpty());
return result;
}
@Test
public void testSanity() throws Exception {
assertEquals("More than one type has the same int value",
allTypes().size(), new HashSet<>(allTypes()).size());
}
/**
* Test of hashCode method, of class DnsRecordType.
*/
@Test
public void testHashCode() throws Exception {
for (DnsRecordType t : allTypes()) {
assertEquals(t.intValue(), t.hashCode());
}
}
/**
* Test of equals method, of class DnsRecordType.
*/
@Test
public void testEquals() throws Exception {
for (DnsRecordType t1 : allTypes()) {
for (DnsRecordType t2 : allTypes()) {
if (t1 != t2) {
assertNotEquals(t1, t2);
}
}
}
}
/**
* Test of find method, of class DnsRecordType.
*/
@Test
public void testFind() throws Exception {
for (DnsRecordType t : allTypes()) {
DnsRecordType found = DnsRecordType.valueOf(t.intValue());
assertSame(t, found);
found = DnsRecordType.valueOf(t.name());
assertSame(t.name(), t, found);
}
}
}