Skip to content

Commit 7866e3e

Browse files
authored
Merge pull request eugenp#4971 from dkapil/task/BAEL-8219
BAEL-8219 Fix tests for core-java, maven and core-java-io projects
2 parents 3f2271f + 3b64d8e commit 7866e3e

8 files changed

Lines changed: 158 additions & 143 deletions

File tree

‎core-java-io/src/test/java/com/baeldung/file/FilenameFilterManualTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class FilenameFilterManualTest {
1818
@BeforeClass
1919
public static void setupClass() {
2020
directory = new File(FilenameFilterManualTest.class.getClassLoader()
21-
.getResource("testFolder")
21+
.getResource("fileNameFilterManualTestFolder")
2222
.getFile());
2323
}
2424

core-java-io/src/test/resources/testFolder/people.json renamed to core-java-io/src/test/resources/fileNameFilterManualTestFolder/people.json

File renamed without changes.

core-java-io/src/test/resources/testFolder/students.json renamed to core-java-io/src/test/resources/fileNameFilterManualTestFolder/students.json

File renamed without changes.

core-java-io/src/test/resources/testFolder/teachers.xml renamed to core-java-io/src/test/resources/fileNameFilterManualTestFolder/teachers.xml

File renamed without changes.

core-java-io/src/test/resources/testFolder/workers.xml renamed to core-java-io/src/test/resources/fileNameFilterManualTestFolder/workers.xml

File renamed without changes.

‎core-java/src/main/java/com/baeldung/exceptionhandling/Exceptions.java‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ public static List<Player> getPlayers() throws IOException {
2525
}
2626

2727
public List<Player> loadAllPlayers(String playersFile) throws IOException{
28-
try {
29-
throw new IOException();
30-
} catch(IOException ex) {
31-
throw new IllegalStateException();
32-
}
28+
throw new IOException();
3329
}
3430

3531
public int getPlayerScoreThrows(String playerFile) throws FileNotFoundException {
@@ -163,14 +159,8 @@ public List<Player> loadAllPlayers(String playersFile) { //can't add "throws My
163159
}
164160
}
165161

166-
public void throwAsGotoAntiPattern() {
167-
try {
168-
// bunch of code
169-
throw new MyException();
170-
// second bunch of code
171-
} catch ( MyException e ) {
172-
// third bunch of code
173-
}
162+
public void throwAsGotoAntiPattern() throws MyException {
163+
throw new MyException();
174164
}
175165

176166
public int getPlayerScoreSwallowingExceptionAntiPattern(String playerFile) {

‎core-java/src/test/java/com/baeldung/binding/AnimalUnitTest.java‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
import static org.hamcrest.CoreMatchers.is;
1818
import static org.junit.Assert.assertThat;
19+
import static org.mockito.Mockito.times;
1920
import static org.mockito.Mockito.verify;
2021

22+
import java.util.List;
23+
2124
/**
2225
* Created by madhumita.g on 01-08-2018.
2326
*/
@@ -66,20 +69,18 @@ public void whenCalledWithParameters_shouldCallFunctionMakeNoiseWithParameters()
6669
int testValue = 3;
6770
animal.makeNoise(testValue);
6871

69-
verify(mockAppender).doAppend(captorLoggingEvent.capture());
72+
verify(mockAppender,times(3)).doAppend(captorLoggingEvent.capture());
7073

71-
final LoggingEvent loggingEvent = captorLoggingEvent.getValue();
74+
final List<LoggingEvent> loggingEvents = captorLoggingEvent.getAllValues();
7275

73-
while (testValue != 0) {
76+
for(LoggingEvent loggingEvent : loggingEvents)
77+
{
7478
assertThat(loggingEvent.getLevel(), is(Level.INFO));
7579

7680
assertThat(loggingEvent.getFormattedMessage(),
77-
is("generic animal noise countdown 3\n"
78-
+ "generic animal noise countdown 2\n"
79-
+ "generic animal noise countdown 1\n"));
80-
81-
testValue-=1;
81+
is("generic animal noise countdown "+testValue));
8282

83+
testValue--;
8384
}
8485
}
8586

‎maven/pom.xml‎

Lines changed: 145 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,151 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.baeldung</groupId>
5-
<artifactId>maven</artifactId>
6-
<version>0.0.1-SNAPSHOT</version>
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>maven</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
77

8-
<parent>
9-
<artifactId>parent-modules</artifactId>
10-
<groupId>com.baeldung</groupId>
11-
<version>1.0.0-SNAPSHOT</version>
12-
</parent>
8+
<parent>
9+
<artifactId>parent-modules</artifactId>
10+
<groupId>com.baeldung</groupId>
11+
<version>1.0.0-SNAPSHOT</version>
12+
</parent>
1313

14-
<build>
15-
<plugins>
16-
<plugin>
17-
<artifactId>maven-resources-plugin</artifactId>
18-
<version>${maven.resources.version}</version>
19-
<configuration>
20-
<outputDirectory>output-resources</outputDirectory>
21-
<resources>
22-
<resource>
23-
<directory>input-resources</directory>
24-
<excludes>
25-
<exclude>*.png</exclude>
26-
</excludes>
27-
<filtering>true</filtering>
28-
</resource>
29-
</resources>
30-
</configuration>
31-
</plugin>
32-
<plugin>
33-
<artifactId>maven-compiler-plugin</artifactId>
34-
<version>${maven-compiler-plugin.version}</version>
35-
<configuration>
36-
<source>${java.version}</source>
37-
<target>${java.version}</target>
38-
<compilerArgs>
39-
<arg>-Xlint:unchecked</arg>
40-
</compilerArgs>
41-
</configuration>
42-
</plugin>
43-
<plugin>
44-
<artifactId>maven-surefire-plugin</artifactId>
45-
<version>${maven-surefire-plugin.version}</version>
46-
<configuration>
47-
<excludes>
48-
<exclude>DataTest.java</exclude>
49-
</excludes>
50-
<includes>
51-
<include>TestFail.java</include>
52-
<include>DataCheck.java</include>
53-
</includes>
54-
<testFailureIgnore>true</testFailureIgnore>
55-
</configuration>
56-
</plugin>
57-
<plugin>
58-
<artifactId>maven-failsafe-plugin</artifactId>
59-
<version>${maven.failsafe.version}</version>
60-
<executions>
61-
<execution>
62-
<goals>
63-
<goal>integration-test</goal>
64-
<goal>verify</goal>
65-
</goals>
66-
<configuration>
67-
<!-- configuration similar to surefire -->
68-
</configuration>
69-
</execution>
70-
</executions>
71-
</plugin>
72-
<plugin>
73-
<artifactId>maven-verifier-plugin</artifactId>
74-
<version>${maven.verifier.version}</version>
75-
<configuration>
76-
<verificationFile>input-resources/verifications.xml</verificationFile>
77-
</configuration>
78-
<executions>
79-
<execution>
80-
<goals>
81-
<goal>verify</goal>
82-
</goals>
83-
</execution>
84-
</executions>
85-
</plugin>
86-
<plugin>
87-
<artifactId>maven-clean-plugin</artifactId>
88-
<version>${maven.clean.version}</version>
89-
<configuration>
90-
<filesets>
91-
<fileset>
92-
<directory>output-resources</directory>
93-
</fileset>
94-
</filesets>
95-
</configuration>
96-
</plugin>
97-
<plugin>
98-
<groupId>org.codehaus.mojo</groupId>
99-
<artifactId>build-helper-maven-plugin</artifactId>
100-
<version>${maven.build.helper.version}</version>
101-
<executions>
102-
<execution>
103-
<phase>generate-sources</phase>
104-
<goals>
105-
<goal>add-source</goal>
106-
</goals>
107-
<configuration>
108-
<sources>
109-
<source>src/main/another-src</source>
110-
</sources>
111-
</configuration>
112-
</execution>
113-
</executions>
114-
</plugin>
115-
</plugins>
116-
</build>
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<artifactId>maven-resources-plugin</artifactId>
18+
<version>${maven.resources.version}</version>
19+
<configuration>
20+
<outputDirectory>output-resources</outputDirectory>
21+
<resources>
22+
<resource>
23+
<directory>input-resources</directory>
24+
<excludes>
25+
<exclude>*.png</exclude>
26+
</excludes>
27+
<filtering>true</filtering>
28+
</resource>
29+
</resources>
30+
</configuration>
31+
</plugin>
32+
<plugin>
33+
<artifactId>maven-compiler-plugin</artifactId>
34+
<version>${maven-compiler-plugin.version}</version>
35+
<configuration>
36+
<source>${java.version}</source>
37+
<target>${java.version}</target>
38+
<compilerArgs>
39+
<arg>-Xlint:unchecked</arg>
40+
</compilerArgs>
41+
</configuration>
42+
</plugin>
43+
<plugin>
44+
<artifactId>maven-surefire-plugin</artifactId>
45+
<version>${maven-surefire-plugin.version}</version>
46+
<configuration>
47+
<excludes>
48+
<exclude>DataTest.java</exclude>
49+
</excludes>
50+
<includes>
51+
<include>TestFail.java</include>
52+
<include>DataCheck.java</include>
53+
</includes>
54+
<testFailureIgnore>true</testFailureIgnore>
55+
</configuration>
56+
</plugin>
57+
<plugin>
58+
<artifactId>maven-failsafe-plugin</artifactId>
59+
<version>${maven.failsafe.version}</version>
60+
<executions>
61+
<execution>
62+
<goals>
63+
<goal>integration-test</goal>
64+
<goal>verify</goal>
65+
</goals>
66+
<configuration>
67+
<!-- configuration similar to surefire -->
68+
</configuration>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
<plugin>
73+
<artifactId>maven-verifier-plugin</artifactId>
74+
<version>${maven.verifier.version}</version>
75+
<configuration>
76+
<verificationFile>input-resources/verifications.xml</verificationFile>
77+
</configuration>
78+
<executions>
79+
<execution>
80+
<goals>
81+
<goal>verify</goal>
82+
</goals>
83+
</execution>
84+
</executions>
85+
</plugin>
86+
<plugin>
87+
<artifactId>maven-clean-plugin</artifactId>
88+
<version>${maven.clean.version}</version>
89+
<configuration>
90+
<filesets>
91+
<fileset>
92+
<directory>output-resources</directory>
93+
</fileset>
94+
</filesets>
95+
</configuration>
96+
</plugin>
97+
<plugin>
98+
<groupId>org.codehaus.mojo</groupId>
99+
<artifactId>build-helper-maven-plugin</artifactId>
100+
<version>${maven.build.helper.version}</version>
101+
<executions>
102+
<execution>
103+
<phase>generate-sources</phase>
104+
<goals>
105+
<goal>add-source</goal>
106+
</goals>
107+
<configuration>
108+
<sources>
109+
<source>src/main/another-src</source>
110+
</sources>
111+
</configuration>
112+
</execution>
113+
</executions>
114+
</plugin>
115+
</plugins>
116+
</build>
117117

118-
<properties>
119-
<maven.resources.version>3.0.2</maven.resources.version>
120-
<maven.failsafe.version>2.21.0</maven.failsafe.version>
121-
<maven.verifier.version>1.1</maven.verifier.version>
122-
<maven.clean.version>3.0.0</maven.clean.version>
123-
<maven.build.helper.version>3.0.0</maven.build.helper.version>
124-
<resources.name>Baeldung</resources.name>
125-
</properties>
118+
<profiles>
119+
<profile>
120+
<id>default</id>
121+
<build>
122+
<plugins>
123+
<plugin>
124+
<artifactId>maven-surefire-plugin</artifactId>
125+
<version>${maven-surefire-plugin.version}</version>
126+
<configuration>
127+
<excludes>
128+
<exclude>DataTest.java</exclude>
129+
</excludes>
130+
<includes>
131+
<include>TestFail.java</include>
132+
<include>DataCheck.java</include>
133+
</includes>
134+
<testFailureIgnore>true</testFailureIgnore>
135+
</configuration>
136+
</plugin>
137+
</plugins>
138+
</build>
139+
</profile>
140+
</profiles>
141+
142+
<properties>
143+
<maven.resources.version>3.0.2</maven.resources.version>
144+
<maven.failsafe.version>2.21.0</maven.failsafe.version>
145+
<maven.verifier.version>1.1</maven.verifier.version>
146+
<maven.clean.version>3.0.0</maven.clean.version>
147+
<maven.build.helper.version>3.0.0</maven.build.helper.version>
148+
<resources.name>Baeldung</resources.name>
149+
</properties>
126150

127151
</project>

0 commit comments

Comments
 (0)