-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter Synthetic Methods in PipelineOptionsFactory #41
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2016 Google Inc. | ||
* | ||
* Licensed 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 com.google.cloud.dataflow.sdk.options; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.nullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
/** | ||
* Java 8 tests for {@link PipelineOptionsFactory}. | ||
*/ | ||
@RunWith(JUnit4.class) | ||
public class PipelineOptionsFactoryJava8Test { | ||
@Rule public ExpectedException thrown = ExpectedException.none(); | ||
|
||
private static interface OptionsWithDefaultMethod extends PipelineOptions { | ||
default Number getValue() { | ||
return 1024; | ||
} | ||
|
||
void setValue(Number value); | ||
} | ||
|
||
@Test | ||
public void testDefaultMethodIgnoresDefaultImplementation() { | ||
OptionsWithDefaultMethod optsWithDefault = | ||
PipelineOptionsFactory.as(OptionsWithDefaultMethod.class); | ||
assertThat(optsWithDefault.getValue(), nullValue()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assertNull? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm keeping as-is for the consistency of every assertion being an assertThat(foo, matches) |
||
|
||
optsWithDefault.setValue(12.25); | ||
assertThat(optsWithDefault.getValue(), equalTo(Double.valueOf(12.25))); | ||
} | ||
|
||
private static interface ExtendedOptionsWithDefault extends OptionsWithDefaultMethod {} | ||
|
||
@Test | ||
public void testDefaultMethodInExtendedClassIgnoresDefaultImplementation() { | ||
OptionsWithDefaultMethod extendedOptsWithDefault = | ||
PipelineOptionsFactory.as(ExtendedOptionsWithDefault.class); | ||
assertThat(extendedOptsWithDefault.getValue(), nullValue()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assertNull? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keeping with matchers for same reason as above |
||
|
||
extendedOptsWithDefault.setValue(Double.NEGATIVE_INFINITY); | ||
assertThat(extendedOptsWithDefault.getValue(), equalTo(Double.NEGATIVE_INFINITY)); | ||
} | ||
|
||
private static interface Options extends PipelineOptions { | ||
Number getValue(); | ||
|
||
void setValue(Number value); | ||
} | ||
|
||
private static interface SubtypeReturingOptions extends Options { | ||
@Override | ||
Integer getValue(); | ||
void setValue(Integer value); | ||
} | ||
|
||
@Test | ||
public void testReturnTypeConflictThrows() throws Exception { | ||
thrown.expect(IllegalArgumentException.class); | ||
thrown.expectMessage( | ||
"Method [getValue] has multiple definitions [public abstract java.lang.Integer " | ||
+ "com.google.cloud.dataflow.sdk.options.PipelineOptionsFactoryJava8Test$" | ||
+ "SubtypeReturingOptions.getValue(), public abstract java.lang.Number " | ||
+ "com.google.cloud.dataflow.sdk.options.PipelineOptionsFactoryJava8Test$Options" | ||
+ ".getValue()] with different return types for [" | ||
+ "com.google.cloud.dataflow.sdk.options.PipelineOptionsFactoryJava8Test$" | ||
+ "SubtypeReturingOptions]."); | ||
PipelineOptionsFactory.as(SubtypeReturingOptions.class); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the copyright change for new files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarification: probably requires a change to
checkstyle.xml
rules, etc. The change should be done atomically across all files.