Skip to content

Commit

Permalink
Run google-java-format on all Guice code.
Browse files Browse the repository at this point in the history
configure a presubmit to ensure that it stays formatted.

Highlights include:
* simplified import order
* method annotations are now consistently defined on the preceding line
* javadoc reformatted to 100 chars column width

One test that contained line numbers in error messages had to be modified and
the formatter didn't like some of the more complicated preprocessor directives
(MOE and AOP).

To avoid formatting the copyright notices as javadoc i did a preprocessing step to rewrite the initial '/**' to '/*' using perl

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132718493
  • Loading branch information
lukesandberg authored and sameb committed Sep 13, 2016
1 parent d66a079 commit 34e7c5d
Show file tree
Hide file tree
Showing 44 changed files with 4,551 additions and 3,344 deletions.
19 changes: 7 additions & 12 deletions core/test/com/google/inject/AllTests.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2006 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -42,24 +42,19 @@
import com.google.inject.util.OverrideModuleTest;
import com.google.inject.util.ProvidersTest;
import com.google.inject.util.TypesTest;

import com.googlecode.guice.GuiceTck;
import com.googlecode.guice.Jsr330Test;

import java.util.Set;
import junit.framework.Test;
import junit.framework.TestSuite;

import java.util.Set;

/**
* @author [email protected] (Bob Lee)
*/
/** @author [email protected] (Bob Lee) */
public class AllTests {

private static final Set<String> SUPPRESSED_TEST_NAMES = ImmutableSet.of(
"testUnscopedProviderWorksOutsideOfRequestedScope(" + ScopesTest.class.getName() + ")",
"testCannotConvertUnannotatedBindings(" + TypeConversionTest.class.getName() + ")"
);
private static final Set<String> SUPPRESSED_TEST_NAMES =
ImmutableSet.of(
"testUnscopedProviderWorksOutsideOfRequestedScope(" + ScopesTest.class.getName() + ")",
"testCannotConvertUnannotatedBindings(" + TypeConversionTest.class.getName() + ")");

public static Test suite() {
TestSuite suite = new TestSuite();
Expand Down
72 changes: 33 additions & 39 deletions core/test/com/google/inject/Asserts.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,7 +14,6 @@
* limitations under the License.
*/


package com.google.inject;

import static com.google.inject.internal.InternalFlags.IncludeStackTraceOption;
Expand All @@ -29,9 +28,6 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.testing.GcFinalization;

import junit.framework.Assert;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -40,29 +36,33 @@
import java.io.ObjectOutputStream;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import junit.framework.Assert;

/**
* @author [email protected] (Jesse Wilson)
*/
/** @author [email protected] (Jesse Wilson) */
public class Asserts {
private Asserts() {}

/**
* Returns the String that would appear in an error message for this chain of classes
* as modules.
* Returns the String that would appear in an error message for this chain of classes as modules.
*/
public static String asModuleChain(Class... classes) {
return Joiner.on(" -> ").appendTo(new StringBuilder(" (via modules: "),
Iterables.transform(ImmutableList.copyOf(classes), new Function<Class, String>() {
@Override
public String apply(Class input) {
return input.getName();
}
})).append(")").toString();
return Joiner.on(" -> ")
.appendTo(
new StringBuilder(" (via modules: "),
Iterables.transform(
ImmutableList.copyOf(classes),
new Function<Class, String>() {
@Override
public String apply(Class input) {
return input.getName();
}
}))
.append(")")
.toString();
}

/**
* Returns the source file appears in error messages based on {@link
* Returns the source file appears in error messages based on {@link
* #getIncludeStackTraceOption()} value.
*/
public static String getDeclaringSourcePart(Class clazz) {
Expand All @@ -89,9 +89,8 @@ public static boolean isIncludeStackTraceComplete() {
}

/**
* Fails unless {@code expected.equals(actual)}, {@code
* actual.equals(expected)} and their hash codes are equal. This is useful
* for testing the equals method itself.
* Fails unless {@code expected.equals(actual)}, {@code actual.equals(expected)} and their hash
* codes are equal. This is useful for testing the equals method itself.
*/
public static void assertEqualsBothWays(Object expected, Object actual) {
assertNotNull(expected);
Expand All @@ -101,17 +100,14 @@ public static void assertEqualsBothWays(Object expected, Object actual) {
assertEquals("hashCode", expected.hashCode(), actual.hashCode());
}

/**
* Fails unless {@code text} includes all {@code substrings}, in order,
* no duplicates
*/
/** Fails unless {@code text} includes all {@code substrings}, in order, no duplicates */
public static void assertContains(String text, String... substrings) {
assertContains(text, false, substrings);
}

/**
* Fails unless {@code text} includes all {@code substrings}, in order,
* and optionally {@code allowDuplicates}.
* Fails unless {@code text} includes all {@code substrings}, in order, and optionally {@code
* allowDuplicates}.
*/
public static void assertContains(String text, boolean allowDuplicates, String... substrings) {
/*if[NO_AOP]
Expand All @@ -124,31 +120,29 @@ public static void assertContains(String text, boolean allowDuplicates, String..
int startingFrom = 0;
for (String substring : substrings) {
int index = text.indexOf(substring, startingFrom);
assertTrue(String.format("Expected \"%s\" to contain substring \"%s\"", text, substring),
assertTrue(
String.format("Expected \"%s\" to contain substring \"%s\"", text, substring),
index >= startingFrom);
startingFrom = index + substring.length();
}

if (! allowDuplicates) {
if (!allowDuplicates) {
String lastSubstring = substrings[substrings.length - 1];
assertTrue(String.format("Expected \"%s\" to contain substring \"%s\" only once),",
text, lastSubstring), text.indexOf(lastSubstring, startingFrom) == -1);
assertTrue(
String.format(
"Expected \"%s\" to contain substring \"%s\" only once),", text, lastSubstring),
text.indexOf(lastSubstring, startingFrom) == -1);
}
}

/**
* Fails unless {@code object} doesn't equal itself when reserialized.
*/
public static void assertEqualWhenReserialized(Object object)
throws IOException {
/** Fails unless {@code object} doesn't equal itself when reserialized. */
public static void assertEqualWhenReserialized(Object object) throws IOException {
Object reserialized = reserialize(object);
assertEquals(object, reserialized);
assertEquals(object.hashCode(), reserialized.hashCode());
}

/**
* Fails unless {@code object} has the same toString value when reserialized.
*/
/** Fails unless {@code object} has the same toString value when reserialized. */
public static void assertSimilarWhenReserialized(Object object) throws IOException {
Object reserialized = reserialize(object);
assertEquals(object.toString(), reserialized.toString());
Expand Down
Loading

0 comments on commit 34e7c5d

Please sign in to comment.