Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.

Commit 618a7d6

Browse files
committed
Merge pull request #480 from chiuki/master
Add test to examples/simple (from website)
2 parents b5c6517 + 52277d6 commit 618a7d6

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

examples/simple/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,16 @@
3838
<version>${project.version}</version>
3939
<optional>true</optional>
4040
</dependency>
41+
42+
<dependency>
43+
<groupId>junit</groupId>
44+
<artifactId>junit</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.mockito</groupId>
49+
<artifactId>mockito-core</artifactId>
50+
<scope>test</scope>
51+
</dependency>
4152
</dependencies>
4253
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright (C) 2015 Square, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package coffee;
17+
18+
import dagger.Module;
19+
import dagger.ObjectGraph;
20+
import dagger.Provides;
21+
import javax.inject.Inject;
22+
import javax.inject.Singleton;
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.junit.runners.JUnit4;
27+
import org.mockito.Mockito;
28+
29+
public class CoffeeMakerTest {
30+
@Inject CoffeeMaker coffeeMaker;
31+
@Inject Heater heater;
32+
33+
@Before public void setUp() {
34+
ObjectGraph.create(new TestModule()).inject(this);
35+
}
36+
37+
@Module(
38+
includes = DripCoffeeModule.class,
39+
injects = CoffeeMakerTest.class,
40+
overrides = true
41+
)
42+
static class TestModule {
43+
@Provides @Singleton Heater provideHeater() {
44+
return Mockito.mock(Heater.class);
45+
}
46+
}
47+
48+
@Test public void testHeaterIsTurnedOnAndThenOff() {
49+
Mockito.when(heater.isHot()).thenReturn(true);
50+
coffeeMaker.brew();
51+
Mockito.verify(heater, Mockito.times(1)).on();
52+
Mockito.verify(heater, Mockito.times(1)).off();
53+
}
54+
}

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<fest.version>1.4</fest.version>
5252
<truth.version>0.13</truth.version>
5353
<compile-testing.version>0.4</compile-testing.version>
54+
<mockito.version>1.10.19</mockito.version>
5455
</properties>
5556

5657
<scm>
@@ -114,6 +115,11 @@
114115
<artifactId>truth</artifactId>
115116
<version>${truth.version}</version>
116117
</dependency>
118+
<dependency>
119+
<groupId>org.mockito</groupId>
120+
<artifactId>mockito-core</artifactId>
121+
<version>${mockito.version}</version>
122+
</dependency>
117123
</dependencies>
118124
</dependencyManagement>
119125

0 commit comments

Comments
 (0)