001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Julien Carsique 018 * 019 */ 020 021package org.nuxeo.runtime.test; 022 023import org.junit.ComparisonFailure; 024 025import org.nuxeo.common.utils.FileUtils; 026 027/** 028 * Extension to {@link org.junit.Assert} 029 * 030 * @since 6.0 031 */ 032public class Assert { 033 034 /** 035 * Protect constructor since it is a static only class 036 */ 037 protected Assert() { 038 } 039 040 /** 041 * Asserts that two strings are equal even if their EOL are different. If they are not, an {@link AssertionError} is 042 * thrown with the given message. If <code>expected</code> and <code>actual</code> are <code>null</code>, they are 043 * considered equal. 044 * 045 * @param expected expected String with Windows or Unix like EOL 046 * @param actual actual String with Windows or Unix like EOL 047 * @see FileUtils#areFilesContentEquals(String, String) 048 */ 049 static public void assertFilesContentEquals(String expected, String actual) { 050 assertFilesContentEquals(null, expected, actual); 051 } 052 053 /** 054 * Asserts that two strings are equal even if their EOL are different. If they are not, an {@link AssertionError} is 055 * thrown with the given message. If <code>expected</code> and <code>actual</code> are <code>null</code>, they are 056 * considered equal. 057 * 058 * @param message the identifying message for the {@link AssertionError} ( <code>null</code> okay) 059 * @param expected expected String with Windows or Unix like EOL 060 * @param actual actual String with Windows or Unix like EOL 061 * @see FileUtils#areFilesContentEquals(String, String) 062 */ 063 static public void assertFilesContentEquals(String message, String expected, String actual) { 064 if (FileUtils.areFilesContentEquals(expected, actual)) { 065 return; 066 } else { 067 String cleanMessage = message == null ? "" : message; 068 throw new ComparisonFailure(cleanMessage, expected, actual); 069 } 070 } 071}