Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
9def3e3edb
|
@ -1,55 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<!-- com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOT -->
|
||||
<parent>
|
||||
<artifactId>osgi-intro</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<!-- Please, note this is not the usual 'jar'. -->
|
||||
<packaging>bundle</packaging>
|
||||
|
||||
<artifactId>osgi-intro-sample-activator</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>org.osgi.core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
|
||||
<!-- Qualified name of the class that exposes the activator iface. -->
|
||||
<Bundle-Activator>com.baeldung.osgi.sample.activator.HelloWorld</Bundle-Activator>
|
||||
|
||||
<!-- One important thing to note:
|
||||
since you are not exporting the package "com.baeldung.osgi.sample.activator",
|
||||
you should at least add it to the Private-Package instruction.
|
||||
Otherwise, the classes inside the package will not be copied to your bundle,
|
||||
as the default value of this instruction is empty. -->
|
||||
|
||||
<Private-Package>com.baeldung.osgi.sample.activator</Private-Package>
|
||||
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -1,16 +0,0 @@
|
|||
package com.baeldung.osgi.sample.activator;
|
||||
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
public class HelloWorld implements BundleActivator {
|
||||
|
||||
public void start(BundleContext ctx) {
|
||||
System.out.println("Hello World.");
|
||||
}
|
||||
|
||||
public void stop(BundleContext bundleContext) {
|
||||
System.out.println("Goodbye World.");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>osgi-intro</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<!-- mvn:com.baeldung/osgi-intro-sample-client/1.0-SNAPSHOT -->
|
||||
<artifactId>osgi-intro-sample-client</artifactId>
|
||||
|
||||
<packaging>bundle</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>osgi-intro-sample-service</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>org.osgi.core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
<Bundle-Activator>com.baeldung.osgi.sample.client.Client</Bundle-Activator>
|
||||
|
||||
<Private-Package>com.baeldung.osgi.sample.client</Private-Package>
|
||||
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -1,44 +0,0 @@
|
|||
package com.baeldung.osgi.sample.client;
|
||||
|
||||
import com.baeldung.osgi.sample.service.definition.Greeter;
|
||||
import org.osgi.framework.*;
|
||||
|
||||
public class Client implements BundleActivator, ServiceListener {
|
||||
|
||||
private BundleContext ctx;
|
||||
private ServiceReference serviceReference;
|
||||
|
||||
public void start(BundleContext ctx) {
|
||||
this.ctx = ctx;
|
||||
try {
|
||||
ctx.addServiceListener(this, "(objectclass=" + Greeter.class.getName() + ")");
|
||||
} catch (InvalidSyntaxException ise) {
|
||||
ise.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(BundleContext bundleContext) {
|
||||
if (serviceReference != null) {
|
||||
ctx.ungetService(serviceReference);
|
||||
}
|
||||
this.ctx = null;
|
||||
}
|
||||
|
||||
public void serviceChanged(ServiceEvent serviceEvent) {
|
||||
int type = serviceEvent.getType();
|
||||
switch (type) {
|
||||
case (ServiceEvent.REGISTERED):
|
||||
System.out.println("Notification of service registered.");
|
||||
serviceReference = serviceEvent.getServiceReference();
|
||||
Greeter service = (Greeter) (ctx.getService(serviceReference));
|
||||
System.out.println(service.sayHiTo("John"));
|
||||
break;
|
||||
case (ServiceEvent.UNREGISTERING):
|
||||
System.out.println("Notification of service unregistered.");
|
||||
ctx.ungetService(serviceEvent.getServiceReference());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<!-- mvn:com.baeldung/osgi-intro-sample-service/1.0-SNAPSHOT -->
|
||||
<parent>
|
||||
<artifactId>osgi-intro</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>osgi-intro-sample-service</artifactId>
|
||||
|
||||
<!-- Please, note this is not the usual 'jar'. -->
|
||||
<packaging>bundle</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>org.osgi.core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
|
||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||
<Bundle-Version>${project.version}</Bundle-Version>
|
||||
<Bundle-Activator>com.baeldung.osgi.sample.service.implementation.GreeterImpl</Bundle-Activator>
|
||||
<Private-Package>com.baeldung.osgi.sample.service.implementation</Private-Package>
|
||||
<Export-Package>com.baeldung.osgi.sample.service.definition</Export-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -1,7 +0,0 @@
|
|||
package com.baeldung.osgi.sample.service.definition;
|
||||
|
||||
public interface Greeter {
|
||||
|
||||
public String sayHiTo(String name);
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.baeldung.osgi.sample.service.implementation;
|
||||
|
||||
import com.baeldung.osgi.sample.service.definition.Greeter;
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class GreeterImpl implements Greeter, BundleActivator {
|
||||
|
||||
private ServiceReference<Greeter> reference;
|
||||
private ServiceRegistration<Greeter> registration;
|
||||
|
||||
@Override public String sayHiTo(String name) {
|
||||
return "Hello " + name;
|
||||
}
|
||||
|
||||
@Override public void start(BundleContext context) throws Exception {
|
||||
System.out.println("Registering service.");
|
||||
registration = context.registerService(Greeter.class, new GreeterImpl(), new Hashtable<String, String>());
|
||||
reference = registration.getReference();
|
||||
}
|
||||
|
||||
@Override public void stop(BundleContext context) throws Exception {
|
||||
System.out.println("Unregistering service.");
|
||||
registration.unregister();
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>
|
||||
|
||||
<artifactId>osgi-intro</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<modules>
|
||||
<module>osgi-intro-sample-activator</module>
|
||||
<module>osgi-intro-sample-service</module>
|
||||
<module>osgi-intro-sample-client</module>
|
||||
</modules>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>osgi-intro-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>osgi-intro-service</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>osgi-intro-gxyz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>osgi-intro-mapquest</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.9.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.json</groupId>
|
||||
<artifactId>javax.json-api</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.json</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>org.osgi.core</artifactId>
|
||||
<version>5.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<extensions>true</extensions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -1,18 +1,21 @@
|
|||
package com.baeldung.templatemethodpattern.application;
|
||||
|
||||
import com.baeldung.templatemethodpattern.model.Computer;
|
||||
import com.baeldung.templatemethodpattern.model.ComputerBuilder;
|
||||
import com.baeldung.templatemethodpattern.model.HighEndComputerBuilder;
|
||||
import com.baeldung.templatemethodpattern.model.StandardComputerBuilder;
|
||||
import com.baeldung.templatemethodpattern.model.HighEndComputer;
|
||||
import com.baeldung.templatemethodpattern.model.StandardComputer;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Computer standardComputer = new StandardComputer();
|
||||
standardComputer.buildComputer();
|
||||
ComputerBuilder standardComputerBuilder = new StandardComputerBuilder();
|
||||
Computer standardComputer = standardComputerBuilder.buildComputer();
|
||||
standardComputer.getComputerParts().forEach((k, v) -> System.out.println("Part : " + k + " Value : " + v));
|
||||
|
||||
Computer highEndComputer = new HighEndComputer();
|
||||
highEndComputer.buildComputer();
|
||||
ComputerBuilder highEndComputerBuilder = new HighEndComputerBuilder();
|
||||
Computer highEndComputer = highEndComputerBuilder.buildComputer();
|
||||
highEndComputer.getComputerParts().forEach((k, v) -> System.out.println("Part : " + k + " Value : " + v));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
package com.baeldung.templatemethodpattern.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Computer {
|
||||
public abstract class ComputerBuilder {
|
||||
|
||||
protected Map<String, String> computerParts = new HashMap<>();
|
||||
protected List<String> moterboardSetupStatus = new ArrayList<>();
|
||||
|
||||
public final void buildComputer() {
|
||||
public final Computer buildComputer() {
|
||||
addMotherboard();
|
||||
setupMotherboard();
|
||||
addProcessor();
|
||||
return getComputer();
|
||||
}
|
||||
|
||||
public abstract void addMotherboard();
|
||||
|
@ -30,4 +30,8 @@ public abstract class Computer {
|
|||
public Map<String, String> getComputerParts() {
|
||||
return computerParts;
|
||||
}
|
||||
|
||||
private Computer getComputer() {
|
||||
return new Computer(computerParts);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.baeldung.templatemethodpattern.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ComputerBuilder {
|
||||
|
||||
protected Map<String, String> computerParts = new HashMap<>();
|
||||
protected List<String> moterboardSetupStatus = new ArrayList<>();
|
||||
|
||||
public final Computer buildComputer() {
|
||||
addMotherboard();
|
||||
setupMotherboard();
|
||||
addProcessor();
|
||||
return getComputer();
|
||||
}
|
||||
|
||||
public abstract void addMotherboard();
|
||||
|
||||
public abstract void setupMotherboard();
|
||||
|
||||
public abstract void addProcessor();
|
||||
|
||||
public List<String> getMotherboardSetupStatus() {
|
||||
return moterboardSetupStatus;
|
||||
}
|
||||
|
||||
public Map<String, String> getComputerParts() {
|
||||
return computerParts;
|
||||
}
|
||||
|
||||
private Computer getComputer() {
|
||||
return new Computer(computerParts);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.templatemethodpattern.model;
|
||||
|
||||
public class HighEndComputerBuilder extends ComputerBuilder {
|
||||
|
||||
@Override
|
||||
public void addMotherboard() {
|
||||
computerParts.put("Motherboard", "High-end Motherboard");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupMotherboard() {
|
||||
moterboardSetupStatus.add("Screwing the high-end motherboard to the case.");
|
||||
moterboardSetupStatus.add("Pluging in the power supply connectors.");
|
||||
moterboardSetupStatus.forEach(step -> System.out.println(step));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProcessor() {
|
||||
computerParts.put("Processor", "High-end Processor");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.templatemethodpattern.model;
|
||||
|
||||
public class StandardComputerBuilder extends ComputerBuilder {
|
||||
|
||||
@Override
|
||||
public void addMotherboard() {
|
||||
computerParts.put("Motherboard", "Standard Motherboard");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupMotherboard() {
|
||||
moterboardSetupStatus.add("Screwing the standard motherboard to the case.");
|
||||
moterboardSetupStatus.add("Pluging in the power supply connectors.");
|
||||
moterboardSetupStatus.forEach(step -> System.out.println(step));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProcessor() {
|
||||
computerParts.put("Processor", "Standard Processor");
|
||||
}
|
||||
}
|
|
@ -1,25 +1,30 @@
|
|||
package com.baeldung.templatemethodpatterntest;
|
||||
|
||||
import com.baeldung.templatemethodpattern.model.Computer;
|
||||
import com.baeldung.templatemethodpattern.model.HighEndComputerBuilder;
|
||||
import com.baeldung.templatemethodpattern.model.StandardComputerBuilder;
|
||||
import com.baeldung.templatemethodpattern.model.HighEndComputer;
|
||||
import com.baeldung.templatemethodpattern.model.StandardComputer;
|
||||
import org.junit.Assert;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TemplateMethodPatternTest {
|
||||
|
||||
private static StandardComputer standardComputer;
|
||||
private static HighEndComputer highEndComputer;
|
||||
private static StandardComputerBuilder standardComputerBuilder;
|
||||
private static HighEndComputerBuilder highEndComputerBuilder;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpStandardComputerInstance() {
|
||||
standardComputer = new StandardComputer();
|
||||
public static void setUpStandardComputerBuilderInstance() {
|
||||
standardComputerBuilder = new StandardComputerBuilder();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpHighEndComputerInstance() {
|
||||
highEndComputer = new HighEndComputer();
|
||||
public static void setUpHighEndComputerBuilderInstance() {
|
||||
highEndComputerBuilder = new HighEndComputerBuilder();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -30,45 +35,55 @@ public class TemplateMethodPatternTest {
|
|||
|
||||
@Test
|
||||
public void givenStandardMotheroboard_whenSetup_thenTwoEqualAssertions() {
|
||||
standardComputer.setupMotherboard();
|
||||
assertEquals("Screwing the standard motherboard to the case.", standardComputer.getMotherboardSetupStatus().get(0));
|
||||
assertEquals("Plugin in the power supply connectors.", standardComputer.getMotherboardSetupStatus().get(1));
|
||||
standardComputerBuilder.setupMotherboard();
|
||||
assertEquals("Screwing the standard motherboard to the case.", standardComputerBuilder.getMotherboardSetupStatus().get(0));
|
||||
assertEquals("Pluging in the power supply connectors.", standardComputerBuilder.getMotherboardSetupStatus().get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStandardProcessor_whenAddingProcessor_thenEqualAssertion() {
|
||||
standardComputer.addProcessor();
|
||||
assertEquals("Standard Processor", standardComputer.getComputerParts().get("Processor"));
|
||||
standardComputerBuilder.addProcessor();
|
||||
assertEquals("Standard Processor", standardComputerBuilder.getComputerParts().get("Processor"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAllStandardParts_whenBuildingComputer_thenTwoParts() {
|
||||
standardComputer.buildComputer();
|
||||
assertEquals(2, standardComputer.getComputerParts().size());
|
||||
standardComputerBuilder.buildComputer();
|
||||
assertEquals(2, standardComputerBuilder.getComputerParts().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAllStandardParts_whenComputerisBuilt_thenComputerInstance() {
|
||||
assertThat(standardComputerBuilder.buildComputer(), instanceOf(Computer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenHighEnddMotherBoard_whenAddingMotherBoard_thenEqualAssertion() {
|
||||
highEndComputer.addMotherboard();
|
||||
Assert.assertEquals("High-end Motherboard", highEndComputer.getComputerParts().get("Motherboard"));
|
||||
highEndComputerBuilder.addMotherboard();
|
||||
Assert.assertEquals("High-end Motherboard", highEndComputerBuilder.getComputerParts().get("Motherboard"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenHighEnddMotheroboard_whenSetup_thenTwoEqualAssertions() {
|
||||
highEndComputer.setupMotherboard();
|
||||
assertEquals("Screwing the high-end motherboard to the case.", highEndComputer.getMotherboardSetupStatus().get(0));
|
||||
assertEquals("Plugin in the power supply connectors.", highEndComputer.getMotherboardSetupStatus().get(1));
|
||||
highEndComputerBuilder.setupMotherboard();
|
||||
assertEquals("Screwing the high-end motherboard to the case.", highEndComputerBuilder.getMotherboardSetupStatus().get(0));
|
||||
assertEquals("Pluging in the power supply connectors.", highEndComputerBuilder.getMotherboardSetupStatus().get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenHightEndProcessor_whenAddingProcessor_thenEqualAssertion() {
|
||||
highEndComputer.addProcessor();
|
||||
Assert.assertEquals("High-end Processor", highEndComputer.getComputerParts().get("Processor"));
|
||||
highEndComputerBuilder.addProcessor();
|
||||
assertEquals("High-end Processor", highEndComputerBuilder.getComputerParts().get("Processor"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAllHighEnddParts_whenBuildingComputer_thenTwoParts() {
|
||||
highEndComputer.buildComputer();
|
||||
assertEquals(2, highEndComputer.getComputerParts().size());
|
||||
highEndComputerBuilder.buildComputer();
|
||||
assertEquals(2, highEndComputerBuilder.getComputerParts().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAllHighEndParts_whenComputerisBuilt_thenComputerInstance() {
|
||||
assertThat(standardComputerBuilder.buildComputer(), instanceOf(Computer.class));
|
||||
}
|
||||
}
|
||||
|
|
1
pom.xml
1
pom.xml
|
@ -118,6 +118,7 @@
|
|||
<module>mustache</module>
|
||||
<module>noexception</module>
|
||||
|
||||
<module>osgi</module>
|
||||
<module>orika</module>
|
||||
|
||||
<module>patterns</module>
|
||||
|
|
|
@ -7,3 +7,4 @@
|
|||
- [A Guied to JUnit 5 Extensions](http://www.baeldung.com/junit-5-extensions)
|
||||
- [Inject Parameters into JUnit Jupiter Unit Tests](http://www.baeldung.com/junit-5-parameters)
|
||||
- [Mockito and JUnit 5 – Using ExtendWith](http://www.baeldung.com/mockito-junit-5-extension)
|
||||
- [JUnit 5 – @RunWith](http://www.baeldung.com/junit-5-runwith)
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
Feature: Testing a REST API
|
||||
Users should be able to submit GET and POST requests to a web service, represented by WireMock
|
||||
|
||||
Scenario: Data Upload to a web service
|
||||
When users upload data on a project
|
||||
Then the server should handle it and return a success status
|
||||
|
||||
Scenario: Data retrieval from a web service
|
||||
When users want to get information on the Cucumber project
|
||||
Then the requested data is returned
|
|
@ -1,4 +1,3 @@
|
|||
### Relevant Articles:
|
||||
- [Guide to Selenium with JUnit / TestNG](http://www.baeldung.com/java-selenium-with-junit-and-testng)
|
||||
- [Testing a Site with Selenium / Webdriver](http://www.baeldung.com)
|
||||
- [Testing with Selenium/WebDriver and the Page Object Pattern](http://www.baeldung.com/selenium-webdriver-page-object)
|
||||
|
|
Loading…
Reference in New Issue