xref: /aosp_15_r20/external/mockito/src/test/java/org/mockito/internal/util/MockNameImplTest.java (revision ceffa222020788e9b81e120db61d5f29c922f983)
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockito.internal.util;
6 
7 import org.junit.Test;
8 import org.mockitoutil.TestBase;
9 
10 import static org.junit.Assert.assertEquals;
11 
12 public class MockNameImplTest extends TestBase {
13 
14     @Test
shouldProvideTheNameForClass()15     public void shouldProvideTheNameForClass() throws Exception {
16         //when
17         String name = new MockNameImpl(null, SomeClass.class).toString();
18         //then
19         assertEquals("someClass", name);
20     }
21 
22     @Test
shouldProvideTheNameForAnonymousClass()23     public void shouldProvideTheNameForAnonymousClass() throws Exception {
24         //given
25         SomeInterface anonymousInstance = new SomeInterface() {};
26         //when
27         String name = new MockNameImpl(null, anonymousInstance.getClass()).toString();
28         //then
29         assertEquals("someInterface", name);
30     }
31 
32     @Test
shouldProvideTheGivenName()33     public void shouldProvideTheGivenName() throws Exception {
34         //when
35         String name = new MockNameImpl("The Hulk", SomeClass.class).toString();
36         //then
37         assertEquals("The Hulk", name);
38     }
39 
40     private class SomeClass {}
41     private class SomeInterface {}
42 }
43