It works with dependencies

This commit is contained in:
Gianmarco Pettinato 2022-04-10 14:27:35 +02:00
parent 9ca39a9ec3
commit d08b2b036d
4 changed files with 57 additions and 12 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}

12
pom.xml
View File

@ -18,6 +18,13 @@
<maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.target>1.7</maven.compiler.target>
</properties> </properties>
<repositories>
<repository>
<id>com.gitlesson.demolibrary</id>
<url>http://192.168.1.5:8087/repository/Alten-examples/</url>
</repository>
</repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
@ -25,6 +32,11 @@
<version>4.11</version> <version>4.11</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.gitlesson.demolibrary</groupId>
<artifactId>demolibrary</artifactId>
<version>1.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -1,13 +1,14 @@
package com.gitlesson; package com.gitlesson;
import com.gitlesson.demolibrary.TestLibrary;
/** /**
* Hello world! * Prints the string that gets from TestLibrary!
* *
*/ */
public class App public class App {
{ public static void main(String[] args) {
public static void main( String[] args ) String test = TestLibrary.getText();
{ System.out.println(test);
System.out.println( "Hello World!" );
} }
} }

View File

@ -1,20 +1,49 @@
package com.gitlesson; package com.gitlesson;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import com.gitlesson.demolibrary.TestLibrary;
/** /**
* Unit test for simple App. * Unit test for simple App.
*/ */
public class AppTest public class AppTest {
{ private final PrintStream stardardOut = System.out;
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
/**
* substitute the standard output with
* a new object because we need to check
* if the method Main writes the correct string
*/
@Before
public void setup() {
System.setOut(new PrintStream(outputStreamCaptor));
}
/**
* Reset the standard out to the system one
*/
@After
public void restore() {
System.setOut(stardardOut);
}
/** /**
* Rigorous Test :-) * Rigorous Test :-)
*/ */
@Test @Test
public void shouldAnswerWithTrue() public void shouldAnswerWithTrue() {
{ String[] args = new String[0];
assertTrue( true ); App.main(args);
String result = outputStreamCaptor.toString();
String expected = TestLibrary.getText();
assertEquals("This strings should match", expected, result);
} }
} }