This repository has been archived by the owner on Aug 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from cgruber/improvederror
Fix up a case where we report errors poorly when state is wrong, usually...
- Loading branch information
Showing
2 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
compiler/src/test/java/dagger/tests/integration/operation/FailureModeErrorsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Copyright (C) 2014 Google, Inc. | ||
* Copyright (C) 2014 Square, 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 dagger.tests.integration.operation; | ||
|
||
import dagger.Module; | ||
import dagger.ObjectGraph; | ||
import javax.inject.Inject; | ||
import javax.inject.Qualifier; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
import static junit.framework.Assert.fail; | ||
import static org.fest.assertions.Assertions.assertThat; | ||
|
||
@RunWith(JUnit4.class) | ||
public final class FailureModeErrorsTest { | ||
|
||
@Module | ||
static class CompleteModule {} | ||
|
||
static class ArrayFoo { | ||
@Inject ArrayFoo(String[] ignored) {} | ||
} | ||
|
||
@Module(injects = ArrayFoo.class, complete = false) | ||
static class ArrayFooModule {} | ||
|
||
@Test public void failOnMissingModule_arrayorgenerics() { | ||
// Generics here are crazy to try to test for, but this code path is legit regardless. | ||
try { | ||
ObjectGraph.create(new CompleteModule(), new ArrayFooModule()).get(ArrayFoo.class); | ||
fail("Should have thrown."); | ||
} catch (IllegalStateException e) { | ||
assertThat(e.getMessage()).contains( | ||
"java.lang.String[] is a generic class or an array and can only be bound with " | ||
+ "concrete type parameter(s) in a @Provides method. required by class " | ||
+ "dagger.tests.integration.operation.FailureModeErrorsTest$ArrayFoo"); | ||
} | ||
} | ||
|
||
@Qualifier @interface MyFoo {} | ||
|
||
static class QualifyingFoo { | ||
@Inject QualifyingFoo(@MyFoo String ignored) {} | ||
} | ||
|
||
@Module(injects = QualifyingFoo.class, complete = false) | ||
static class QualifyingFooModule {} | ||
|
||
@Test public void failOnMissingModule_qualified() { | ||
try { | ||
ObjectGraph.create(new CompleteModule(), new QualifyingFooModule()).get(QualifyingFoo.class); | ||
fail("Should have thrown."); | ||
} catch (IllegalStateException e) { | ||
assertThat(e.getMessage()).contains( | ||
"@dagger.tests.integration.operation.FailureModeErrorsTest$MyFoo()/java.lang.String " | ||
+ "is a @Qualifier-annotated type and must be bound by a @Provides method. required by " | ||
+ "class dagger.tests.integration.operation.FailureModeErrorsTest$QualifyingFoo"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters