diff --git a/assertj-core/src/test/java/org/assertj/core/util/myArraysTest.java b/assertj-core/src/test/java/org/assertj/core/util/myArraysTest.java new file mode 100644 index 0000000000..790d24f5bd --- /dev/null +++ b/assertj-core/src/test/java/org/assertj/core/util/myArraysTest.java @@ -0,0 +1,25 @@ +package org.assertj.core.util; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class myArraysTest { + + //boundary test + @Test + public void sizeOfTestSmallest(){ assertEquals(0, Arrays.sizeOf(new char[0])); } + + @Test + public void sizeOfTestSecondSmallest(){ assertEquals(1, Arrays.sizeOf(new char[1])); } + + @Test + public void sizeOfTestTypical(){ assertEquals(500, Arrays.sizeOf(new char[500])); } + + @Test + public void sizeOfTestSecondBiggest(){ assertEquals(Integer.MAX_VALUE - 3, Arrays.sizeOf(new char[Integer.MAX_VALUE - 3])); } + + @Test + public void sizeOfTestBiggest(){ assertEquals(Integer.MAX_VALUE - 2, Arrays.sizeOf(new char[Integer.MAX_VALUE - 2])); } + +} diff --git a/assertj-core/src/test/java/org/assertj/core/util/myDateUtilTests.java b/assertj-core/src/test/java/org/assertj/core/util/myDateUtilTests.java new file mode 100644 index 0000000000..aeb456b4c6 --- /dev/null +++ b/assertj-core/src/test/java/org/assertj/core/util/myDateUtilTests.java @@ -0,0 +1,68 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2025 the original author or authors. + */ + +package org.assertj.core.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.assertj.core.util.DateUtil.parse; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +public class myDateUtilTests { + private static SimpleDateFormat dateFormatter; + + private static String[] unparsableDates; + private static String[] parsibleDates; + + @BeforeAll + public static void setupForTests(){ + dateFormatter = new SimpleDateFormat("dd/MM/yyyy"); + unparsableDates = new String[] {"00/00/0000", "1.2/1.1/15.63", "99/99/9999", "gr/eg/milk"}; + parsibleDates = new String[] {"01/01/0001", "01/12/1970", "20/01/2038", "31/12/9999"}; + + } + + //partition equivalence + @Test + public void parseTestExtremeMinimum() throws ParseException { assertThrows(RuntimeException.class, () -> parse(unparsableDates[0])); } + + @Test + public void parseTestFloats() throws ParseException { assertThrows(RuntimeException.class, () -> parse(unparsableDates[1])); } + + @Test + public void parseTest() throws ParseException { assertThrows(RuntimeException.class, () -> parse(unparsableDates[2])); } + + @Test + public void parseTestExtremeMaximum() throws ParseException { assertThrows(RuntimeException.class, () -> parse(unparsableDates[3])); } + + @Test + public void parseTestMinimum() throws ParseException { assertEquals(parse("0001-01-01"), dateFormatter.parse(parsibleDates[0])); } + + @Test + public void parseTestTypical() throws ParseException{ assertEquals(parse("1970-12-01"), dateFormatter.parse(parsibleDates[1])); } + + @Test + public void parseTestEpoch() throws ParseException{ assertEquals(parse("2038-01-20"), dateFormatter.parse(parsibleDates[2])); } + + @Test + public void parseTestMax() throws ParseException{ assertEquals(parse("9999-12-31"), dateFormatter.parse(parsibleDates[3])); } +} + + diff --git a/assertj-core/src/test/java/org/assertj/core/util/myStringsTests.java b/assertj-core/src/test/java/org/assertj/core/util/myStringsTests.java new file mode 100644 index 0000000000..39a197d9e2 --- /dev/null +++ b/assertj-core/src/test/java/org/assertj/core/util/myStringsTests.java @@ -0,0 +1,82 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * Copyright 2012-2025 the original author or authors. + */ + +package org.assertj.core.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvFileSource; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +class myStringsTests { + + private static String[] escapeCharacters; + private static String[] typicalStrings; + private static String[] stringsForPercentEscape; + + @BeforeAll + static public void setUp(){ + escapeCharacters = new String[] {"\n", "\t", "\b", "\'", "\""}; + typicalStrings = new String[] {"Writing strings is so much fun", Character.toString(0)}; + stringsForPercentEscape = new String[] {"This is a string", "%", "This sentence %has a percent in it", "%This %sentence %has %lots of percents %in it", "╫╦£æ₧", "%╫%╦£æ%₧", "\b%Backspaced character"}; + } + + @Test + public void quotesAroundObjectsTestBool(){ assertEquals(true, Strings.quote(true)); } + + @Test + public void quotesAroundObjectsTestShort(){ assertEquals(Short.MIN_VALUE, Strings.quote(Short.MIN_VALUE)); } + + @Test + public void quotesAroundObjectsTestDoubleMin() { assertEquals(Double.MIN_VALUE, Strings.quote(Double.MIN_VALUE)); } + + @Test + public void quotesAroundObjectsTestDoubleMax(){ assertEquals(Double.MAX_VALUE, Strings.quote(Double.MAX_VALUE)); } + + @Test + public void quotesAroundObjectsEmptyString(){ assertEquals("''", Strings.quote("")); } + + @Test + public void escapePercentTestNull(){ assertEquals(null, Strings.escapePercent(null)); } + + @Test + public void escapePercentTestNoPercent(){ assertEquals("This is a string", Strings.escapePercent(stringsForPercentEscape[0])); } + + @Test + public void escapePercentTestSinglePercent(){ assertEquals("%%", Strings.escapePercent(stringsForPercentEscape[1])); } + + @Test + public void escapePercentTestPercentInString(){ assertEquals("This sentence %%has a percent in it", Strings.escapePercent(stringsForPercentEscape[2])); } + + @Test + public void escapePercentTestPercentsInString(){ assertEquals("%%This %%sentence %%has %%lots of percents %%in it", Strings.escapePercent(stringsForPercentEscape[3])); } + + @Test + public void escapePercentTestSpecialString(){ assertEquals("╫╦£æ₧", Strings.escapePercent(stringsForPercentEscape[4])); } + + @Test + public void escapePercentTestSpecialStringWithPercents(){ assertEquals("%%╫%%╦£æ%%₧", Strings.escapePercent(stringsForPercentEscape[5])); } + + @Test + public void escapePercentTestEscapeSequenceString(){ assertEquals("\b%%Backspaced character", Strings.escapePercent(stringsForPercentEscape[6])); } +} +