AssignmentTests.AsignmentTestNGTest.java Source code

Java tutorial

Introduction

Here is the source code for AssignmentTests.AsignmentTestNGTest.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package AssignmentTests;

import Classes.ObjectAttributes;
import Config.Config;
import Service.Addition;
import Service.FailureTest;
import Service.Implimentation.AdditionImpl;
import Service.Implimentation.FailureTestImpl;
import Service.Implimentation.NullOrNotImpl;
import Service.Implimentation.ObjectCompImpl;
import Service.Implimentation.TrueOrFalseImpl;
import Service.NullOrNot;
import Service.ObjectComp;
import Service.TrueOrFalse;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.testng.Assert;
import static org.testng.Assert.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

/**
 *
 * @author luke
 */
public class AsignmentTestNGTest {

    public AsignmentTestNGTest() {
    }

    static Addition addition;
    static FailureTest failureTest;
    static NullOrNot nullOrNot;
    static ObjectComp objectComp;
    static TrueOrFalse trueOrFalse;

    @BeforeClass
    public static void setUpClass() throws Exception {
        addition = new AdditionImpl();
        failureTest = new FailureTestImpl();
        nullOrNot = new NullOrNotImpl();
        objectComp = new ObjectCompImpl();
        trueOrFalse = new TrueOrFalseImpl();
        ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
        ctx.getBean("add");
        ctx.getBean("fail");
        ctx.getBean("isItNull");
        ctx.getBean("isItTrue");
        ctx.getBean("objectTheSame");

    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @BeforeMethod
    public void setUpMethod() throws Exception {
    }

    @AfterMethod
    public void tearDownMethod() throws Exception {
    }

    @Test
    public void additionTest() {
        int integerNumber = 8;
        double doubleNumber = 8.4;
        float floatNumber = 9;

        assertEquals(addition.add(4, 4), integerNumber);
        assertEquals(addition.add(4, 4.4), doubleNumber);
        assertEquals(addition.add((float) 4, (float) 5), floatNumber);
    }

    @Test
    public void objectComparisonTest() {
        ObjectAttributes objectMatch = new ObjectAttributes("Luke", "Davids");
        ObjectAttributes objectMissMatch = new ObjectAttributes("Karriem", "Petersen");

        assertEquals(objectComp.ObjectsTheSame(), objectMatch);
        assertNotSame(objectComp.ObjectsTheSame(), objectMissMatch);
    }

    @Test
    public void nullTest() {
        String string = null;

        assertNotNull(nullOrNot.mustNotBeNull("Value"));
        assertNull(nullOrNot.mustNotBeNull(string));
    }

    @Test
    public void truthTest() {
        assertTrue(trueOrFalse.mustBeTrue(1));
        assertFalse(trueOrFalse.mustBeTrue(0));
    }

    @Test
    public void FailingTest() {
        fail("This test was supposed to fail.");
    }
}