Merge remote-tracking branch 'upstream/master'

This commit is contained in:
abialas 2017-11-19 21:35:00 +01:00
commit 9eab427cf4
7 changed files with 75 additions and 8 deletions

View File

@ -1,3 +1,4 @@
###Relevant Articles:
- [A Guide to the Front Controller Pattern in Java](http://www.baeldung.com/java-front-controller-pattern)
- [Introduction to Intercepting Filter Pattern in Java](http://www.baeldung.com/intercepting-filter-pattern-in-java)
- [Implementing the Template Method Pattern in Java](http://www.baeldung.com/template-method-pattern-in-java)

View File

@ -9,6 +9,7 @@
<modules>
<module>front-controller</module>
<module>intercepting-filter</module>
<module>template-method</module>
</modules>
<parent>
@ -51,4 +52,4 @@
<maven-war-plugin.version>3.0.0</maven-war-plugin.version>
<jetty-maven-plugin.version>9.4.0.v20161208</jetty-maven-plugin.version>
</properties>
</project>
</project>

View File

@ -1,15 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.templatemethodpattern</groupId>
<artifactId>templatemethodpattern</artifactId>
<groupId>com.baeldung.templatemethod</groupId>
<artifactId>template-method</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>com.baeldung.patterns</groupId>
<artifactId>patterns-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
@ -18,4 +20,18 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

View File

@ -0,0 +1,10 @@
package org.baeldung.mockito;
public class FinalList extends MyList {
@Override
public int size() {
return 1;
}
}

View File

@ -0,0 +1,35 @@
package org.baeldung.mockito;
import org.junit.Test;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class MockFinals {
@Test
public void whenMockFinalClassMockWorks() {
FinalList finalList = new FinalList();
FinalList mock = mock(FinalList.class);
when(mock.size()).thenReturn(2);
assertNotEquals(mock.size(), finalList.size());
}
@Test
public void whenMockFinalMethodMockWorks() {
MyList myList = new MyList();
MyList mock = mock(MyList.class);
when(mock.finalMethod()).thenReturn(1);
assertNotEquals(mock.finalMethod(), myList.finalMethod());
}
}

View File

@ -19,4 +19,7 @@ class MyList extends AbstractList<String> {
// no-op
}
final public int finalMethod() {
return 0;
}
}