Skip to content

Commit

Permalink
write a line into test.file
Browse files Browse the repository at this point in the history
  • Loading branch information
huifer committed Mar 7, 2024
1 parent ad95cd2 commit 261c9a9
Show file tree
Hide file tree
Showing 5 changed files with 580 additions and 0 deletions.
90 changes: 90 additions & 0 deletions docs/spring/cs0f67148a-dc23-11ee-b73a-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Copyright 2009-2019 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.type;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class LongTypeHandlerTest extends BaseTypeHandlerTest {

private static final TypeHandler<Long> TYPE_HANDLER = new LongTypeHandler();

@Override
@Test
public void shouldSetParameter() throws Exception {
TYPE_HANDLER.setParameter(ps, 1, 100L, null);
verify(ps).setLong(1, 100L);
}

@Override
@Test
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getLong("column")).thenReturn(100L);
assertEquals(Long.valueOf(100L), TYPE_HANDLER.getResult(rs, "column"));

when(rs.getLong("column")).thenReturn(0L);
assertEquals(Long.valueOf(0L), TYPE_HANDLER.getResult(rs, "column"));
}

@Override
@Test
public void shouldGetResultNullFromResultSetByName() throws Exception {
when(rs.getLong("column")).thenReturn(0L);
when(rs.wasNull()).thenReturn(true);
assertNull(TYPE_HANDLER.getResult(rs, "column"));
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getLong(1)).thenReturn(100L);
assertEquals(Long.valueOf(100L), TYPE_HANDLER.getResult(rs, 1));

when(rs.getLong(1)).thenReturn(0L);
assertEquals(Long.valueOf(0L), TYPE_HANDLER.getResult(rs, 1));
}

@Override
@Test
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
when(rs.getLong(1)).thenReturn(0L);
when(rs.wasNull()).thenReturn(true);
assertNull(TYPE_HANDLER.getResult(rs, 1));
}

@Override
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
when(cs.getLong(1)).thenReturn(100L);
assertEquals(Long.valueOf(100L), TYPE_HANDLER.getResult(cs, 1));

when(cs.getLong(1)).thenReturn(0L);
assertEquals(Long.valueOf(0L), TYPE_HANDLER.getResult(cs, 1));
}

@Override
@Test
public void shouldGetResultNullFromCallableStatement() throws Exception {
when(cs.getLong(1)).thenReturn(0L);
when(cs.wasNull()).thenReturn(true);
assertNull(TYPE_HANDLER.getResult(cs, 1));
}

}
73 changes: 73 additions & 0 deletions docs/spring/cs0f988ad8-dc23-11ee-b73a-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright 2009-2019 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.executor.loader;

import net.sf.cglib.proxy.Factory;
import org.apache.ibatis.domain.blog.Author;
import org.apache.ibatis.executor.ExecutorException;
import org.apache.ibatis.executor.loader.cglib.CglibProxyFactory;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.ibatis.session.Configuration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

import static org.junit.jupiter.api.Assertions.*;

class CglibProxyTest extends SerializableProxyTest {

@BeforeAll
static void createProxyFactory() {
proxyFactory = new CglibProxyFactory();
}

@Test
void shouldCreateAProxyForAPartiallyLoadedBean() throws Exception {
ResultLoaderMap loader = new ResultLoaderMap();
loader.addLoader("id", null, null);
Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
Author author2 = (Author) deserialize(serialize((Serializable) proxy));
assertTrue(author2 instanceof Factory);
}

@Test
void shouldFailCallingAnUnloadedProperty() {
// yes, it must go in uppercase
HashMap<String, ResultLoaderMap.LoadPair> unloadedProperties = new HashMap<>();
unloadedProperties.put("ID", null);
Author author2 = (Author) ((CglibProxyFactory) proxyFactory).createDeserializationProxy(author, unloadedProperties, new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
Assertions.assertThrows(ExecutorException.class, author2::getId);
}

@Test
void shouldLetCallALoadedProperty() {
Author author2 = (Author) ((CglibProxyFactory) proxyFactory).createDeserializationProxy(author, new HashMap<>(), new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
assertEquals(999, author2.getId());
}

@Test
void shouldSerizalizeADeserlizaliedProxy() throws Exception {
Object proxy = ((CglibProxyFactory) proxyFactory).createDeserializationProxy(author, new HashMap<>(), new DefaultObjectFactory(), new ArrayList<>(), new ArrayList<>());
Author author2 = (Author) deserialize(serialize((Serializable) proxy));
assertEquals(author, author2);
assertNotEquals(author.getClass(), author2.getClass());
}

}
16 changes: 16 additions & 0 deletions docs/spring/cs0fc957b2-dc23-11ee-b73a-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dolores.oauthserver;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class OauthServerApplicationTests {

@Test
public void contextLoads() {
}

}
17 changes: 17 additions & 0 deletions docs/spring/cs0ffa9958-dc23-11ee-b73a-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.huifer.design.builder;

/**
* 轮子
*/
public class Wheel {

private Integer size;

public Integer getSize() {
return size;
}

public void setSize(Integer size) {
this.size = size;
}
}
Loading

0 comments on commit 261c9a9

Please sign in to comment.