選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AddTest.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2012 Google Inc. and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.pgm;
  11. import static org.junit.Assert.assertArrayEquals;
  12. import static org.junit.Assert.assertEquals;
  13. import static org.junit.Assert.assertNotNull;
  14. import static org.junit.Assert.fail;
  15. import org.eclipse.jgit.api.Git;
  16. import org.eclipse.jgit.dircache.DirCache;
  17. import org.eclipse.jgit.lib.CLIRepositoryTestCase;
  18. import org.junit.Before;
  19. import org.junit.Test;
  20. public class AddTest extends CLIRepositoryTestCase {
  21. private Git git;
  22. @Override
  23. @Before
  24. public void setUp() throws Exception {
  25. super.setUp();
  26. git = new Git(db);
  27. }
  28. @Test
  29. public void testAddNothing() throws Exception {
  30. try {
  31. execute("git add");
  32. fail("Must die");
  33. } catch (Die e) {
  34. // expected, requires argument
  35. }
  36. }
  37. @Test
  38. public void testAddUsage() throws Exception {
  39. execute("git add --help");
  40. }
  41. @Test
  42. public void testAddAFile() throws Exception {
  43. writeTrashFile("greeting", "Hello, world!");
  44. assertArrayEquals(new String[] { "" }, //
  45. execute("git add greeting"));
  46. DirCache cache = db.readDirCache();
  47. assertNotNull(cache.getEntry("greeting"));
  48. assertEquals(1, cache.getEntryCount());
  49. }
  50. @Test
  51. public void testAddFileTwice() throws Exception {
  52. writeTrashFile("greeting", "Hello, world!");
  53. assertArrayEquals(new String[] { "" }, //
  54. execute("git add greeting greeting"));
  55. DirCache cache = db.readDirCache();
  56. assertNotNull(cache.getEntry("greeting"));
  57. assertEquals(1, cache.getEntryCount());
  58. }
  59. @Test
  60. public void testAddAlreadyAdded() throws Exception {
  61. writeTrashFile("greeting", "Hello, world!");
  62. git.add().addFilepattern("greeting").call();
  63. assertArrayEquals(new String[] { "" }, //
  64. execute("git add greeting"));
  65. DirCache cache = db.readDirCache();
  66. assertNotNull(cache.getEntry("greeting"));
  67. assertEquals(1, cache.getEntryCount());
  68. }
  69. }