Clase 10: Interfaces en Java

				
					package Curso_2_Intermedio.clase10_interfaces_listeners.intefaces_ejemplo1;

public class Demo implements MyInterface {
    public void method1() {
        System.out.println("implementation of method1");
    }

    public void method2() {
        System.out.println("implementation of method2");
    }



    public static void main(String arg[]) {
        MyInterface obj = new Demo();
        obj.method1();
    }
}

				
			
				
					package clase10.ejemplo1;

public interface MyInterface {

    void metodo1();

    void metodo2();

}

				
			
				
					package clase10.ejemplo4;

import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;

public class InvokedMethodListener implements IInvokedMethodListener {

    public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
        System.out.println("Antes de la invocacion de " + method.getTestMethod().getMethodName());
    }

    public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
        System.out.println("Luego de la invocacion de " + method.getTestMethod().getMethodName());
    }


}

				
			
				
					package clase10.ejemplo4;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners(value = InvokedMethodListener.class)
public class AppleTest {

    @BeforeMethod
    public void setup(){
        System.out.println("Esto es el setup!! @BeforeMethod");
    }

    @Test
    public void test1(){
        System.out.println("Esto es el TEST1!!! @Test");
    }

    @AfterMethod
    public void closeTest(){
        System.out.println("Esto es el fin!!! @AfterMethod");
    }

    /*
    --> imprimir algo...
        @beforeTest
    --> imprimir algo...

    --> imprimir algo...
        @test
    --> imprimir algo...

    --> imprimir algo...
        @afterMethod
    --> imprimir algo...

     */


}

				
			
				
					<suite name="Ecommerce Suite Tests">

    <listeners>
        <listener class-name="clase10.ejemplo5.SuiteListeners"></listener>
    </listeners>

    <test name="Test 1">
        <classes>
            <class name = "clase10.ejemplo5.YoutubeTest"></class>
            <class name = "clase10.ejemplo4.AppleTest"></class>
        </classes>
    </test>
</suite>
				
			
				
					package clase10.ejemplo5;

import org.testng.ISuite;
import org.testng.ISuiteListener;

public class SuiteListeners implements ISuiteListener {

    public void onStart(ISuite suite) {
        System.out.println("comenzo la ejecucion de la Suite name : " + suite.getName());
    }

    public void onFinish(ISuite suite) {
        System.out.println("terminó la ejecucion de la Suite name : " + suite.getName());
    }
}

				
			
				
					package clase10.ejemplo5;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class YoutubeTest {

    @BeforeMethod
    public void setup(){
        System.out.println("Esto es el setup!! @BeforeMethod");
    }

    @Test
    public void test1(){
        System.out.println("Esto es el TEST1!!! @Test");
    }

    @AfterMethod
    public void closeTest(){
        System.out.println("Esto es el fin!!! @AfterMethod");
    }



}

				
			
				
					package clase10.ejemplo6_ITestListener;

import org.testng.Assert;
import org.testng.SkipException;
import org.testng.annotations.Test;

public class MyTests {

    @Test
    public void successTest() {
        Assert.assertTrue(true);
        Assert.assertEquals(2, 2);
    }

    @Test
    public void failureTest() {
        Assert.assertEquals(2, 3);
    }

    @Test
    public void skippedTest() {
        throw new SkipException("Skipped Test!!");
    }
}

				
			
				
					<suite name="Ecommerce Suite Tests">

    <listeners>
        <listener class-name="clase10.ejemplo6_ITestListener.TestListener"></listener>
    </listeners>

    <test name="Test 1">
        <classes>
            <class name = "clase10.ejemplo6_ITestListener.MyTests"></class>
        </classes>
    </test>
</suite>
				
			
				
					package clase10.ejemplo6_ITestListener;

import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

public class TestListener implements ITestListener {
    public void onStart(ITestContext context) {
        System.out.println("@@@@  La ejecucion a comenzado!!");
    }

    public void onFinish(ITestContext context) {
        System.out.println("@@@@  La ejecucion ha finalizado!!");
    }

    public void onTestStart(ITestResult result) {
        System.out.println("@@@@  El test ha comenzado --> " + result.getName());
    }

    public void onTestSuccess(ITestResult result) {
        System.out.println("@@@@ Test passed!! --> " + result.getName());
    }

    public void onTestFailure(ITestResult result) {
        System.out.println("@@@@ Test failed!! --> " + result.getName() + " - " + result.getTestName());
    }

    public void onTestSkipped(ITestResult result) {
        System.out.println("@@@@ Test skipped!!");
    }

    public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
        System.out.println("@@@@ The test has failed more than expected!!");
    }

    public void onTestFailedWithTimeout(ITestResult result) {
        System.out.println("@@@@ Test failed due to timeout...!!");
        this.onTestFailure(result);
    }

}