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:
mcilwain 2017-07-13 08:30:40 -07:00 committed by Ben McIlwain
parent ea4572b4b5
commit 2521409e39
5 changed files with 54 additions and 59 deletions

View file

@ -198,7 +198,6 @@ public class BigqueryPollJobActionTest {
}
@Test
@SuppressWarnings("unchecked")
public void testJobStatusUnreadable() throws Exception {
when(bigqueryJobsGet.execute()).thenThrow(IOException.class);
thrown.expect(NotModifiedException.class);

View file

@ -419,13 +419,6 @@ public class DomainAllocateFlowTest
doSuccessfulTest(13);
}
@Test
@Override
public void testRequiresLogin() throws Exception {
createTld("tld");
super.testRequiresLogin();
}
@Test
public void testSuccess_secDns() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);

View file

@ -29,7 +29,6 @@ public class TmchCrlTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Test
@SuppressWarnings("null")
public void testSuccess() throws Exception {
assertThat(TmchCrl.get()).isNull();
TmchCrl.set("lolcat", "http://lol.cat");

View file

@ -297,7 +297,6 @@ public class RdeImportUtilsTest extends ShardableTestCase {
/** Verifies that no errors are thrown when a valid escrow file is validated */
@Test
@SuppressWarnings("CheckReturnValue")
public void testValidateEscrowFile_valid() throws Exception {
xmlInput = DEPOSIT_XML.openBufferedStream();
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);

View file

@ -31,11 +31,11 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ComparingInvocationHandlerTest {
static class Dummy {
}
static class Dummy {}
static interface MyInterface {
String func(int a, String b);
Dummy func();
}
@ -52,13 +52,13 @@ public class ComparingInvocationHandlerTest {
}
static final ArrayList<String> log = new ArrayList<>();
static final class MyInterfaceComparingInvocationHandler
extends ComparingInvocationHandler<MyInterface> {
private boolean dummyEqualsResult = true;
private boolean exceptionEqualsResult = true;
MyInterfaceComparingInvocationHandler(MyInterface actual, MyInterface second) {
super(MyInterface.class, actual, second);
}
@ -73,30 +73,34 @@ public class ComparingInvocationHandlerTest {
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));
}
@Override protected boolean compareResults(
Method method, @Nullable Object a, @Nullable Object b) {
@Override
protected boolean compareResults(Method method, @Nullable Object a, @Nullable Object b) {
if (method.getReturnType().equals(Dummy.class)) {
return dummyEqualsResult;
}
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)) {
return "dummy";
}
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);
}
@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));
}
}
@ -108,12 +112,14 @@ public class ComparingInvocationHandlerTest {
private final MyInterface mySecondMock = mock(MyInterface.class);
private MyInterfaceComparingInvocationHandler invocationHandler;
@Before public void setUp() {
@Before
public void setUp() {
log.clear();
invocationHandler = new MyInterfaceComparingInvocationHandler(myActualMock, mySecondMock);
}
@Test public void test_actualThrows_logDifference() {
@Test
public void test_actualThrows_logDifference() {
MyInterface comparator = invocationHandler.makeProxy();
MyException myException = new MyException("message");
when(myActualMock.func(3, "str")).thenThrow(myException);
@ -125,12 +131,15 @@ public class ComparingInvocationHandlerTest {
} catch (MyException expected) {
}
assertThat(log).containsExactly(String.format(
"func: Only actual implementation threw exception: testException(%s)",
myException.toString()));
assertThat(log)
.containsExactly(
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();
MyOtherException myOtherException = new MyOtherException("message");
when(myActualMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
@ -138,15 +147,16 @@ public class ComparingInvocationHandlerTest {
assertThat(comparator.func(3, "str")).isEqualTo(ACTUAL_RESULT);
assertThat(log).containsExactly(String.format(
"func: Only second implementation threw exception: testException(%s)",
myOtherException.toString()));
assertThat(log)
.containsExactly(
String.format(
"func: Only second implementation threw exception: testException(%s)",
myOtherException.toString()));
}
@Test public void test_bothThrowEqual_noLog() {
MyInterface comparator = invocationHandler
.setExeptionsEquals(true)
.makeProxy();
@Test
public void test_bothThrowEqual_noLog() {
MyInterface comparator = invocationHandler.setExeptionsEquals(true).makeProxy();
MyException myException = new MyException("actual message");
MyOtherException myOtherException = new MyOtherException("second message");
when(myActualMock.func(3, "str")).thenThrow(myException);
@ -161,10 +171,9 @@ public class ComparingInvocationHandlerTest {
assertThat(log).isEmpty();
}
@Test public void test_bothThrowDifferent_logDifference() {
MyInterface comparator = invocationHandler
.setExeptionsEquals(false)
.makeProxy();
@Test
public void test_bothThrowDifferent_logDifference() {
MyInterface comparator = invocationHandler.setExeptionsEquals(false).makeProxy();
MyException myException = new MyException("actual message");
MyOtherException myOtherException = new MyOtherException("second message");
when(myActualMock.func(3, "str")).thenThrow(myException);
@ -176,14 +185,16 @@ public class ComparingInvocationHandlerTest {
} catch (MyException expected) {
}
assertThat(log).containsExactly(String.format(
"func: Both implementations threw, but got different exceptions! "
+ "'testException(%s)' vs 'testException(%s)'",
myException.toString(),
myOtherException.toString()));
assertThat(log)
.containsExactly(
String.format(
"func: Both implementations threw, but got different exceptions! "
+ "'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();
when(myActualMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
when(mySecondMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
@ -193,23 +204,21 @@ public class ComparingInvocationHandlerTest {
assertThat(log).isEmpty();
}
@Test public void test_bothReturnDifferent_logDifference() {
@Test
public void test_bothReturnDifferent_logDifference() {
MyInterface comparator = invocationHandler.makeProxy();
when(myActualMock.func(3, "str")).thenReturn(ACTUAL_RESULT);
when(mySecondMock.func(3, "str")).thenReturn(SECOND_RESULT);
assertThat(comparator.func(3, "str")).isEqualTo(ACTUAL_RESULT);
assertThat(log).containsExactly(
"func: Got different results! "
+ "'actual result' vs "
+ "'second result'");
assertThat(log)
.containsExactly("func: Got different results! 'actual result' vs 'second result'");
}
@Test public void test_usesOverriddenMethods_noDifference() {
MyInterface comparator = invocationHandler
.setDummyEquals(true)
.makeProxy();
@Test
public void test_usesOverriddenMethods_noDifference() {
MyInterface comparator = invocationHandler.setDummyEquals(true).makeProxy();
when(myActualMock.func()).thenReturn(new Dummy());
when(mySecondMock.func()).thenReturn(new Dummy());
@ -218,18 +227,14 @@ public class ComparingInvocationHandlerTest {
assertThat(log).isEmpty();
}
@Test public void test_usesOverriddenMethods_logDifference() {
MyInterface comparator = invocationHandler
.setDummyEquals(false)
.makeProxy();
@Test
public void test_usesOverriddenMethods_logDifference() {
MyInterface comparator = invocationHandler.setDummyEquals(false).makeProxy();
when(myActualMock.func()).thenReturn(new Dummy());
when(mySecondMock.func()).thenReturn(new Dummy());
comparator.func();
assertThat(log).containsExactly(
"func: Got different results! "
+ "'dummy' vs "
+ "'dummy'");
assertThat(log).containsExactly("func: Got different results! 'dummy' vs 'dummy'");
}
}