Home | History | Annotate | Download | only in sun
      1 /**
      2  * Copyright 2006-2017 the original author or authors.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package org.objenesis.instantiator.sun;
     17 
     18 import org.junit.Before;
     19 import org.junit.Test;
     20 import org.objenesis.EmptyClass;
     21 import org.objenesis.instantiator.ObjectInstantiator;
     22 import org.objenesis.strategy.PlatformDescription;
     23 
     24 import static org.junit.Assert.*;
     25 import static org.junit.Assume.*;
     26 
     27 /**
     28  * @author Henri Tremblay
     29  */
     30 public class MagicInstantiatorTest {
     31 
     32    @Before
     33    public void before() {
     34       // I know it works one these two. Not sure on others
     35       assumeTrue(
     36          PlatformDescription.isThisJVM(PlatformDescription.HOTSPOT) ||
     37             PlatformDescription.isThisJVM(PlatformDescription.OPENJDK));
     38    }
     39 
     40    @Test
     41    public void testNewInstance() throws Exception {
     42       ObjectInstantiator<EmptyClass> o1 = new MagicInstantiator<EmptyClass>(EmptyClass.class);
     43       assertEquals(EmptyClass.class, o1.newInstance().getClass());
     44 
     45       ObjectInstantiator<EmptyClass> o2 = new MagicInstantiator<EmptyClass>(EmptyClass.class);
     46       assertEquals(EmptyClass.class, o2.newInstance().getClass());
     47    }
     48 
     49    @Test
     50    public void testInternalInstantiator() {
     51       ObjectInstantiator<EmptyClass> o1 = new MagicInstantiator<EmptyClass>(EmptyClass.class).getInstantiator();
     52       assertEquals(EmptyClass.class, o1.newInstance().getClass());
     53    }
     54 }
     55