Skip to content

Commit 9eab427

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 1a05e67 + e2202f0 commit 9eab427

7 files changed

Lines changed: 75 additions & 8 deletions

File tree

‎patterns/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
###Relevant Articles:
22
- [A Guide to the Front Controller Pattern in Java](http://www.baeldung.com/java-front-controller-pattern)
33
- [Introduction to Intercepting Filter Pattern in Java](http://www.baeldung.com/intercepting-filter-pattern-in-java)
4+
- [Implementing the Template Method Pattern in Java](http://www.baeldung.com/template-method-pattern-in-java)

‎patterns/pom.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<modules>
1010
<module>front-controller</module>
1111
<module>intercepting-filter</module>
12+
<module>template-method</module>
1213
</modules>
1314

1415
<parent>
@@ -51,4 +52,4 @@
5152
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
5253
<jetty-maven-plugin.version>9.4.0.v20161208</jetty-maven-plugin.version>
5354
</properties>
54-
</project>
55+
</project>

‎patterns/template-method/pom.xml‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.baeldung.templatemethodpattern</groupId>
5-
<artifactId>templatemethodpattern</artifactId>
4+
<groupId>com.baeldung.templatemethod</groupId>
5+
<artifactId>template-method</artifactId>
66
<version>1.0</version>
77
<packaging>jar</packaging>
8-
<properties>
9-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10-
<maven.compiler.source>1.8</maven.compiler.source>
11-
<maven.compiler.target>1.8</maven.compiler.target>
12-
</properties>
8+
<parent>
9+
<groupId>com.baeldung.patterns</groupId>
10+
<artifactId>patterns-parent</artifactId>
11+
<version>1.0.0-SNAPSHOT</version>
12+
<relativePath>..</relativePath>
13+
</parent>
14+
1315
<dependencies>
1416
<dependency>
1517
<groupId>junit</groupId>
@@ -18,4 +20,18 @@
1820
<scope>test</scope>
1921
</dependency>
2022
</dependencies>
23+
<build>
24+
<plugins>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-compiler-plugin</artifactId>
28+
<version>3.7.0</version>
29+
</plugin>
30+
</plugins>
31+
</build>
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
<maven.compiler.source>1.8</maven.compiler.source>
35+
<maven.compiler.target>1.8</maven.compiler.target>
36+
</properties>
2137
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.baeldung.mockito;
2+
3+
public class FinalList extends MyList {
4+
5+
@Override
6+
public int size() {
7+
return 1;
8+
}
9+
10+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.baeldung.mockito;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertNotEquals;
6+
import static org.mockito.Mockito.mock;
7+
import static org.mockito.Mockito.when;
8+
9+
public class MockFinals {
10+
11+
@Test
12+
public void whenMockFinalClassMockWorks() {
13+
14+
FinalList finalList = new FinalList();
15+
16+
FinalList mock = mock(FinalList.class);
17+
when(mock.size()).thenReturn(2);
18+
19+
assertNotEquals(mock.size(), finalList.size());
20+
21+
}
22+
23+
@Test
24+
public void whenMockFinalMethodMockWorks() {
25+
26+
MyList myList = new MyList();
27+
28+
MyList mock = mock(MyList.class);
29+
when(mock.finalMethod()).thenReturn(1);
30+
31+
assertNotEquals(mock.finalMethod(), myList.finalMethod());
32+
}
33+
34+
35+
}

‎testing-modules/mockito/src/test/java/org/baeldung/mockito/MyList.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ public void add(int index, String element) {
1919
// no-op
2020
}
2121

22+
final public int finalMethod() {
23+
return 0;
24+
}
2225
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mock-maker-inline

0 commit comments

Comments
 (0)