@Test public void testResolveSymbolicRef() { when(mockRefDb.getRef(eq("HEAD"))).thenThrow(new IllegalArgumentException()); when(mockRefDb.getSymRef(eq("HEAD"))).thenReturn("refs/heads/branch1"); Optional<Ref> ref = command.setName("HEAD").call(); assertTrue(ref.isPresent()); assertTrue(ref.get() instanceof SymRef); assertEquals("HEAD", ref.get().getName()); assertEquals("refs/heads/branch1", ((SymRef) ref.get()).getTarget()); }
@Before public void setUp() { mockRefDb = mock(RefDatabase.class); Builder<String, String> builder = ImmutableMap.builder(); Map<String, String> allRefs = builder // .put("refs/heads/master", forString("refs/heads/master").toString()) // .put("refs/heads/branch1", forString("refs/heads/branch1").toString()) // .put("refs/heads/v1.1", forString("refs/heads/v1.1").toString()) // .put("refs/tags/tag1", forString("refs/tags/tag1").toString()) // .put("refs/tags/v1.1", forString("refs/tags/v1.1").toString()) // .put( "refs/remotes/origin/master", forString("refs/remotes/origin/master").toString()) // .put( "refs/remotes/origin/branch1", forString("refs/remotes/origin/branch1").toString()) // .put("refs/remotes/juan/master", forString("refs/remotes/juan/master").toString()) // .put("refs/remotes/juan/v1.1", forString("refs/remotes/juan/v1.1").toString()) // .build(); when(mockRefDb.getAll()).thenReturn(allRefs); command = new RefParse(); for (String name : allRefs.keySet()) { when(mockRefDb.getRef(eq(name))).thenReturn(allRefs.get(name)); } CommandLocator mockCommandLocator = mock(CommandLocator.class); when(mockCommandLocator.getRefDatabase()).thenReturn(mockRefDb); command.setCommandLocator(mockCommandLocator); ResolveObjectType mockResolveObjectType = mock(ResolveObjectType.class); when(mockCommandLocator.command(eq(ResolveObjectType.class))).thenReturn(mockResolveObjectType); when(mockResolveObjectType.setObjectId((ObjectId) anyObject())) .thenReturn(mockResolveObjectType); when(mockResolveObjectType.call()).thenReturn(TYPE.COMMIT); }