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(); } }
'매일매일개발 > Codewars' 카테고리의 다른 글
codewars #17 Strings Mix (4kyu) (0) | 2018.04.09 |
---|---|
Codewars #16 Java format Unicode encoder/decoder (6kyu) (0) | 2018.04.06 |
Codewars #14 Calculator (3kyu) (0) | 2018.04.03 |
Codewars #13 Anagram Detection (7kyu) (0) | 2018.04.02 |
Codewars #12 Range Extraction (4kyu) (0) | 2018.03.30 |