Example usage for java.lang AssertionError AssertionError

List of usage examples for java.lang AssertionError AssertionError

Introduction

In this page you can find the example usage for java.lang AssertionError AssertionError.

Prototype

public AssertionError(double detailMessage) 

Source Link

Document

Constructs an AssertionError with its detail message derived from the specified double, which is converted to a string as defined in section 15.18.1.1 of The Java™ Language Specification.

Usage

From source file:com.evolveum.midpoint.model.impl.dataModel.dot.DotModel.java

public DotModel(DataModel dataModel) {
    this.dataModel = dataModel;
    for (DataItem dataItem : dataModel.getDataItems()) {
        DotDataItem ddi;/*  www . j a  v a 2  s .com*/
        if (dataItem instanceof RepositoryDataItem) {
            ddi = new DotRepositoryDataItem((RepositoryDataItem) dataItem);
        } else if (dataItem instanceof ResourceDataItem) {
            ddi = new DotResourceDataItem((ResourceDataItem) dataItem, this);
        } else if (dataItem instanceof AdHocDataItem) {
            ddi = new DotAdHocDataItem((AdHocDataItem) dataItem);
        } else {
            throw new AssertionError("Wrong data item: " + dataItem);
        }
        dataItemsMap.put(dataItem, ddi);
    }
    for (Relation relation : dataModel.getRelations()) {
        DotRelation dr;
        if (relation instanceof MappingRelation) {
            dr = new DotMappingRelation((MappingRelation) relation);
        } else {
            dr = new DotOtherRelation(relation);
        }
        relationsMap.put(relation, dr);
    }
}

From source file:mondrian.util.UtilCompatibleJdk15.java

private static MemoryPoolMXBean findTenuredGenPool() {
    for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
        if (pool.getType() == MemoryType.HEAP) {
            return pool;
        }/*  w ww .  j  ava 2 s .  c o  m*/
    }
    throw new AssertionError("Could not find tenured space");
}

From source file:com.evolveum.midpoint.task.quartzimpl.work.segmentation.StringWorkSegmentationStrategy.java

@Override
protected AbstractWorkBucketContentType createAdditionalBucket(AbstractWorkBucketContentType lastBucketContent,
        Integer lastBucketSequentialNumber) {
    if (marking == INTERVAL) {
        return createAdditionalIntervalBucket(lastBucketContent, lastBucketSequentialNumber);
    } else if (marking == PREFIX) {
        return createAdditionalPrefixBucket(lastBucketContent, lastBucketSequentialNumber);
    } else {//from   w w  w .j a  v a2s .co m
        throw new AssertionError("unsupported marking: " + marking);
    }
}

From source file:com.tc.config.HaConfigTest.java

@SuppressWarnings("unused")
public void testBasicMakeAllNodes() {
    try {/*from w w  w.j  ava 2s .  c o  m*/
        tcConfig = getTempFile("tc-config-testFakeL2sName.xml");
        String config = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
                + "\n<tc-config xmlns=\"http://www.terracotta.org/config\">" + "\n<servers>"
                + "\n      <server name=\"server1\" />" + "\n</servers>" + "\n</tc-config>";
        writeConfigFile(config);

        // test for picking up default active server group
        ConfigurationSetupManagerFactory factory = new StandardConfigurationSetupManagerFactory(
                new String[] { "-f", tcConfig.getAbsolutePath() },
                StandardConfigurationSetupManagerFactory.ConfigMode.L2, null);
        HaConfig haConfig = new HaConfigImpl(
                factory.createL2TVSConfigurationSetupManager(null, getClass().getClassLoader()));
        Assert.assertTrue(haConfig.getNodesStore().getAllNodes().length == 1);

        // test for picking up right active server group for a give server
        factory = new StandardConfigurationSetupManagerFactory(
                new String[] { "-f", tcConfig.getAbsolutePath(), "-n", "server1" },
                StandardConfigurationSetupManagerFactory.ConfigMode.L2, null);
        haConfig = new HaConfigImpl(
                factory.createL2TVSConfigurationSetupManager(null, getClass().getClassLoader()));
        Assert.assertTrue(haConfig.getNodesStore().getAllNodes().length == 1);

        // expecting an error when given non existing server for haConfig
        factory = new StandardConfigurationSetupManagerFactory(
                new String[] { "-f", tcConfig.getAbsolutePath(), "-n", "server2" },
                StandardConfigurationSetupManagerFactory.ConfigMode.L2, null);
        try {
            new HaConfigImpl(factory.createL2TVSConfigurationSetupManager(null, getClass().getClassLoader()));
            throw new AssertionError("Config setup manager is suppose to blast for non-existing server name");
        } catch (ConfigurationSetupException cse) {
            // expected exception
        }

    } catch (Exception e) {
        throw new AssertionError(e);
    }
}

