|
| 1 | +/* |
| 2 | + * CDDL HEADER START |
| 3 | + * |
| 4 | + * The contents of this file are subject to the terms of the |
| 5 | + * Common Development and Distribution License (the "License"). |
| 6 | + * You may not use this file except in compliance with the License. |
| 7 | + * |
| 8 | + * See LICENSE.txt included in this distribution for the specific |
| 9 | + * language governing permissions and limitations under the License. |
| 10 | + * |
| 11 | + * When distributing Covered Code, include this CDDL HEADER in each |
| 12 | + * file and include the License file at LICENSE.txt. |
| 13 | + * If applicable, add the following below this CDDL HEADER, with the |
| 14 | + * fields enclosed by brackets "[]" replaced with your own identifying |
| 15 | + * information: Portions Copyright [yyyy] [name of copyright owner] |
| 16 | + * |
| 17 | + * CDDL HEADER END |
| 18 | + */ |
| 19 | + |
| 20 | +/* |
| 21 | + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. |
| 22 | + */ |
| 23 | +package org.opengrok.indexer.history; |
| 24 | + |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +import java.util.Date; |
| 28 | +import java.util.List; |
| 29 | +import java.util.Set; |
| 30 | + |
| 31 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 32 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
| 33 | + |
| 34 | +public class HistoryTest { |
| 35 | + private final List<HistoryEntry> entries = List.of( |
| 36 | + new HistoryEntry("84599b3c", new Date(1485438707000L), |
| 37 | + "Kryštof Tulinger <[email protected]>", null, |
| 38 | + " renaming directories\n\n", true, |
| 39 | + Set.of("/git/moved2/renamed2.c")), |
| 40 | + new HistoryEntry("67dfbe26", new Date(1485263397000L), |
| 41 | + "Kryštof Tulinger <[email protected]>", null, |
| 42 | + " renaming renamed -> renamed2\n\n", true, |
| 43 | + Set.of("/git/moved/renamed2.c"))); |
| 44 | + |
| 45 | + @Test |
| 46 | + public void testEqualsRenamed() { |
| 47 | + History history = new History(entries, List.of("moved/renamed2.c", "moved2/renamed2.c", "moved/renamed.c")); |
| 48 | + History historyNoRenames = new History(entries); |
| 49 | + assertNotEquals(history, historyNoRenames); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testEquals() { |
| 54 | + History history = new History(entries); |
| 55 | + assertEquals(2, history.getHistoryEntries().size()); |
| 56 | + History historySmaller = new History(entries.subList(1, 2)); |
| 57 | + assertEquals(1, historySmaller.getHistoryEntries().size()); |
| 58 | + assertNotEquals(history, historySmaller); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testToString() { |
| 63 | + History history = new History(entries); |
| 64 | + String expectedString = "[84599b3c Thu Jan 26 14:51:47 CET 2017 Kryštof Tulinger <[email protected]> renaming directories\n" + |
| 65 | + "\n" + |
| 66 | + "\n" + |
| 67 | + ", 67dfbe26 Tue Jan 24 14:09:57 CET 2017 Kryštof Tulinger <[email protected]> renaming renamed -> renamed2\n" + |
| 68 | + "\n" + |
| 69 | + "\n" + |
| 70 | + "], renamed files: []"; |
| 71 | + assertEquals(expectedString, history.toString()); |
| 72 | + } |
| 73 | +} |
0 commit comments