示例#1
0
    def test_foreign_repl():
        from java.util.logging import LogRecord
        from java.util.logging import Level

        lr = LogRecord(Level.ALL, "message")
        assert repr(LogRecord).startswith('<JavaClass[java.util.logging.LogRecord] at')
        assert repr(lr).startswith('<JavaObject[java.util.logging.LogRecord] at')

        from java.lang import Integer
        i = Integer('22')
        assert repr(Integer).startswith('<JavaClass[java.lang.Integer] at')
        assert repr(i) == '22'
示例#2
0
    def test_is_type():
        import java
        from java.util.logging import Handler
        from java.util import Set
        from java.util.logging import LogRecord
        from java.util.logging import Level

        assert java.is_type(Handler)
        assert java.is_type(LogRecord)
        assert java.is_type(Set)
        assert java.is_type(Level)

        lr = LogRecord(Level.ALL, "message")
        assert not java.is_type(lr)
        assert not java.is_type(Level.ALL)
        assert not java.is_type("ahoj")
示例#3
0
    def test_extend_java_class_01():
        from java.util.logging import Handler
        from java.util.logging import LogRecord
        from java.util.logging import Level

        lr = LogRecord(Level.ALL, "The first message")

        # extender object
        class MyHandler(Handler):
            "This is MyHandler doc"
            counter = 0

            def isLoggable(self, logrecord):
                self.counter = self.counter + 1
                return self.__super__.isLoggable(logrecord)

            def sayHello(self):
                return 'Hello'

        h = MyHandler()

        # accessing extender object via this property
        assert hasattr(h, 'this')
        assert hasattr(h.this, 'sayHello')
        assert hasattr(h.this, 'counter')
        assert hasattr(h.this, 'isLoggable')

        #accessing java methods or methods from extender object directly
        assert hasattr(h, 'close')
        assert hasattr(h, 'flush')
        assert hasattr(h, 'getEncoding')
        assert hasattr(h, 'setEncoding')

        assert h.this.counter == 0
        assert h.isLoggable(lr)
        assert h.this.counter == 1
        assert h.isLoggable(lr)
        assert h.isLoggable(lr)
        assert h.this.counter == 3

        assert 'Hello' == h.this.sayHello()

        h2 = MyHandler()
        assert h2.this.counter == 0
        assert h2.isLoggable(lr)
        assert h2.this.counter == 1
        assert h.this.counter == 3
示例#4
0
 def findRightState(self, mobObjectId):
     st1 = None
     if self.Spawn_List[mobObjectId][0] == None:
         record = LogRecord(
             Level.WARNING,
             "Founded NPE at findRightState() - npcObjectId: " +
             str(mobObjectId))
         record.setLoggerName("SagasSuperclass")
         _log.log(record)
         return None
     playerName = self.Spawn_List[mobObjectId][
         0]  #There is a possibility for an NPE here, but only if something else is wrong in the quest
     st1 = L2World.getInstance().getPlayer(
         playerName
     )  #Therefore, placing an NPE catch here will only hide the error, not solve it.
     if st1: st1 = st1.getQuestState(self.qn)
     return st1