From source file:com.gatf.executor.core.GatfFunctionHandler.java

public static String handleFunction(String function) {
    if (function.equals(BOOLEAN)) {
        Random rand = new Random();
        return String.valueOf(rand.nextBoolean());
    } else if (function.matches(DT_FMT_REGEX)) {
        Matcher match = datePattern.matcher(function);
        match.matches();//from   w  ww . j ava 2 s.  c o  m
        SimpleDateFormat format = new SimpleDateFormat(match.group(1));
        return format.format(new Date());
    } else if (function.matches(DT_FUNC_FMT_REGEX)) {
        Matcher match = specialDatePattern.matcher(function);
        match.matches();
        String formatStr = match.group(1);
        String operation = match.group(2);
        int value = Integer.valueOf(match.group(3));
        String unit = match.group(4);
        SimpleDateFormat format = new SimpleDateFormat(formatStr);
        try {
            Date dt = format.parse(format.format(new Date()));
            Calendar cal = Calendar.getInstance();
            cal.setTime(dt);

            value = (operation.equals(MINUS) ? -value : value);
            if (unit.equals(YEAR)) {
                cal.add(Calendar.YEAR, value);
            } else if (unit.equals(MONTH)) {
                cal.add(Calendar.MONTH, value);
            } else if (unit.equals(DAY)) {
                cal.add(Calendar.DAY_OF_YEAR, value);
            } else if (unit.equals(HOUR)) {
                cal.add(Calendar.HOUR_OF_DAY, value);
            } else if (unit.equals(MINUITE)) {
                cal.add(Calendar.MINUTE, value);
            } else if (unit.equals(SECOND)) {
                cal.add(Calendar.SECOND, value);
            } else if (unit.equals(MILLISECOND)) {
                cal.add(Calendar.MILLISECOND, value);
            }
            return format.format(cal.getTime());
        } catch (Exception e) {
            throw new AssertionError("Invalid date format specified - " + formatStr);
        }
    } else if (function.equals(FLOAT)) {
        Random rand = new Random(12345678L);
        return String.valueOf(rand.nextFloat());
    } else if (function.equals(ALPHA)) {
        return RandomStringUtils.randomAlphabetic(10);
    } else if (function.equals(ALPHANUM)) {
        return RandomStringUtils.randomAlphanumeric(10);
    } else if (function.equals(NUMBER_PLUS)) {
        Random rand = new Random();
        return String.valueOf(rand.nextInt(1234567));
    } else if (function.equals(NUMBER_MINUS)) {
        Random rand = new Random();
        return String.valueOf(-rand.nextInt(1234567));
    } else if (function.equals(NUMBER)) {
        Random rand = new Random();
        boolean bool = rand.nextBoolean();
        return bool ? String.valueOf(rand.nextInt(1234567)) : String.valueOf(-rand.nextInt(1234567));
    } else if (function.matches(RANDOM_RANGE_REGEX)) {
        Matcher match = randRangeNum.matcher(function);
        match.matches();
        String min = match.group(1);
        String max = match.group(2);
        try {
            int nmin = Integer.parseInt(min);
            int nmax = Integer.parseInt(max);
            return String.valueOf(nmin + (int) (Math.random() * ((nmax - nmin) + 1)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:jhc.redsniff.webdriver.download.FileDownloader.java

private void ensureFileNotPresent(File file) throws AssertionError {
    if (file.exists())
        if (!file.delete())
            throw new AssertionError("File exists and could not be deleted");
}

From source file:com.predic8.membrane.test.AssertUtils.java

public static String getAndAssert(int expectedHttpStatusCode, String url, String[] header)
        throws ParseException, IOException {
    if (hc == null)
        hc = new DefaultHttpClient();
    HttpGet get = new HttpGet(url);
    try {//from w w  w  .  j av  a2  s.  co m
        if (header != null)
            for (int i = 0; i < header.length; i += 2)
                get.addHeader(header[i], header[i + 1]);
        HttpResponse res = hc.execute(get);
        try {
            assertEquals(expectedHttpStatusCode, res.getStatusLine().getStatusCode());
        } catch (AssertionError e) {
            throw new AssertionError(e.getMessage() + " while fetching " + url);
        }
        HttpEntity entity = res.getEntity();
        return entity == null ? "" : EntityUtils.toString(entity);
    } finally {
        get.releaseConnection();
    }
}

From source file:com.wickettasks.business.services.tasklist.TestTaskListService.java

@Test
public void testDeleteTaskList() {
    TaskList taskList = this.taskListService.add("testTaskList", this.user.getId());
    Integer taskListId = taskList.getId();
    try {/*from  w w w .j  ava 2 s.c  o m*/
        this.taskListService.delete(taskListId, this.user.getId());
    } catch (AccessRestrictionException e) {
        throw new AssertionError(e);
    }
    List<TaskList> userTaskLists = this.taskListService.findByUserId(this.user.getId());
    assertEquals(Boolean.TRUE, Boolean.valueOf(userTaskLists.isEmpty()));
}

From source file:uk.ac.kcl.iop.brc.core.pipeline.dncpipeline.sanity.AnonymisationSanityChecker.java

@PostConstruct
public void checkBasicAnonymisationRules() throws ParseException {
    Patient patient = new Patient();
    patient.addForeName("TestName1");
    patient.addForeName("TestName2");
    patient.addSurname("TestLastName1");
    patient.addSurname("TestLastName1");
    patient.addNhsNumber("11122");
    PatientAddress patientAddress1 = new PatientAddress();
    patientAddress1.setAddress("Kidderpore Avenue Hampstead, London");
    patientAddress1.setPostCode("cb4 2za");
    PatientAddress patientAddress2 = new PatientAddress();
    patientAddress2.setAddress("addressText");
    patientAddress2.setPostCode("cb4 2za");
    patient.addAddress(patientAddress1);
    patient.addAddress(patientAddress2);
    patient.addPhoneNumber("50090051234");
    patient.addPhoneNumber("11090051234");
    patient.addDateOfBirth(TimeUtil.getDateFromString("09/05/1990", "dd/MM/yyyy"));

    String anonymisedText = anonymisationService.pseudonymisePersonPlainText(patient,
            "\n" + "\n" + "TestName1 TestName2 TestLastName1 TestLastName2\n" + "\n" + "\n" + "11122\n"
                    + "50090051234" + "\n 09/05/1990" + "\n" + "cb42za"
                    + " Some random text that should not be anonymised. \n"
                    + "Address is Kidderpore Ave, (Hampstead, London.");
    System.out.println(anonymisedText);
    if (anonymisedText.contains("TestName1") || anonymisedText.contains("TestName2")) {
        throw new AssertionError(
                "First name pseudonymisation is not working! Please check config/anonymisation/nameRules");
    }//w w w.  j a va2 s.  c  om
    if (anonymisedText.contains("TestLastName1") || anonymisedText.contains("TestLastName2")) {
        throw new AssertionError(
                "Last name pseudonymisation is not working! Please check config/anonymisation/nameRules");
    }
    if (anonymisedText.contains("11122")) {
        throw new AssertionError(
                "NHS Number pseudonymisation is not working! Please check config/anonymisation/nhsIdRules");
    }
    if (anonymisedText.contains("50090051234")) {
        throw new AssertionError(
                "Phone number pseudonymisation is not working! Please check config/anonymisation/phoneRules");
    }
    if (anonymisedText.contains("09/05/1990")) {
        throw new AssertionError(
                "Date of birth pseudonymisation is not working! Please check config/anonymisation/dateOfBirthRules");
    }
    if (anonymisedText.contains("cb42za")) {
        throw new AssertionError(
                "Post code pseudonymisation is not working! Please check config/anonymisation/addressRules");
    }
    if (!anonymisedText.contains("Some random text that should not be anonymised.")) {
        throw new AssertionError("Pseudonymisation rules anonymise everything? Please check your rules!");
    }

    if (!anonymisedText.contains("Address is AAAAA")) {
        throw new AssertionError(
                "Approximate address pseudonymisation is not working. Please check config/anonymisation/addressRules!");
    }
}

From source file:edu.cwru.apo.TrustAPOHttpClient.java

private SSLSocketFactory newSslSocketFactory() {
    try {/*from w  w  w.  j a  v a 2 s .co  m*/
        // Get an instance of the Bouncy Castle KeyStore format
        KeyStore trusted = KeyStore.getInstance("BKS");
        // Get the raw resource, which contains the keystore with
        // your trusted certificates (root and any intermediate certs)
        InputStream in = context.getResources().openRawResource(R.raw.keystore);
        try {
            // Initialize the keystore with the provided trusted certificates
            // Also provide the password of the keystore
            trusted.load(in, "mysecret".toCharArray());
        } finally {
            in.close();
        }
        // Pass the keystore to the SSLSocketFactory. The factory is responsible
        // for the verification of the server certificate.
        SSLSocketFactory sf = new SSLSocketFactory(trusted);
        // Hostname verification from certificate
        // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506
        sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
        return sf;
    } catch (Exception e) {
        throw new AssertionError(e);
    }
}