All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.siwenyan.si.SiEventHandlerAssertEquals Maven / Gradle / Ivy

There is a newer version: 1.25.1.0
Show newest version
package com.github.siwenyan.si;

import org.junit.Assert;

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Map;
import java.util.Properties;

public class SiEventHandlerAssertEquals implements ISiEventHandler {

    @Override
    public void handle(SiContextMonitorEvent event, Map spec) {
        Properties props = new Properties();
        props.putAll(spec);

        SiContext sc = event.getSiTest().getSiContext();
        String s1 = sc.dynamic(props.getProperty("Expected", props.getProperty("Param1")), "", "");
        String s2 = sc.dynamic(props.getProperty("Actual", props.getProperty("Param2")), "", "");
        sc.getReporter().reportMessage("Comparing [" + s1 + "] with [" + s2 + "]");

        String command = props.getProperty("Command");
        if ("String".equalsIgnoreCase(command)) {
            Assert.assertEquals(s1, s2);
        } else if ("Number".equalsIgnoreCase(command)) {
            NumberFormat nf = NumberFormat.getInstance();
            try {
                Assert.assertEquals(nf.parse(s1), nf.parse(s2));
            } catch (ParseException e) {
                Assert.fail("Invalid number format: [" + s1 + "] VS [" + s2 + "]");
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy