mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 08:57:12 +02:00
Perform some minor test cleanup
This standardizes use of annotations/inheritance/formatting across tests, to make the code more legible and consistent. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=161810734
This commit is contained in:
parent
ea4572b4b5
commit
2521409e39
5 changed files with 54 additions and 59 deletions
|
@ -198,7 +198,6 @@ public class BigqueryPollJobActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void testJobStatusUnreadable() throws Exception {
|
public void testJobStatusUnreadable() throws Exception {
|
||||||
when(bigqueryJobsGet.execute()).thenThrow(IOException.class);
|
when(bigqueryJobsGet.execute()).thenThrow(IOException.class);
|
||||||
thrown.expect(NotModifiedException.class);
|
thrown.expect(NotModifiedException.class);
|
||||||
|
|
|
@ -419,13 +419,6 @@ public class DomainAllocateFlowTest
|
||||||
doSuccessfulTest(13);
|
doSuccessfulTest(13);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Override
|
|
||||||
public void testRequiresLogin() throws Exception {
|
|
||||||
createTld("tld");
|
|
||||||
super.testRequiresLogin();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_secDns() throws Exception {
|
public void testSuccess_secDns() throws Exception {
|
||||||
setupDomainApplication("tld", TldState.QUIET_PERIOD);
|
setupDomainApplication("tld", TldState.QUIET_PERIOD);
|
||||||
|
|
|
@ -29,7 +29,6 @@ public class TmchCrlTest {
|
||||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("null")
|
|
||||||
public void testSuccess() throws Exception {
|
public void testSuccess() throws Exception {
|
||||||
assertThat(TmchCrl.get()).isNull();
|
assertThat(TmchCrl.get()).isNull();
|
||||||
TmchCrl.set("lolcat", "http://lol.cat");
|
TmchCrl.set("lolcat", "http://lol.cat");
|
||||||
|
|
|
@ -297,7 +297,6 @@ public class RdeImportUtilsTest extends ShardableTestCase {
|
||||||
|
|
||||||
/** Verifies that no errors are thrown when a valid escrow file is validated */
|
/** Verifies that no errors are thrown when a valid escrow file is validated */
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("CheckReturnValue")
|
|
||||||
public void testValidateEscrowFile_valid() throws Exception {
|
public void testValidateEscrowFile_valid() throws Exception {
|
||||||
xmlInput = DEPOSIT_XML.openBufferedStream();
|
xmlInput = DEPOSIT_XML.openBufferedStream();
|
||||||
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
|
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
|
||||||
|
|
|
@ -31,11 +31,11 @@ import org.junit.runners.JUnit4;
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class ComparingInvocationHandlerTest {
|
public class ComparingInvocationHandlerTest {
|
||||||
|
|
||||||
static class Dummy {
|
static class Dummy {}
|
||||||
}
|
|
||||||
|
|
||||||
static interface MyInterface {
|
static interface MyInterface {
|
||||||
String func(int a, String b);
|
String func(int a, String b);
|
||||||
|
|
||||||
Dummy func();
|
Dummy func();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,13 +52,13 @@ public class ComparingInvocationHandlerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
static final ArrayList<String> log = new ArrayList<>();
|
static final ArrayList<String> log = new ArrayList<>();
|
||||||
|
|
||||||
static final class MyInterfaceComparingInvocationHandler
|
static final class MyInterfaceComparingInvocationHandler
|
||||||
extends ComparingInvocationHandler<MyInterface> {
|
extends ComparingInvocationHandler<MyInterface> {
|
||||||
|
|
||||||
private boolean dummyEqualsResult = true;
|
private boolean dummyEqualsResult = true;
|
||||||
private boolean exceptionEqualsResult = true;
|
private boolean exceptionEqualsResult = true;
|
||||||
|
|
||||||
|
|
||||||
MyInterfaceComparingInvocationHandler(MyInterface actual, MyInterface second) {
|
MyInterfaceComparingInvocationHandler(MyInterface actual, MyInterface second) {
|
||||||
super(MyInterface.class, actual, second);
|
super(MyInterface.class, actual, second);
|
||||||
}
|
}
|
||||||
|
@ -73,30 +73,34 @@ public class ComparingInvocationHandlerTest {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void log(Method method, String message) {
|
@Override
|
||||||
|
protected void log(Method method, String message) {
|
||||||
log.add(String.format("%s: %s", method.getName(), message));
|
log.add(String.format("%s: %s", method.getName(), message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected boolean compareResults(
|
@Override
|
||||||
Method method, @Nullable Object a, @Nullable Object b) {
|
protected boolean compareResults(Method method, @Nullable Object a, @Nullable Object b) {
|
||||||
if (method.getReturnType().equals(Dummy.class)) {
|
if (method.getReturnType().equals(Dummy.class)) {
|
||||||
return dummyEqualsResult;
|
return dummyEqualsResult;
|
||||||
}
|
}
|
||||||
return super.compareResults(method, a, b);
|
return super.compareResults(method, a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected String stringifyResult(Method method, @Nullable Object a) {
|
@Override
|
||||||
|
protected String stringifyResult(Method method, @Nullable Object a) {
|
||||||
if (method.getReturnType().equals(Dummy.class)) {
|
if (method.getReturnType().equals(Dummy.class)) {
|
||||||
return "dummy";
|
return "dummy";
|
||||||
}
|
}
|
||||||
return super.stringifyResult(method, a);
|
return super.stringifyResult(method, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected boolean compareThrown(Method method, Throwable a, Throwable b) {
|
@Override
|
||||||
|
protected boolean compareThrown(Method method, Throwable a, Throwable b) {
|
||||||
return exceptionEqualsResult && super.compareThrown(method, a, b);
|
return exceptionEqualsResult && super.compareThrown(method, a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected String stringifyThrown(Method method, Throwable a) {
|
@Override
|
||||||
|
protected String stringifyThrown(Method method, Throwable a) {
|
||||||
return String.format("testException(%s)", super.stringifyThrown(method, a));
|
return String.format("testException(%s)", super.stringifyThrown(method, a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,12 +112,14 @@ public class ComparingInvocationHandlerTest {
|
||||||
private final MyInterface mySecondMock = mock(MyInterface.class);
|
private final MyInterface mySecondMock = mock(MyInterface.class);
|
||||||
private MyInterfaceComparingInvocationHandler invocationHandler;
|
private MyInterfaceComparingInvocationHandler invocationHandler;
|
||||||
|
|
||||||
@Before public void setUp() {
|
@Before
|
||||||
|
public void setUp() {
|
||||||
log.clear();
|
log.clear();
|
||||||
invocationHandler = new MyInterfaceComparingInvocationHandler(myActualMock, mySecondMock);
|
invocationHandler = new MyInterfaceComparingInvocationHandler(myActualMock, mySecondMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void test_actualThrows_logDifference() {
|
@Test
|
||||||
|
public void test_actualThrows_logDifference() {
|
||||||
MyInterface comparator = invocationHandler.makeProxy();
|
MyInterface comparator = invocationHandler.makeProxy();
|
||||||
MyException myException = new MyException("message");
|
MyException myException = new MyException("message");
|
||||||
when(myActualMock.func(3, "str")).thenThrow(myException);
|
when(myActualMock.func(3, "str")).thenThrow(myException);
|
||||||
|
@ -125,12 +131,15 @@ public class ComparingInvocationHandlerTest {
|
||||||
} catch (MyException expected) {
|
} catch (MyException expected) {
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(log).containsExactly(String.format(
|
assertThat(log)
|
||||||
"func: Only actual implementation threw exception: testException(%s)",
|
.containsExactly(
|
||||||
myException.toString()));
|
String.format(
|
||||||
|
"func: Only actual implementation threw exception: testException(%s)",
|
||||||
|
myException.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void test_secondThrows_logDifference() {
|
@Test
|
||||||
|
public void test_secondThrows_logDifference() {
|
||||||
MyInterface comparator = invocationHandler.makeProxy();
|
MyInterface comparator = invocationHandler.makeProxy();
|
||||||
MyOtherException myOtherException = new MyOtherException("message");
|
MyOtherException myOtherException = new MyOtherException("message");
|
||||||
when(myActualMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
|
when(myActualMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
|
||||||
|
@ -138,15 +147,16 @@ public class ComparingInvocationHandlerTest {
|
||||||
|
|
||||||
assertThat(comparator.func(3, "str")).isEqualTo(ACTUAL_RESULT);
|
assertThat(comparator.func(3, "str")).isEqualTo(ACTUAL_RESULT);
|
||||||
|
|
||||||
assertThat(log).containsExactly(String.format(
|
assertThat(log)
|
||||||
"func: Only second implementation threw exception: testException(%s)",
|
.containsExactly(
|
||||||
myOtherException.toString()));
|
String.format(
|
||||||
|
"func: Only second implementation threw exception: testException(%s)",
|
||||||
|
myOtherException.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void test_bothThrowEqual_noLog() {
|
@Test
|
||||||
MyInterface comparator = invocationHandler
|
public void test_bothThrowEqual_noLog() {
|
||||||
.setExeptionsEquals(true)
|
MyInterface comparator = invocationHandler.setExeptionsEquals(true).makeProxy();
|
||||||
.makeProxy();
|
|
||||||
MyException myException = new MyException("actual message");
|
MyException myException = new MyException("actual message");
|
||||||
MyOtherException myOtherException = new MyOtherException("second message");
|
MyOtherException myOtherException = new MyOtherException("second message");
|
||||||
when(myActualMock.func(3, "str")).thenThrow(myException);
|
when(myActualMock.func(3, "str")).thenThrow(myException);
|
||||||
|
@ -161,10 +171,9 @@ public class ComparingInvocationHandlerTest {
|
||||||
assertThat(log).isEmpty();
|
assertThat(log).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void test_bothThrowDifferent_logDifference() {
|
@Test
|
||||||
MyInterface comparator = invocationHandler
|
public void test_bothThrowDifferent_logDifference() {
|
||||||
.setExeptionsEquals(false)
|
MyInterface comparator = invocationHandler.setExeptionsEquals(false).makeProxy();
|
||||||
.makeProxy();
|
|
||||||
MyException myException = new MyException("actual message");
|
MyException myException = new MyException("actual message");
|
||||||
MyOtherException myOtherException = new MyOtherException("second message");
|
MyOtherException myOtherException = new MyOtherException("second message");
|
||||||
when(myActualMock.func(3, "str")).thenThrow(myException);
|
when(myActualMock.func(3, "str")).thenThrow(myException);
|
||||||
|
@ -176,14 +185,16 @@ public class ComparingInvocationHandlerTest {
|
||||||
} catch (MyException expected) {
|
} catch (MyException expected) {
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(log).containsExactly(String.format(
|
assertThat(log)
|
||||||
"func: Both implementations threw, but got different exceptions! "
|
.containsExactly(
|
||||||
+ "'testException(%s)' vs 'testException(%s)'",
|
String.format(
|
||||||
myException.toString(),
|
"func: Both implementations threw, but got different exceptions! "
|
||||||
myOtherException.toString()));
|
+ "'testException(%s)' vs 'testException(%s)'",
|
||||||
|
myException.toString(), myOtherException.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void test_bothReturnSame_noLog() {
|
@Test
|
||||||
|
public void test_bothReturnSame_noLog() {
|
||||||
MyInterface comparator = invocationHandler.makeProxy();
|
MyInterface comparator = invocationHandler.makeProxy();
|
||||||
when(myActualMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
|
when(myActualMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
|
||||||
when(mySecondMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
|
when(mySecondMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
|
||||||
|
@ -193,23 +204,21 @@ public class ComparingInvocationHandlerTest {
|
||||||
assertThat(log).isEmpty();
|
assertThat(log).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void test_bothReturnDifferent_logDifference() {
|
@Test
|
||||||
|
public void test_bothReturnDifferent_logDifference() {
|
||||||
MyInterface comparator = invocationHandler.makeProxy();
|
MyInterface comparator = invocationHandler.makeProxy();
|
||||||
when(myActualMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
|
when(myActualMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
|
||||||
when(mySecondMock.func(3, "str")).thenReturn(SECOND_RESULT);
|
when(mySecondMock.func(3, "str")).thenReturn(SECOND_RESULT);
|
||||||
|
|
||||||
assertThat(comparator.func(3, "str")).isEqualTo(ACTUAL_RESULT);
|
assertThat(comparator.func(3, "str")).isEqualTo(ACTUAL_RESULT);
|
||||||
|
|
||||||
assertThat(log).containsExactly(
|
assertThat(log)
|
||||||
"func: Got different results! "
|
.containsExactly("func: Got different results! 'actual result' vs 'second result'");
|
||||||
+ "'actual result' vs "
|
|
||||||
+ "'second result'");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void test_usesOverriddenMethods_noDifference() {
|
@Test
|
||||||
MyInterface comparator = invocationHandler
|
public void test_usesOverriddenMethods_noDifference() {
|
||||||
.setDummyEquals(true)
|
MyInterface comparator = invocationHandler.setDummyEquals(true).makeProxy();
|
||||||
.makeProxy();
|
|
||||||
when(myActualMock.func()).thenReturn(new Dummy());
|
when(myActualMock.func()).thenReturn(new Dummy());
|
||||||
when(mySecondMock.func()).thenReturn(new Dummy());
|
when(mySecondMock.func()).thenReturn(new Dummy());
|
||||||
|
|
||||||
|
@ -218,18 +227,14 @@ public class ComparingInvocationHandlerTest {
|
||||||
assertThat(log).isEmpty();
|
assertThat(log).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void test_usesOverriddenMethods_logDifference() {
|
@Test
|
||||||
MyInterface comparator = invocationHandler
|
public void test_usesOverriddenMethods_logDifference() {
|
||||||
.setDummyEquals(false)
|
MyInterface comparator = invocationHandler.setDummyEquals(false).makeProxy();
|
||||||
.makeProxy();
|
|
||||||
when(myActualMock.func()).thenReturn(new Dummy());
|
when(myActualMock.func()).thenReturn(new Dummy());
|
||||||
when(mySecondMock.func()).thenReturn(new Dummy());
|
when(mySecondMock.func()).thenReturn(new Dummy());
|
||||||
|
|
||||||
comparator.func();
|
comparator.func();
|
||||||
|
|
||||||
assertThat(log).containsExactly(
|
assertThat(log).containsExactly("func: Got different results! 'dummy' vs 'dummy'");
|
||||||
"func: Got different results! "
|
|
||||||
+ "'dummy' vs "
|
|
||||||
+ "'dummy'");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue