매일매일개발/Codewars
Codewars #15 Bagels (4kyu)
개하싶
2018. 4. 6. 00:06
Here's a seemingly simple challenge. We're giving you a class called bagel, exactly as it appears below. All it really does is return an int, specifically 3.
public class Bagel { public final int getValue() { return 3; } }
The catch? For the solution, we're testing that the result is equal to 4. But as a little hint, the solution to the this Kata is exactly the same as the example test cases.
통과조건...import org.junit.Test; import static org.junit.Assert.assertEquals; import org.junit.runners.JUnit4; public class BagelTest { @Test public void testBagel() { Bagel bagel = BagelSolver.getBagel(); assertEquals( bagel.getValue() == 4, java.lang.Boolean.TRUE ); } }
...별짓을 다했다 리플랙션 , 프록시, bci
설마이걸까 했는데 -.- 으음 빡친다.
import java.lang.reflect.Field; import java.lang.reflect.Modifier; public class BagelSolver { public static Bagel getBagel() { try { Field f = Boolean.class.getField("TRUE"); Field modifiers = Field.class.getDeclaredField("modifiers"); modifiers.setAccessible(true); modifiers.setInt(f, f.getModifiers() & ~Modifier.FINAL); f.set(null, false); } catch (Exception e) { // TODO: handle exception } return new Bagel(); } }