-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test instead of Main class for DI Exercise
- Loading branch information
Showing
7 changed files
with
157 additions
and
74 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,16 +1,23 @@ | ||
<?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> | ||
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> | ||
|
||
<parent> | ||
<groupId>com.epam.training</groupId> | ||
<artifactId>unideb-prog2-parent</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
<parent> | ||
<groupId>com.epam.training</groupId> | ||
<artifactId>unideb-prog2-parent</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
|
||
<artifactId>dependency-injection-framework</artifactId> | ||
<artifactId>dependency-injection-framework</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
40 changes: 0 additions & 40 deletions
40
week-8/dependency-injection-framework/src/main/java/com/epam/training/Main.java
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -10,5 +10,5 @@ | |
public @interface Qualifier { | ||
|
||
public String name(); | ||
|
||
} |
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
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
115 changes: 115 additions & 0 deletions
115
...ction-framework/src/test/java/com/epam/training/di/impl/DiContextImplIntegrationTest.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,115 @@ | ||
package com.epam.training.di.impl; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.epam.training.di.Configuration; | ||
import com.epam.training.di.DiContext; | ||
import com.epam.training.di.annotation.Bean; | ||
import com.epam.training.di.annotation.Qualifier; | ||
|
||
public class DiContextImplIntegrationTest { | ||
|
||
private DiContext context = new DiContextBuilder().build(new DiContextImplIntegrationTest.ContextConfig()); | ||
|
||
@Test | ||
public void testGetBeanShouldReturnWithStringAWhenThisBeanExists() { | ||
// Given | ||
String expected = "StringA"; | ||
|
||
// When | ||
Optional<String> actual = context.getBean("stringBeanA", String.class); | ||
|
||
// Then | ||
assertTrue(actual.isPresent()); | ||
assertEquals(expected, actual.get()); | ||
} | ||
|
||
@Test | ||
public void testGetBeanShouldReturnWithStringBWhenThisBeanExists() { | ||
// Given | ||
String expected = "StringB"; | ||
|
||
// When | ||
Optional<String> actual = context.getBean("stringBeanB", String.class); | ||
|
||
// Then | ||
assertTrue(actual.isPresent()); | ||
assertEquals(expected, actual.get()); | ||
} | ||
|
||
@Test | ||
public void testGetBeanShouldReturnWithIntegerBeanWhenGetIsCalledWithTypeOnly() { | ||
// Given | ||
Integer expected = 10; | ||
|
||
// When | ||
Optional<Integer> actual = context.getBean(Integer.class); | ||
|
||
// Then | ||
assertTrue(actual.isPresent()); | ||
assertEquals(expected, actual.get()); | ||
} | ||
|
||
@Test | ||
public void testGetBeanShouldReturnWithStringBuilderBeanWhenGetIsCalledWithTypeOnly() { | ||
// Given | ||
String expected = "StringA10"; | ||
|
||
// When | ||
Optional<StringBuilder> actual = context.getBean(StringBuilder.class); | ||
|
||
// Then | ||
assertTrue(actual.isPresent()); | ||
assertEquals(expected, actual.get().toString()); | ||
} | ||
|
||
@Test | ||
public void testGetBeanShouldReturnWithOptionalEmptyWhenBeanDoesNotExist() { | ||
// Given | ||
|
||
// When | ||
Optional<String> actual = context.getBean("stringBean", String.class); | ||
|
||
// Then | ||
assertTrue(actual.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testGetBeanShouldThrowAnExceptionWhenMoreBeansAreAvailable() { | ||
// Given | ||
|
||
// When Then | ||
assertThrows(IllegalArgumentException.class, () -> context.getBean(String.class)); | ||
} | ||
|
||
public static class ContextConfig implements Configuration { | ||
|
||
@Bean | ||
public String stringBeanA() { | ||
return "StringA"; | ||
} | ||
|
||
@Bean | ||
public String stringBeanB() { | ||
return "StringB"; | ||
} | ||
|
||
@Bean | ||
public Integer integerBean() { | ||
return 10; | ||
} | ||
|
||
@Bean | ||
public StringBuilder stringBuilder(@Qualifier(name = "stringBeanA") String string, Integer integer) { | ||
return new StringBuilder(string).append(integer); | ||
} | ||
|
||
} | ||
|
||
} |